Julia: Inconsistency with BigFloat

Created on 24 Jun 2020  路  6Comments  路  Source: JuliaLang/julia


There is some inconsistency with BigFloat when given NaN

julia> Float16(NaN) === Float16(NaN)
true
julia> Float32(NaN) === Float32(NaN)
true
julia> Float64(NaN) === Float64(NaN)
true

But

julia> BigFloat(NaN) === BigFloat(NaN)
false

All 6 comments

This is only because BigFloat contains a pointer, and therefore separately constructed BigFloat instances are always distinct under ===. This doesn't just affect NaN, but any BigFloat values, for example:

julia> BigFloat(42) === BigFloat(42)
false

So there is no way to compare NaNs for BigFloat?

There is isequal for that:

julia> isequal(BigFloat(NaN), BigFloat(NaN))
true

Better to use isnan if you want to check for NaN

Isn't isequal(Float16(NaN), Float64(NaN)) too flexible.

No, that is intended.

isequal treats all floating-point NaN values as equal to each other,

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sbromberger picture sbromberger  路  3Comments

yurivish picture yurivish  路  3Comments

ararslan picture ararslan  路  3Comments

helgee picture helgee  路  3Comments

Keno picture Keno  路  3Comments