fix(builtins): correct toPrecision output for subnormal floats#5226
fix(builtins): correct toPrecision output for subnormal floats#5226HiteshShonak wants to merge 3 commits intoboa-dev:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Number.prototype.toPrecision for extremely small (including subnormal) f64 values where fixed-point formatting at 100 fractional digits collapses to all zeros, by falling back to scientific formatting to derive the correct mantissa/exponent.
Changes:
- Detects the “all zeros” fixed-point formatting case and derives digits/exponent from scientific notation instead.
- Adds regression tests covering
Number.MIN_VALUE.toPrecision(1)and(2)to prevent reintroducing the bug.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| core/engine/src/builtins/number/mod.rs | Adds scientific-notation fallback when fixed formatting loses all significant digits, fixing exponent/mantissa extraction. |
| core/engine/src/builtins/number/tests.rs | Adds regression coverage for Number.MIN_VALUE precision formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Test262 conformance changes
Fixed tests (1):Tested main commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5226 +/- ##
===========================================
+ Coverage 47.24% 59.71% +12.47%
===========================================
Files 476 589 +113
Lines 46892 63415 +16523
===========================================
+ Hits 22154 37869 +15715
- Misses 24738 25546 +808 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This Pull Request fixes/closes #5225.
It changes the following:
format!("{this_num:.100}")collapses a subnormal float to all zeros, fall back to scientific notation formatting to correctly extract the mantissa and exponent.Number.MIN_VALUE.toPrecision(1)andtoPrecision(2).Testing:
cargo test -p boa_engine number -- --nocaptureSpec reference: https://tc39.es/ecma262/#sec-number.prototype.toprecision