Skip to content

Commit 63e30db

Browse files
jishnubKristofferC
authored andcommitted
leq for reals falls back to le and eq (#46341)
(cherry picked from commit ef511c9)
1 parent a9367cb commit 63e30db

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

base/promotion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ xor(x::T, y::T) where {T<:Integer} = no_op_err("xor", T)
409409

410410
(==)(x::T, y::T) where {T<:Number} = x === y
411411
(< )(x::T, y::T) where {T<:Real} = no_op_err("<" , T)
412-
(<=)(x::T, y::T) where {T<:Real} = no_op_err("<=", T)
412+
(<=)(x::T, y::T) where {T<:Real} = (x == y) | (x < y)
413413

414414
rem(x::T, y::T) where {T<:Real} = no_op_err("rem", T)
415415
mod(x::T, y::T) where {T<:Real} = no_op_err("mod", T)

test/operators.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,14 @@ end
254254
end
255255

256256
@test [Base.afoldl(+, 1:i...) for i = 1:40] == [i * (i + 1) ÷ 2 for i = 1:40]
257+
258+
@testset "<= (issue #46327)" begin
259+
struct A46327 <: Real end
260+
Base.:(==)(::A46327, ::A46327) = false
261+
Base.:(<)(::A46327, ::A46327) = false
262+
@test !(A46327() <= A46327())
263+
struct B46327 <: Real end
264+
Base.:(==)(::B46327, ::B46327) = true
265+
Base.:(<)(::B46327, ::B46327) = false
266+
@test B46327() <= B46327()
267+
end

0 commit comments

Comments
 (0)