From 29b79e93e9d7ef8be762ef98bf4f07ce3be5931f Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Mon, 8 Sep 2025 04:44:40 +0200 Subject: [PATCH 1/3] prevent adding methods to the functions `>` and `>=` As documented, the intended way to implement `>` is to add a method to `<`. Similarly with `>=`. A package should never add a method to either `>` or `>=`. --- src/values/compare.jl | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/src/values/compare.jl b/src/values/compare.jl index f778ce95..22f3d290 100644 --- a/src/values/compare.jl +++ b/src/values/compare.jl @@ -3,30 +3,18 @@ function (==)(x::Mag, y::Mag) 0 != ccall(@libarb(mag_equal), Cint, (Ref{Mag}, Ref{Mag}), x, y) end -function (!=)(x::Mag, y::Mag) - 0 == ccall(@libarb(mag_equal), Cint, (Ref{Mag}, Ref{Mag}), x, y) -end function (==)(x::ArbFloat{P}, y::ArbFloat{P}) where {P} 0 != ccall(@libarb(arf_equal), Cint, (Ref{ArbFloat}, Ref{ArbFloat}), x, y) end -function (!=)(x::ArbFloat{P}, y::ArbFloat{P}) where {P} - 0 == ccall(@libarb(arf_equal), Cint, (Ref{ArbFloat}, Ref{ArbFloat}), x, y) -end function (==)(x::ArbReal{P}, y::ArbReal{P}) where {P} 0 != ccall(@libarb(arb_equal), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) end -function (!=)(x::ArbReal{P}, y::ArbReal{P}) where {P} - 0 == ccall(@libarb(arb_equal), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) -end function (==)(x::ArbComplex{P}, y::ArbComplex{P}) where {P} 0 != ccall(@libarb(acb_equal), Cint, (Ref{ArbComplex}, Ref{ArbComplex}), x, y) end -function (!=)(x::ArbComplex{P}, y::ArbComplex{P}) where {P} - 0 == ccall(@libarb(acb_equal), Cint, (Ref{ArbComplex}, Ref{ArbComplex}), x, y) -end #> F(x::T,y::T), for F as {<, >, <=, >=} @@ -45,28 +33,16 @@ end function (<)(x::Mag, y::Mag) signbit(cmp(x, y)) end -function (>)(x::Mag, y::Mag) - signbit(cmp(y, x)) -end function (<=)(x::Mag, y::Mag) (x < y) || (x == y) end -function (>=)(x::Mag, y::Mag) - (x > y) || (x == y) -end function (<)(x::ArbFloat{P}, y::ArbFloat{P}) where {P} signbit(cmp(x, y)) end -function (>)(x::ArbFloat{P}, y::ArbFloat{P}) where {P} - signbit(cmp(y, x)) -end function (<=)(x::ArbFloat{P}, y::ArbFloat{P}) where {P} (x < y) || (x == y) end -function (>=)(x::ArbFloat{P}, y::ArbFloat{P}) where {P} - (x > y) || (x == y) -end function (<)(x::ArbReal{P}, y::ArbReal{P}) where {P} x = upperbound(x) @@ -74,26 +50,15 @@ function (<)(x::ArbReal{P}, y::ArbReal{P}) where {P} 0 != ccall(@libarb(arb_lt), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) end -function (>)(x::ArbReal{P}, y::ArbReal{P}) where {P} - x = lowerbound(x) - y = upperbound(y) - 0 != ccall(@libarb(arb_gt), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) -end - function (<=)(x::ArbReal{P}, y::ArbReal{P}) where {P} x < y || 0 != ccall(@libarb(arb_contains), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) end -function (>=)(x::ArbReal{P}, y::ArbReal{P}) where {P} - x > y || - 0 != ccall(@libarb(arb_contains), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) -end - # ArbComplex comparisons < > <= >= -for F in (:(==), :(!=), :(<), :(<=), :(>=), :(>), :isequal, :isless) +for F in (:(==), :(<), :(<=), :isequal, :isless) @eval begin $F(x::ArbFloat{P}, y::T) where {P, T<:Integer} = $F(promote(x, y)...,) From 6fa3b0c64a61594fec67d291939f68d43b8f39c9 Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Tue, 9 Sep 2025 17:56:49 +0200 Subject: [PATCH 2/3] revert deleting two methods to prevent changes in behavior --- src/values/compare.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/values/compare.jl b/src/values/compare.jl index 22f3d290..d813a418 100644 --- a/src/values/compare.jl +++ b/src/values/compare.jl @@ -50,11 +50,22 @@ function (<)(x::ArbReal{P}, y::ArbReal{P}) where {P} 0 != ccall(@libarb(arb_lt), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) end +function (>)(x::ArbReal{P}, y::ArbReal{P}) where {P} + x = lowerbound(x) + y = upperbound(y) + 0 != ccall(@libarb(arb_gt), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) +end + function (<=)(x::ArbReal{P}, y::ArbReal{P}) where {P} x < y || 0 != ccall(@libarb(arb_contains), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) end +function (>=)(x::ArbReal{P}, y::ArbReal{P}) where {P} + x > y || + 0 != ccall(@libarb(arb_contains), Cint, (Ref{ArbReal}, Ref{ArbReal}), x, y) +end + # ArbComplex comparisons < > <= >= From c8c03ebd9e52bd41d7e581181dff3cd3c088680a Mon Sep 17 00:00:00 2001 From: Neven Sajko Date: Tue, 9 Sep 2025 18:01:43 +0200 Subject: [PATCH 3/3] other reverts --- src/values/compare.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/values/compare.jl b/src/values/compare.jl index d813a418..3484e643 100644 --- a/src/values/compare.jl +++ b/src/values/compare.jl @@ -69,7 +69,7 @@ end # ArbComplex comparisons < > <= >= -for F in (:(==), :(<), :(<=), :isequal, :isless) +for F in (:(==), :(<), :(<=), :(>=), :(>), :isequal, :isless) @eval begin $F(x::ArbFloat{P}, y::T) where {P, T<:Integer} = $F(promote(x, y)...,)