Skip to content

@sprintf throws a bound error - but only on some inputs. #22137

@sbromberger

Description

@sbromberger

Perhaps related to #22126 ?

julia> @sprintf("%.330f", 2)
"2.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

julia> @sprintf("%.330f", 2.1)
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

julia> versioninfo()
Julia Version 0.7.0-DEV.373
Commit 82e9638225 (2017-05-28 01:51 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin16.5.0)
  CPU: Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, skylake)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviordisplay and printingAesthetics and correctness of printed representations of objects.strings"Strings!"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions