Repository navigation
Fix leading zeros in format_to_fixed for small numbers - #67
Merged
Merged
Conversation
format_to_fixed for small numbers
Contributor
Author
|
FYI, the Clippy failure is pre-existing on main and unrelated to this PR. Rust 1.100 deprecates Happy to send a separate PR for this if needed! |
Member
|
@devrelu please do so! It sounds like a pretty straightforward change, and I can review it ASAP |
devrelu
force-pushed
the
fix/to-fixed-leading-zero
branch
from
November 22, 2026 11:06
0ca931f to
46e09be
Compare
Contributor
Author
|
Thanks! Opened #68 for the Clippy fix. Once it's merged, I'll rebase this PR so CI goes green. |
devrelu
force-pushed
the
fix/to-fixed-leading-zero
branch
from
November 22, 2026 11:13
46e09be to
d09adeb
Compare
HalidOdat
approved these changes
Nov 22, 2026
HalidOdat
left a comment
Member
There was a problem hiding this comment.
Looks great! Thank you for the contribution! 🙌
devrelu
force-pushed
the
fix/to-fixed-leading-zero
branch
from
November 22, 2026 12:24
d09adeb to
9576e21
Compare
Member
|
I'll do a patch release after this is merged 😄 |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This Pull Request fixes #66.
format64_to_fixedpreviously started the fractional block loop ati = 0. For blocks belowMIN_BLOCK_2[idx], the indexpfell into the previous row ofPOW10_SPLIT_2, causing digits computed from the wrong multiplier to be written where leading zeros belong:This PR restores the zero-fill logic from the original C d2fixed implementation, which skips those blocks:
Changes
9 * min_blockzeros up front and start the fractional loop atmin_block.min_exponent_boundrytests, which previously asserted the buggy output. With exponent bits 0x294, the value is ~5.3e-110, sotoFixed(100)must be all zeros. The actual last all-zero exponents at 100 fractional digits are 0x2B1 (zero mantissa) and 0x2B0 (full mantissa), verified against V8 across all exponents.Testing
cargo testandcargo test --features smallpass.Number.prototype.toFixedacross ~300k random (f64, digits) pairs—plus a sweep of1.2345 * 10^efor e in-330..25across all digit counts0..=100produced zero mismatches.