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

@sprintf %g precision is sometimes not honored #41801

Closed
bjarthur opened this issue Aug 6, 2021 · 3 comments
Closed

@sprintf %g precision is sometimes not honored #41801

bjarthur opened this issue Aug 6, 2021 · 3 comments
Labels
needs more info Clarification or a reproducible example is required

Comments

@bjarthur
Copy link
Contributor

bjarthur commented Aug 6, 2021

julia> x=9.98402083170343e-31
9.98402083170343e-31

julia> @sprintf("%0.1g", x)
"1e-30"

julia> @sprintf("%0.2g", x)              ### not correct
"9.999999999999999e-31"

julia> @sprintf("%0.3g", x)
"9.98e-31"

julia> @sprintf("%0.4g", x)
"9.984e-31"
@bicycle1885
Copy link
Member

I cannot reproduce it on the latest master branch and on Julia 1.6.2. Which Julia version did you use?

julia> using Printf

julia> x=9.98402083170343e-31
9.98402083170343e-31

julia> @sprintf("%0.1g", x)
"1e-30"

julia> @sprintf("%0.2g", x)              ### not correct
"1e-30"

julia> @sprintf("%0.3g", x)
"9.98e-31"

julia> @sprintf("%0.4g", x)
"9.984e-31"

julia> versioninfo()
Julia Version 1.8.0-DEV.310
Commit cb30aa7a08* (2021-08-06 03:11 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: AMD Ryzen 9 3950X 16-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, znver2)
Environment:
  JULIA_PROJECT = @.

@bicycle1885 bicycle1885 added the needs more info Clarification or a reproducible example is required label Aug 6, 2021
@aramirezreyes
Copy link
Contributor

aramirezreyes commented Aug 10, 2021

I can reproduce with v1.6.0 in macOS

but not in today's master.

Can it be related to #40689?

@bjarthur
Copy link
Contributor Author

bjarthur commented Aug 11, 2021

my bad, i was using 1.6.1 and should've checked a more recent version. sorry. WFM on 1.7-beta3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info Clarification or a reproducible example is required
Projects
None yet
Development

No branches or pull requests

3 participants