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:
Node.js output:
node -e 'console.log(Number.MIN_VALUE.toPrecision(1))'
# 5e-324
Expected 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
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
From repo root:
cargo run --bin boa -- -e 'console.log(Number.MIN_VALUE.toPrecision(1))'Boa output:
Node.js output:
Expected behavior
toPrecision()should return correctly rounded significant digits for all finite values including subnormals, matching Node.js and browser behavior.Build environment:
Additional context
Root cause is in
core/engine/src/builtins/number/mod.rs-format!("{this_num:.100}")collapses subnormal values to all zeros, causingflt_str_to_expto return a wrong positive exponent.Spec reference: https://tc39.es/ecma262/#sec-number.prototype.toprecision