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

Ensure Ryu.writeexp doesn't round past starting position #37546

Merged
merged 1 commit into from
Sep 12, 2020
Merged

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Sep 12, 2020

Fixes #37539. The issue here was the Ryu.writeexp code got to the
rounding section and started rounding 0.999 up to precision of 1, but
because the format string specifies a space before the number, it kept
rounding the space "digit", which messed up the final string. The
solution proposed here keeps track of the original starting pos when
we start writeexp and terminates the rounding sequence if we get
there.

I also checked Ryu.writefixed, because it has similar rounding code,
but it doesn't fail on quite the same case because it explicitly keeps
track of the decimal point and will terminate rounding based on that in
some cases. I did, however, manage to reproduce with 9.999, because
the rounding then extends before the decimal point, so a similar fix is
applied to writefixed.

Fixes #37539. The issue here was the `Ryu.writeexp` code got to the
rounding section and started rounding `0.999` up to precision of 1, but
because the format string specifies a space before the number, it kept
rounding the space "digit", which messed up the final string. The
solution proposed here keeps track of the original starting `pos` when
we start `writeexp` and terminates the rounding sequence if we get
there.

I also checked `Ryu.writefixed`, because it has similar rounding code,
but it doesn't fail on quite the same case because it explicitly keeps
track of the decimal point and will terminate rounding based on that in
some cases. I did, however, manage to reproduce with `9.999`, because
the rounding then extends before the decimal point, so a similar fix is
applied to `writefixed`.
@quinnj quinnj merged commit 9d41eb3 into master Sep 12, 2020
@quinnj quinnj deleted the jq/37539 branch September 12, 2020 18:47
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.

@printf formats 0.999 as !0.0e-1
1 participant