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

do not trim trailing zeros of integral part #40755

Merged
merged 1 commit into from
May 11, 2021

Conversation

bicycle1885
Copy link
Member

@bicycle1885 bicycle1885 commented May 9, 2021

Currently, setting trimtrailingzeros = true of Ryu.writefixed may trim trailing zeros of integral part if precision = 0, which is surprising because it changes the scale of the value:

using Base: Ryu

@show Ryu.writefixed(1.25e+5, 0, false, false, false, UInt8('.'), true)
@show Ryu.writefixed(1.25e+5, 1, false, false, false, UInt8('.'), true)
@show Ryu.writefixed(1.25e+5, 2, false, false, false, UInt8('.'), true)
Ryu.writefixed(125000.0, 0, false, false, false, UInt8('.'), true) = "125"
Ryu.writefixed(125000.0, 1, false, false, false, UInt8('.'), true) = "125000"
Ryu.writefixed(125000.0, 2, false, false, false, UInt8('.'), true) = "125000"

This PR fixes the problem so that only trailing zeros of fractional part are trimmed. I think this change is not breaking because Ryu is not a part of the official API.

Copy link
Member

@quinnj quinnj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@quinnj quinnj merged commit 79b8af2 into JuliaLang:master May 11, 2021
@bicycle1885 bicycle1885 deleted the ryu-trimzeros branch May 11, 2021 03:55
@bicycle1885 bicycle1885 added the backport 1.6 Change should be backported to release-1.6 label May 11, 2021
@KristofferC KristofferC mentioned this pull request May 11, 2021
45 tasks
Comment on lines +552 to +554
@show Ryu.writefixed(1.25e+5, 0, false, false, false, UInt8('.'), true) == "125000"
@show Ryu.writefixed(1.25e+5, 1, false, false, false, UInt8('.'), true) == "125000"
@show Ryu.writefixed(1.25e+5, 2, false, false, false, UInt8('.'), true) == "125000"
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/@show/@test/ 😂

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump (@quinnj, as reviewer)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KristofferC KristofferC removed the backport 1.6 Change should be backported to release-1.6 label Jul 12, 2021
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.

None yet

4 participants