Skip to content

Commit

Permalink
fix fallback floating-point isless for -NaN, NaN (#25376)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jan 4, 2018
1 parent 068f94b commit edeb002
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/operators.jl
Expand Up @@ -121,9 +121,9 @@ values such as `NaN`.
"""
function isless end

isless(x::AbstractFloat, y::AbstractFloat) = (!isnan(x) & isnan(y)) | signless(x, y) | (x < y)
isless(x::Real, y::AbstractFloat) = (!isnan(x) & isnan(y)) | signless(x, y) | (x < y)
isless(x::AbstractFloat, y::Real ) = (!isnan(x) & isnan(y)) | signless(x, y) | (x < y)
isless(x::AbstractFloat, y::AbstractFloat) = (!isnan(x) & (isnan(y) | signless(x, y))) | (x < y)
isless(x::Real, y::AbstractFloat) = (!isnan(x) & (isnan(y) | signless(x, y))) | (x < y)
isless(x::AbstractFloat, y::Real ) = (!isnan(x) & (isnan(y) | signless(x, y))) | (x < y)


function ==(T::Type, S::Type)
Expand Down
7 changes: 7 additions & 0 deletions test/mpfr.jl
Expand Up @@ -490,6 +490,13 @@ end
# total ordering
@test isless(big(-0.0), big(0.0))
@test isless(big(1.0), big(NaN))
@test isless(big(Inf), big(NaN))
@test isless(big(Inf), -big(NaN))
@test !isless(big(NaN), big(NaN))
@test !isless(big(-NaN), big(NaN))
@test !isless(-big(NaN), big(NaN))
@test !isless(-big(NaN), big(1.0))
@test !isless(-big(NaN), 1.0)

# cmp
@test cmp(big(-0.0), big(0.0)) == -1
Expand Down
2 changes: 2 additions & 0 deletions test/numbers.jl
Expand Up @@ -720,6 +720,8 @@ end
@test !isless(+NaN,+Inf)
@test !isless(+NaN,-NaN)
@test !isless(+NaN,+NaN)
@test !isless(+NaN,1)
@test !isless(-NaN,1)

@test isequal( 0, 0.0)
@test isequal( 0.0, 0)
Expand Down

0 comments on commit edeb002

Please sign in to comment.