-
-
Notifications
You must be signed in to change notification settings - Fork 616
Description
Describe the bug
Number.prototype.toPrecision() returns wrong output for subnormal floats. instead of the correct significant digits, boa returns a bogus value with a wrong positive exponent.
To Reproduce
Number.MIN_VALUE.toPrecision(1)
// returns "0e+101" in Boa, expected "5e-324"From repo root:
cargo run --bin boa -- -e 'console.log(Number.MIN_VALUE.toPrecision(1))'Boa output:
0e+101
Node.js output:
node -e 'console.log(Number.MIN_VALUE.toPrecision(1))'
# 5e-324Expected behavior
toPrecision() should return correctly rounded significant digits for all finite values including subnormals, matching Node.js and browser behavior.
Build environment:
- OS: Windows 11
- Version: 10.0.26200
- Target triple: x86_64-pc-windows-msvc
- Rustc version: rustc 1.94.0 (4a4ef493e 2026-03-02)
Additional context
Root cause is in core/engine/src/builtins/number/mod.rs - format!("{this_num:.100}") collapses subnormal values to all zeros, causing flt_str_to_exp to return a wrong positive exponent.
Spec reference: https://tc39.es/ecma262/#sec-number.prototype.toprecision
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels