Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Small numbers formatted incorrectly or crash #84

Open
jagot opened this issue Aug 13, 2020 · 2 comments
Open

Small numbers formatted incorrectly or crash #84

jagot opened this issue Aug 13, 2020 · 2 comments

Comments

@jagot
Copy link

jagot commented Aug 13, 2020

julia> using Formatting

julia> fmt = FormatExpr("{1:+11.3e}")
FormatExpr("", "", Formatting.FormatEntry[Formatting.FormatEntry(Formatting.ArgSpec(1, false, identity), FormatSpec
  cls   = f
  typ   = e
  fill  =
  align = >
  sign  = +
  width = 11
  prec  = 3
  ipre  = false
  zpad  = false
  tsep  = false
)], String[])

julia> format(fmt, 9.99999999e-308)
"+9.1000e-308"

Similar to #71?

This is worse, though:

julia> format(fmt, 1.0e-309)
ERROR: InexactError: trunc(Int64, Inf)
Stacktrace:
 [1] trunc at ./float.jl:703 [inlined]
 [2] trunc at ./float.jl:359 [inlined]
 [3] _pfmt_floate(::Base.GenericIOBuffer{Array{UInt8,1}}, ::Char, ::Int64, ::Float64, ::Int64, ::Int64, ::Char) at /Users/jagot/.julia/packages/Formatting/LU9hd/src/fmtcore.jl:204
 [4] _pfmt_e(::Base.GenericIOBuffer{Array{UInt8,1}}, ::FormatSpec, ::Float64) at /Users/jagot/.julia/packages/Formatting/LU9hd/src/fmtcore.jl:251
 [5] printfmt(::Base.GenericIOBuffer{Array{UInt8,1}}, ::FormatSpec, ::Float64) at /Users/jagot/.julia/packages/Formatting/LU9hd/src/fmtspec.jl:190
 [6] printfmt(::Base.GenericIOBuffer{Array{UInt8,1}}, ::FormatExpr, ::Float64) at /Users/jagot/.julia/packages/Formatting/LU9hd/src/formatexpr.jl:147
 [7] sprint(::Function, ::FormatExpr, ::Vararg{Any,N} where N; context::Nothing, sizehint::Int64) at ./strings/io.jl:105
 [8] sprint at ./strings/io.jl:101 [inlined]
 [9] format(::FormatExpr, ::Float64) at /Users/jagot/.julia/packages/Formatting/LU9hd/src/formatexpr.jl:165
 [10] top-level scope at REPL[10]:1
(time-propagation) pkg> st Formatting
Status `~/work/project/Project.toml`
  [59287772] Formatting v0.4.1
@jmkuhn
Copy link
Contributor

jmkuhn commented Aug 24, 2020

Your 2 examples expose 2 different issues.

The first is Julia issue #37171.

julia> round(9.99999999e-308, sigdigits = 4)
9.99999999e-308

when the desired result is 1.0e-307.

The second example was an issue with Formatting and has been fixed in Master by #85.

@jmkuhn
Copy link
Contributor

jmkuhn commented Sep 7, 2021

Fixed in Julia Master (1.8) JuliaLang/julia#42033

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants