Bugs in isfinite(), isnan and isinf()?

the following seems to be bugs to me:

julia> isfinite.([NaN, Inf, 2.0, -Inf])
4-element BitArray{1}:
 1
 1
 1
 1

julia> isinf.([NaN, Inf, 2.0, -Inf])
4-element BitArray{1}:
 0
 0
 0
 0

julia> isnan.([NaN, Inf, 2.0, -Inf])
4-element BitArray{1}:
 0
 0
 0
 0

am I missing something? or are they really bugs? I’m using 1.5.3

I think you’ve redefined something really fundamental. I can’t reproduce any of these.

1 Like

oh yes! they back to normal after I start with --startup-file=no

but I did not redefine them!!! maybe some packages did that??? need to check…

1 Like

I found that it’s --math-mode=fast makes them crazy:

julia> @enter isfinite(NaN)
[ Info: tracking Base
In isfinite(x) at float.jl:554
>554  isfinite(x::AbstractFloat) = x - x == 0

About to run: (-)(0.0, 0.0)

from the above, I see that NaN is indeed passed as 0.0 into isfinite() !
is it the expected behavior when --math-mode=fast? thanks.

Yes. fastmath implies that all values are finite, and produces undefined behavior if that is not true.

3 Likes

could u please point to the appropriate documentation about math-mode behaviors? dunno why I can’t find the docs. thanks.

Is this what you’re looking for? Mathematics · The Julia Language

not exactly.

I want document on above :point_up:

I think it’s a statement that has huge implications. Wanna see it in official doc.

" Use @fastmath to allow floating point optimizations that are correct for real numbers, but lead to differences for IEEE numbers." Performance Tips · The Julia Language. By “IEEE Numbers”, this is explicitly calling out things like -0.0 NaN and Inf

See fast-math and finite-math-only on the gcc man pages: gcc(1): GNU project C/C++ compiler - Linux man page

EDIT: the Julia documentation mentions that @fastmath corresponds to the fast-math option of clang which in its documentation is pretty clear about NaN and +-Inf as well:

Allow floating-point optimizations that assume arguments and results are not NaNs or ±Inf.

1 Like

thanks.

but I think your earlier statement is much more concise and clear. It should be put in official documentation…

2 Likes

I just noticed that if you click on LLVM Fast-Math flags, which is prominently mentioned in the @fastmath documentation, the first two points are

1 Like