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

Formatting large float throws InexactError #102

Open
oxdc opened this issue Aug 12, 2021 · 1 comment
Open

Formatting large float throws InexactError #102

oxdc opened this issue Aug 12, 2021 · 1 comment

Comments

@oxdc
Copy link

oxdc commented Aug 12, 2021

intv = trunc(Integer, rax)

julia> using Formatting

julia> fmt(FormatSpec("15.6f"), 1e5)  # OK
"  100000.000000"

julia> fmt(FormatSpec("15.6f"), 1e10)  # OK, even the width is too small
"10000000000.000000"

julia> fmt(FormatSpec("15.6f"), 1e20)  # Error, the float is too large to be represented by Int64
ERROR: InexactError: trunc(Int64, 1.0e20)
Stacktrace:
 [1] trunc
   @ .\float.jl:716 [inlined]
 [2] trunc
   @ .\float.jl:291 [inlined]
 [3] _pfmt_f(out::IOBuffer, fs::FormatSpec, x::Float64)
   @ Formatting ~\.julia\packages\Formatting\BwWBf\src\fmtcore.jl:176
 [4] printfmt(io::IOBuffer, fs::FormatSpec, x::Float64)
   @ Formatting ~\.julia\packages\Formatting\BwWBf\src\fmtspec.jl:190
 [5] sprint(::Function, ::FormatSpec, ::Vararg{Any, N} where N; context::Nothing, sizehint::Int64)
   @ Base .\strings\io.jl:105
 [6] sprint
   @ .\strings\io.jl:101 [inlined]
 [7] fmt(fs::FormatSpec, x::Float64)
   @ Formatting ~\.julia\packages\Formatting\BwWBf\src\fmtspec.jl:205
 [8] top-level scope
   @ REPL[16]:1

This could be fixed by changing Integer to BigInt.

ScottPJones referenced this issue in JuliaString/Format.jl Feb 14, 2024
@ScottPJones
Copy link
Collaborator

Note: this has been fixed in Format.jl.

ScottPJones referenced this issue in JuliaString/Format.jl Feb 14, 2024
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