Repository navigation
correct the fixed-mode halfway example in the dtoa headers - #332
Open
Ramya-9353 wants to merge 1 commit into
Open
Ramya-9353 wants to merge 1 commit into
Ramya-9353 wants to merge 1 commit into
Conversation
The FIXED-mode comments in double-to-string.h, fixed-dtoa.h and bignum-dtoa.h illustrate the halfway rule with toFixed(0.15, 2) returning buffer "2", point 0. The library returns "15", point 0, and 0.15 is not a halfway case for a double at any digit count: the nearest double lies below the tie, so one digit gives "1" (the ToFixed tests pin "0.1"). Use the exactly representable toFixed(0.25, 1) -> "3", point 0 instead and pin it at the FastFixedDtoa and BignumDtoa layers.
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.
Repro: DoubleToAscii(0.15, FIXED, 2), FastFixedDtoa(0.15, 2) and BignumDtoa(0.15, BIGNUM_DTOA_FIXED, 2) return buffer "15", point 0, not the documented buffer "2", point 0.
Cause: 0.15 is not a halfway case for a double: the nearest value is 0.1499999999999999944..., below the tie, so even one requested digit yields "1" (the existing ToFixed test pins "0.1"), and with two digits nothing is cut at a tie.
Fix: illustrate the rule with the exactly representable halfway case toFixed(0.25, 1) -> buffer "3", point 0 in all three headers, and pin it with checks at the FastFixedDtoa and BignumDtoa layers, matching the ToFixed(0.25, 1) -> "0.3" case already in test-conversions.cc.