Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format initial string to specific precision, so rounding works. #4159

Merged
merged 1 commit into from Oct 12, 2016

Conversation

headius
Copy link
Member

@headius headius commented Sep 15, 2016

The logic in our double-based sprintf logic attempts to round
values manually by inspecting a long-form version of the double.
If we need to round, and the next digit is a five, it will round
toward zero (truncate) iff that five is the last digit in the long
unrounded string. This appears to have been an attempt to mimic
C printf's behavior of rounding "true half" to even in the
presence of inaccurately-represented IEEE754 decimals.

This commit changes the pre-formatting to actually format with the
specified precision, allowing NumberFormat's default HALF_EVEN
logic to to the work for us.

Fixes #4157.

The logic in our double-based sprintf logic attempts to round
values manually by inspecting a long-form version of the double.
If we need to round, and the next digit is a five, it will round
toward zero (truncate) iff that five is the last digit in the long
unrounded string. This appears to have been an attempt to mimic
C printf's behavior of rounding "true half" to even in the
presence of inaccurately-represented IEEE754 decimals.

This commit changes the pre-formatting to actually format with the
specified precision, allowing NumberFormat's default HALF_EVEN
logic to to the work for us.

Fixes jruby#4157.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants