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

Grisu._show() with 1 digit precision shows 2 digits #6885

Closed
nalimilan opened this issue May 19, 2014 · 2 comments
Closed

Grisu._show() with 1 digit precision shows 2 digits #6885

nalimilan opened this issue May 19, 2014 · 2 comments

Comments

@nalimilan
Copy link
Member

This behavior may be misleading since I would consider that 2.0e-12 means the 0 is significant, which isn't the case with the second command below.

julia> sprint(Base.Grisu._show, 2.45e-12, Base.Grisu.PRECISION, 2, true)
"2.4e-12"

julia> sprint(Base.Grisu._show, 2.45e-12, Base.Grisu.PRECISION, 1, true)
"2.0e-12"

On the other hand, @printf (which uses a different definition for the precision) returns:

julia> @printf("%.0e", 2.45e-12)
2e-12

I guess an argument in favor of Grisu's behavior is that one gets a standard representation where 2.0 is necessarily a float, i.e. it cannot be mistakenly parsed back as an integer before the parser finds out there's an exponent part. But float("2e-12") works, so that's apparently not a problem.

@jiahao
Copy link
Member

jiahao commented May 19, 2014

Oddly similar to #6608

@nalimilan
Copy link
Member Author

Ah, indeed, this must be a duplicate.

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

No branches or pull requests

2 participants