Skip to content

fix(math): avoid overflow in Math.asinh for very large finite inputs#5241

Closed
Veercodeprog wants to merge 2 commits intoboa-dev:mainfrom
Veercodeprog:veercodeprog/5239-fix-math-asinh-overflow
Closed

fix(math): avoid overflow in Math.asinh for very large finite inputs#5241
Veercodeprog wants to merge 2 commits intoboa-dev:mainfrom
Veercodeprog:veercodeprog/5239-fix-math-asinh-overflow

Conversation

@Veercodeprog
Copy link

@Veercodeprog Veercodeprog commented Mar 23, 2026

Fixes #5239

This Pull Request fixes/closes #5239.

It changes the following:

  • Cause: For very large finite x, Rust’s f64::asinh can overflow internally (e.g. when forming ), so Math.asinh returned ±Infinity instead of a finite value (e.g. 1e308, Number.MAX_VALUE).
  • Fix: When |x|² would overflow, use the large-magnitude approximation sign(x) · (ln(2|x|) + 1/(4x²)), with the correction computed as (1/(2x))² so is never formed. Otherwise delegate to f64::asinh. Implemented in core/engine/src/builtins/math/mod.rs.
  • Tests: Extended asinh tests in core/engine/src/builtins/math/tests.rs for 1e308, Number.MAX_VALUE, and -1e308.

How to verify

  • cargo test -p boa_engine builtins::math::tests::asinh
  • cargo run --bin boa -- -e 'console.log(Math.asinh(1e308)); console.log(Math.asinh(Number.MAX_VALUE)); console.log(Math.asinh(-1e308))' — expect finite values (~709.89, ~710.48, ~-709.89), not Infinity.

@Veercodeprog Veercodeprog requested a review from a team as a code owner March 23, 2026 18:30
@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 23, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 23, 2026
@github-actions github-actions bot added C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics labels Mar 23, 2026
@jedel1043
Copy link
Member

Duplicate of #5240

@jedel1043 jedel1043 marked this as a duplicate of #5240 Mar 23, 2026
@jedel1043 jedel1043 closed this Mar 23, 2026
@github-actions github-actions bot removed the Waiting On Review Waiting on reviews from the maintainers label Mar 23, 2026
@Veercodeprog
Copy link
Author

Veercodeprog commented Mar 23, 2026

Duplicate of #5240

i havent checked the code of 5240 before i pushed my code , i just checked the review of the pr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Builtins PRs and Issues related to builtins/intrinsics C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Math.asinh returns Infinity for large finite inputs like 1e308 and Number.MAX_VALUE

2 participants