fix issues 411,Reason: NewFromFloat returns the shortest decimal for round-trip.#418
fix issues 411,Reason: NewFromFloat returns the shortest decimal for round-trip.#4188xmx8 wants to merge 1 commit into
Conversation
…floating-point value (rather than the shortest round-trip representation).
|
why this PR has not been merged yet? |
mwoss
left a comment
There was a problem hiding this comment.
Thanks for opening and PR and helping to fix #411.
It looks great, however, this changes the public contract of NewFromFloat / NewFromFloat32 from "shortest round-trip representation" to "exact binary value," which is a breaking behavioral change.
Examples:
On master:
NewFromFloat(0.1).String() # "0.1"
NewFromFloat(0.3).String() # "0.3"On this branch:
NewFromFloat(0.1).String() # "0.1000000000000000055511151231257827021181583404541015625"
NewFromFloat(0.3).String() # "0.299999999999999988897769753748434595763683319091796875"Anyone comparing .String() output, persisting, etc, these values will be affected. The "shortest" behavior is the long-standing documented contract and is what most callers may rely on.
So maybe we could fix that narrower case from #411? I meant exact expansion only when the float has no fractional part while preserving shortest round-trip for fractional values?
If we would like to fix both, I would implement new public method like NewFromFloatExact
Perform an exact decimal expansion strictly based on the true binary floating-point value (rather than the shortest round-trip representation).,see:#411