fix(math): correct Math.acosh for large finite inputs#5230
fix(math): correct Math.acosh for large finite inputs#5230jedel1043 merged 4 commits intoboa-dev:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Math.acosh returning Infinity for very large finite inputs by avoiding an overflow inside Rust’s f64::acosh() implementation, and adds regression tests to cover the affected cases.
Changes:
- Add a large-input fast path in
Math.acoshfor finiten > 1e154usingln(n) + LN_2. - Add regression tests for
Math.acosh(1e308)andMath.acosh(Number.MAX_VALUE).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| core/engine/src/builtins/math/mod.rs | Adds a large-finite-input fallback to avoid f64::acosh() overflow. |
| core/engine/src/builtins/math/tests.rs | Adds regression coverage for large finite inputs that previously produced Infinity. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test262 conformance changes
Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5230 +/- ##
===========================================
+ Coverage 47.24% 59.84% +12.60%
===========================================
Files 476 582 +106
Lines 46892 63459 +16567
===========================================
+ Hits 22154 37979 +15825
- Misses 24738 25480 +742 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Would it be better to follow the bounds established by the Boost library? It documents that the ln approximation is valid for numbers bigger than 1/√epsilon |
updated to use 1/sqrt(epsilon) matching the Boost threshold, thanks for the reference |
This Pull Request fixes/closes #5229.
It changes the following:
1/√f64::EPSILON(67_108_864.0), fall back ton.ln() + LN_2instead of callingf64::acosh()directly, avoiding an internalx²overflow that producesInfinity. Threshold follows the Boost math library convention.Math.acosh(1e308)andMath.acosh(Number.MAX_VALUE).Testing:
cargo test -p boa_engine math -- --nocaptureSpec reference: https://tc39.es/ecma262/#sec-math.acosh