Skip to content

Commit 807bd21

Browse files
committed
Refactor div definition
1 parent 8c24478 commit 807bd21

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/math.jl

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,17 @@ end
7676
Base.:-(l::UnionAbstractQuantity) = new_quantity(typeof(l), -ustrip(l), dimension(l))
7777

7878
# Combining different abstract types
79-
for op in (:*, :/, :+, :-, :atan, :atand, :copysign, :flipsign),
79+
for op in (:*, :/, :+, :-, :atan, :atand, :copysign, :flipsign, :div),
8080
(t1, _, _) in ABSTRACT_QUANTITY_TYPES,
8181
(t2, _, _) in ABSTRACT_QUANTITY_TYPES
8282

8383
t1 == t2 && continue
8484

85-
@eval Base.$op(l::$t1, r::$t2) = $op(promote_except_value(l, r)...)
86-
end
87-
# different methods needed:
88-
for (t1, _, _) in ABSTRACT_QUANTITY_TYPES, (t2, _, _) in ABSTRACT_QUANTITY_TYPES
89-
90-
t1 == t2 && continue
91-
92-
@eval Base.div(x::$t1, y::$t2, r::RoundingMode=RoundToZero) = div(promote_except_value(x, y)..., r)
85+
if op == :div
86+
@eval Base.$op(x::$t1, y::$t2, r::RoundingMode=RoundToZero) = $op(promote_except_value(x, y)..., r)
87+
else
88+
@eval Base.$op(l::$t1, r::$t2) = $op(promote_except_value(l, r)...)
89+
end
9390
end
9491

9592
# We don't promote on the dimension types:
@@ -211,11 +208,7 @@ for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES, f in (:copysign, :flipsign,
211208
end
212209
for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES, f in (:rem, :mod)
213210
# Need to define all rounding modes to avoid ambiguities
214-
rounding_modes = if f == :rem
215-
(RoundingMode, typeof.((RoundToZero, RoundDown, RoundUp, RoundFromZero))...)
216-
else
217-
(nothing,)
218-
end
211+
rounding_modes = f == :rem ? (RoundingMode, typeof.((RoundToZero, RoundDown, RoundUp, RoundFromZero))...) : (nothing,)
219212
for rounding_mode in rounding_modes
220213
param, extra_f_args = if rounding_mode == RoundingMode
221214
# Add default:

0 commit comments

Comments
 (0)