Skip to content

fix(math): correct Math.asinh for large finite inputs#5240

Open
HiteshShonak wants to merge 4 commits intoboa-dev:mainfrom
HiteshShonak:fix/math-asinh-large-finite
Open

fix(math): correct Math.asinh for large finite inputs#5240
HiteshShonak wants to merge 4 commits intoboa-dev:mainfrom
HiteshShonak:fix/math-asinh-large-finite

Conversation

@HiteshShonak
Copy link
Contributor

This Pull Request fixes/closes #5239.

It changes the following:

  • When the absolute value of the input is finite and greater than 1/√f64::EPSILON (67_108_864.0), fall back to n.signum() * (n.abs().ln() + LN_2) instead of calling f64::asinh() directly, avoiding an internal overflow that produces Infinity. threshold follows the Boost math library convention.
  • Add regression tests for Math.asinh(1e308), Math.asinh(-1e308), and Math.asinh(Number.MAX_VALUE).

Testing:

cargo test -p boa_engine math -- --nocapture

Spec reference: https://tc39.es/ecma262/#sec-math.asinh

@HiteshShonak HiteshShonak requested a review from a team as a code owner March 23, 2026 15:35
Copilot AI review requested due to automatic review settings March 23, 2026 15:35
@github-actions github-actions bot added Waiting On Review Waiting on reviews from the maintainers C-Tests Issues and PRs related to the tests. C-Builtins PRs and Issues related to builtins/intrinsics and removed Waiting On Review Waiting on reviews from the maintainers labels Mar 23, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Math.asinh returning Infinity for very large finite inputs by introducing a large-input fallback formula consistent with common libm/Boost behavior, and adds regression tests to prevent recurrence.

Changes:

  • Add a large-input threshold in Math.asinh to compute sign(x) * (ln(|x|) + LN_2) for large finite x, avoiding overflow in f64::asinh().
  • Add regression tests for Math.asinh(1e308), Math.asinh(-1e308), and Math.asinh(Number.MAX_VALUE).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
core/engine/src/builtins/math/mod.rs Adds a large-input branch to keep Math.asinh finite for extremely large finite numbers.
core/engine/src/builtins/math/tests.rs Adds regression coverage for large finite inputs that previously overflowed to infinities.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Mar 23, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,732 50,732 0
Ignored 1,426 1,426 0
Failed 805 805 0
Panics 0 0 0
Conformance 95.79% 95.79% 0.00%

Tested main commit: 8fcbfcbb8b9e70fe878d28376a6496eaa57a70d7
Tested PR commit: 02c601e54d40286ff20435c72909ec440d2a0974
Compare commits: 8fcbfcb...02c601e

@codecov
Copy link

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.83%. Comparing base (6ddc2b4) to head (94fb037).
⚠️ Report is 917 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #5240       +/-   ##
===========================================
+ Coverage   47.24%   59.83%   +12.58%     
===========================================
  Files         476      582      +106     
  Lines       46892    63459    +16567     
===========================================
+ Hits        22154    37968    +15814     
- Misses      24738    25491      +753     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 24, 2026
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. Waiting On Review Waiting on reviews from the maintainers

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

4 participants