Repository navigation
round decimal to float once - #123
Merged
Merged
Conversation
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.
decimal.to_floatrounds once, in the VM, instead of turning each half into a Float first.It used to be
float.from_int(units) / float.from_int(10^scale). Both halves clamp at the largest Float, so once either passed it the answer was wrong:10^400at 399 places read as1.0instead of10.0. Every operand of a big enough decimal hit it, andmulreaches those scales on its own.Now a private
float__from_decimal(units, scale)builds<units>e-<scale>and parses it, so Rust's own decimal-to-binary conversion rounds to the nearest Float, subnormals included, andValue::floatkeeps the no-NaN rule: too large is the largest Float, too small is0.0.Checked in the test:
10^400at 399 places is10.0; a negative one keeps its sign; two decimals past the largest Float both give the largest Float;10^-400is0.0; andnew(1, 1)is the same Float as the literal0.1.All seven CI gates pass locally. hawk ran for the host target, and nothing here is gated on a cfg.