-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 throws a bound error - but only on some inputs. #22137
Comments
Issue also exists on 0.5 and 0.6. julia> @sprintf("%.325f", nextfloat(0.0))
"0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049"
julia> @sprintf("%.325f", 1.0)
ERROR: BoundsError: attempt to access 326-element Array{UInt8,1} at index [327]
Stacktrace:
[1] bignumdtoa(::Float64, ::Int64, ::Int64, ::Array{UInt8,1}, ::Array{Base.Grisu.Bignums.Bignum,1}) at ./grisu/bignum.jl:68
[2] grisu(::Float64, ::Int64, ::Int64, ::Array{UInt8,1}, ::Array{Base.Grisu.Bignums.Bignum,1}) at ./grisu/grisu.jl:51
[3] fix_dec(::Float64, ::Int64) at ./printf.jl:953
[4] fix_dec(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Float64, ::String, ::Int64, ::Int64, ::Char) at ./printf.jl:801 The exception can occur with printing less decimal places when the input is large: julia> v = prevfloat(typemax(Float64))
1.7976931348623157e308
julia> @sprintf("%.16f", v)
"179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0000000000000000"
julia> @sprintf("%.17f", v)
ERROR: BoundsError: attempt to access 326-element Array{UInt8,1} at index [327]
Stacktrace:
[1] bignumdtoa(::Float64, ::Int64, ::Int64, ::Array{UInt8,1}, ::Array{Base.Grisu.Bignums.Bignum,1}) at ./grisu/bignum.jl:68
[2] grisu(::Float64, ::Int64, ::Int64, ::Array{UInt8,1}, ::Array{Base.Grisu.Bignums.Bignum,1}) at ./grisu/grisu.jl:51
[3] fix_dec(::Float64, ::Int64) at ./printf.jl:953
[4] fix_dec(::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Float64, ::String, ::Int64, ::Int64, ::Char) at ./printf.jl:801 |
Off by one error? looks like Line 952 in ecc3a81
|
This is still an issue in 1.1.0 |
@quinnj, I think you're the most recent person to have dived into the Printf code, would it be possible for you to take a look at this? |
So, I somehow totally missed that I was pinged here; sorry about that. But, as fate would have it, I'm going over old numeric display issues in light of #32799 and it looks like this would be solved by that PR. Now, we still need to work out the exact details of |
Fixed in #32859 |
Perhaps related to #22126 ?
The text was updated successfully, but these errors were encountered: