|
76 | 76 | Base.:-(l::UnionAbstractQuantity) = new_quantity(typeof(l), -ustrip(l), dimension(l)) |
77 | 77 |
|
78 | 78 | # Combining different abstract types |
79 | | -for op in (:*, :/, :+, :-, :atan, :atand, :copysign, :flipsign), |
| 79 | +for op in (:*, :/, :+, :-, :atan, :atand, :copysign, :flipsign, :div), |
80 | 80 | (t1, _, _) in ABSTRACT_QUANTITY_TYPES, |
81 | 81 | (t2, _, _) in ABSTRACT_QUANTITY_TYPES |
82 | 82 |
|
83 | 83 | t1 == t2 && continue |
84 | 84 |
|
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 |
93 | 90 | end |
94 | 91 |
|
95 | 92 | # We don't promote on the dimension types: |
@@ -211,11 +208,7 @@ for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES, f in (:copysign, :flipsign, |
211 | 208 | end |
212 | 209 | for (type, base_type, _) in ABSTRACT_QUANTITY_TYPES, f in (:rem, :mod) |
213 | 210 | # 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,) |
219 | 212 | for rounding_mode in rounding_modes |
220 | 213 | param, extra_f_args = if rounding_mode == RoundingMode |
221 | 214 | # Add default: |
|
0 commit comments