Skip to content

Commit

Permalink
leq for reals falls back to le and eq (#46341)
Browse files Browse the repository at this point in the history
  • Loading branch information
jishnub authored Aug 17, 2022
1 parent 9f78e04 commit ef511c9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/promotion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ xor(x::T, y::T) where {T<:Integer} = no_op_err("xor", T)

(==)(x::T, y::T) where {T<:Number} = x === y
(< )(x::T, y::T) where {T<:Real} = no_op_err("<" , T)
(<=)(x::T, y::T) where {T<:Real} = no_op_err("<=", T)
(<=)(x::T, y::T) where {T<:Real} = (x == y) | (x < y)

rem(x::T, y::T) where {T<:Real} = no_op_err("rem", T)
mod(x::T, y::T) where {T<:Real} = no_op_err("mod", T)
Expand Down
11 changes: 11 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,14 @@ end
illtype = Vector{Core._typevar(:T, Union{}, Any)}
@test Returns(illtype) == Returns{DataType}(illtype)
end

@testset "<= (issue #46327)" begin
struct A46327 <: Real end
Base.:(==)(::A46327, ::A46327) = false
Base.:(<)(::A46327, ::A46327) = false
@test !(A46327() <= A46327())
struct B46327 <: Real end
Base.:(==)(::B46327, ::B46327) = true
Base.:(<)(::B46327, ::B46327) = false
@test B46327() <= B46327()
end

2 comments on commit ef511c9

@mgkuhn
Copy link
Contributor

@mgkuhn mgkuhn commented on ef511c9 Aug 17, 2022

Choose a reason for hiding this comment

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

Wouldn't deleting line 501 have been sufficient, since there is already

<=(x, y) = (x < y) | (x == y)

in base/operators.jl ?

@mgkuhn
Copy link
Contributor

@mgkuhn mgkuhn commented on ef511c9 Aug 17, 2022

Choose a reason for hiding this comment

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

Also shouldn't it have been (x < y) || (x == y) to use logic shortcut instead of Boolean or, and to test the more likely to succeed condition first?

Please sign in to comment.