Skip to content

correct the fixed-mode halfway example in the dtoa headers - #332

Open
Ramya-9353 wants to merge 1 commit into
google:masterfrom
Ramya-9353:fixed-halfway-doc-example
Open

Ramya-9353 wants to merge 1 commit into
google:masterfrom
Ramya-9353:fixed-halfway-doc-example

Conversation

@Ramya-9353

Copy link
Copy Markdown
Contributor

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant