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

Formatting large float throws InexactError #102

@oxdc

Description

@oxdc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions