Skip to content

floating-point range may throw InexactError when it tries to convert NaN to an integer #58975

Open
@nsajko

Description

@nsajko
julia> range(start = Float16(0), stop = Float16(0.0004), length = 2^16)
ERROR: InexactError: Int64(NaN16)
Stacktrace:
  [1] Int64
    @ ./float.jl:923 [inlined]
  [2] convert
    @ ./number.jl:7 [inlined]
  [3] _round_convert
    @ ./rounding.jl:480 [inlined]
  [4] round
    @ ./rounding.jl:479 [inlined]
  [5] round
    @ ./rounding.jl:477 [inlined]
  [6] _linspace(start::Float16, stop::Float16, len::Int64)
    @ Base ./twiceprecision.jl:679
  [7] range_start_stop_length(start::Float16, stop::Float16, len::Int64)
    @ Base ./twiceprecision.jl:665
  [8] _range
    @ ./range.jl:174 [inlined]
  [9] #range#31
    @ ./range.jl:160 [inlined]
 [10] top-level scope
    @ REPL[1]:1

julia> versioninfo()
Julia Version 1.12.0-beta4
Commit 600ac61d3d2 (2025-06-05 07:03 UTC)
Build Info:
  Official https://julialang.org release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, znver2)
  GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 8 virtual cores)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions