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

Fix rounding cases for fixed-width printing in ryu routines #40321

Merged
merged 1 commit into from
Apr 2, 2021

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Apr 2, 2021

Fixes #40303. When printing values to fixed widths through the
Ryu.writefixed or Ryu.writeexp routines, we have a "cleanup" section
after a value has been printed to see if it needs to be rounded given
the input precision and width. The core issue was the terminating
condition: it previously only checked if we were at the start of a
buffer or had encountered the '-' character. Via Printf formatting,
however, it also allows specifying the '+' and ' ' characters to
preceed a formatted number. Hence, in the OP, the '1' character was
getting "rounded" up to the ',' character. The fix here is correctly
checking if the plus or space options were passed to the routine and
if so, include those in our rounding termination check. The original
issue only reported the "plus" case for the f format specifier, but
the same bug affects the e format specifier and the "space" option.

Fixes #40303. When printing values to fixed widths through the
`Ryu.writefixed` or `Ryu.writeexp` routines, we have a "cleanup" section
after a value has been printed to see if it needs to be rounded given
the input precision and width. The core issue was the terminating
condition: it previously only checked if we were at the start of a
buffer or had encountered the `'-'` character. Via Printf formatting,
however, it also allows specifying the `'+'` and `' '` characters to
preceed a formatted number. Hence, in the OP, the `'1'` character was
getting "rounded" up to the `','` character. The fix here is correctly
checking if the `plus` or `space` options were passed to the routine and
if so, include those in our rounding termination check. The original
issue only reported the "plus" case for the `f` format specifier, but
the same bug affects the `e` format specifier and the "space" option.
@KristofferC KristofferC added backport 1.6 Change should be backported to release-1.6 bugfix This change fixes an existing bug labels Apr 2, 2021
@quinnj quinnj merged commit 8c3164c into master Apr 2, 2021
@quinnj quinnj deleted the jq/40303.2 branch April 2, 2021 19:40
@KristofferC KristofferC mentioned this pull request Apr 4, 2021
33 tasks
@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sprintf creates wrong string
2 participants