Skip to content

Commit 0ae27e9

Browse files
committed
Only define new methods for rem instead of all binary operators
They seemed to introduce several ambiguities.
1 parent a36deaa commit 0ae27e9

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/TracedRNumber.jl

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,29 @@ for (jlop, hloop) in (
9797
(:(Base.mod), :remainder),
9898
(:(Base.rem), :remainder),
9999
)
100-
@eval begin
101-
function $(jlop)(
102-
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::TracedRNumber{T})
103-
) where {T}
104-
return Ops.$(hloop)(lhs, rhs)
105-
end
100+
@eval function $(jlop)(
101+
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::TracedRNumber{T})
102+
) where {T}
103+
return Ops.$(hloop)(lhs, rhs)
104+
end
105+
end
106106

107-
function $(jlop)(
108-
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::Number)
109-
) where {T}
110-
return Ops.$(hloop)(lhs, TracedUtils.promote_to(TracedRNumber{T}, rhs))
111-
end
107+
function Base.rem(
108+
@nospecialize(lhs::TracedRNumber{T}), @nospecialize(rhs::Number)
109+
) where {T}
110+
return Ops.remainder(lhs, TracedUtils.promote_to(TracedRNumber{T}, rhs))
111+
end
112112

113-
function $(jlop)(
114-
@nospecialize(lhs::Number), @nospecialize(rhs::TracedRNumber{T})
115-
) where {T}
116-
return Ops.$(hloop)(TracedUtils.promote_to(TracedRNumber{T}, lhs), rhs)
117-
end
118-
end
113+
function Base.rem(
114+
@nospecialize(lhs::Number), @nospecialize(rhs::TracedRNumber{T})
115+
) where {T}
116+
return Ops.remainder(TracedUtils.promote_to(TracedRNumber{T}, lhs), rhs)
117+
end
118+
119+
120+
function Base.mod(@nospecialize(x::Reactant.TracedRNumber{T}), @nospecialize(y::Reactant.TracedRNumber{T})) where {T}
121+
r = rem(x, y)
122+
return ifelse(r == 0, copysign(r,y), ifelse((r > 0) (y > 0), r + y, r))
119123
end
120124

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

0 commit comments

Comments
 (0)