Skip to content

Commit

Permalink
Only define new methods for rem instead of all binary operators
Browse files Browse the repository at this point in the history
They seemed to introduce several ambiguities.
  • Loading branch information
giordano committed Feb 16, 2025
1 parent a36deaa commit 0ae27e9
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions src/TracedRNumber.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,29 @@ for (jlop, hloop) in (
(:(Base.mod), :remainder),
(:(Base.rem), :remainder),
)
@eval begin
function $(jlop)(
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::TracedRNumber{T})
) where {T}
return Ops.$(hloop)(lhs, rhs)
end
@eval function $(jlop)(
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::TracedRNumber{T})
) where {T}
return Ops.$(hloop)(lhs, rhs)
end
end

function $(jlop)(
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::Number)
) where {T}
return Ops.$(hloop)(lhs, TracedUtils.promote_to(TracedRNumber{T}, rhs))
end
function Base.rem(
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::Number)
) where {T}
return Ops.remainder(lhs, TracedUtils.promote_to(TracedRNumber{T}, rhs))
end

function $(jlop)(
@nospecialize(lhs::Number), @nospecialize(rhs::TracedRNumber{T})
) where {T}
return Ops.$(hloop)(TracedUtils.promote_to(TracedRNumber{T}, lhs), rhs)
end
end
function Base.rem(
@nospecialize(lhs::Number), @nospecialize(rhs::TracedRNumber{T})
) where {T}
return Ops.remainder(TracedUtils.promote_to(TracedRNumber{T}, lhs), rhs)
end


function Base.mod(@nospecialize(x::Reactant.TracedRNumber{T}), @nospecialize(y::Reactant.TracedRNumber{T})) where {T}
r = rem(x, y)
return ifelse(r == 0, copysign(r,y), ifelse((r > 0) (y > 0), r + y, r))
end

function Base.div(@nospecialize(lhs::TracedRNumber{T}), rhs) where {T<:Integer}
Expand Down

0 comments on commit 0ae27e9

Please sign in to comment.