Skip to content

parse(Float32,x) doesn't detect overflow/underflow on windows #46544

Open
@c42f

Description

On linux, we have

julia> parse(Float32, "10e100")
ERROR: ArgumentError: cannot parse "10e100" as Float32

However, on windows with Julia 1.8, we have

julia> parse(Float32, "10e100")
Inf32

Similarly for underflow, as in parse(Float32, "1e-100") (though arguably it's less clear that we should throw in this case? We generally accept loss of precision as an unavoidable part of float parsing in general.)


I think this can be traced to a failure in whichever C runtime we're using on windows, as a ccall to jl_strtof_c results in:

julia> Libc.errno(0)
       @ccall jl_strtof_c("10e100"::Cstring, Ref{Ptr{UInt8}}(C_NULL)::Ptr{Ptr{UInt8}})::Cfloat
Inf32

julia> Libc.errno()
0

(on linux, we have Libc.errno() == Libc.ERANGE after the same code is run.)

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorsystem:windowsAffects only Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions