Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ Test whether a number value is a NaN, an indeterminate value which is neither an
nor a finite number ("not a number").
"""
isnan(x::AbstractFloat) = (x != x)::Bool
isnan(x::Real) = false
isnan(x::Number) = false

isfinite(x::AbstractFloat) = x - x == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about isfinite? I think it is also not defined for Number?

Also a test would be good so this does not get deleted by accident.

struct N38232 <: Number end
@test isfinite(N38232())
@test !isnan(N38232())

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isfinite is not true by default. It is using Base.decompose for Real which is not exposed therefore I would leave the decision what to do it for a separate PR (fell free to open it; I need isnan for DataFrames.jl, as NaN has a special treatment in comparisons).

I will add the test you suggest - thank you.

isfinite(x::Real) = decompose(x)[3] != 0
Expand Down
5 changes: 5 additions & 0 deletions test/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,8 @@ end
@test ≈(1.0; atol=1).(1.0:3.0) == [true, true, false]

end

@testset "isnan for Number" begin
struct CustomNumber <: Number end
@test !isnan(CustomNumber())
end