You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -121,15 +135,86 @@ function Base.:(*)(x::Decimal, y::Decimal)
121
135
returnfix(Decimal(s, x.c * y.c, x.q + y.q))
122
136
end
123
137
124
-
# Inversion
125
-
function Base.inv(x::Decimal)
126
-
c =round(BigInt, BigInt(10)^(-x.q + DIGITS) / x.c) # the decimal point of 1/x.c is shifted by -x.q so that the integer part of the result is correct and then it is shifted further by DIGITS to also cover some digits from the fractional part.
127
-
q =-DIGITS # we only need to remember that there are these digits after the decimal point
128
-
normalize(Decimal(x.s, c, q))
138
+
function Base.:(/)(x::Decimal, y::Decimal)
139
+
ifiszero(y)
140
+
ifiszero(x)
141
+
throw(UndefinedDivisionError())
142
+
else
143
+
throw(DivisionByZeroError())
144
+
end
145
+
end
146
+
147
+
s = x.s != y.s
148
+
149
+
# 0 / y, where y ≠ 0
150
+
ifiszero(x)
151
+
returnDecimal(s, BigZero, x.q - y.q)
152
+
end
153
+
154
+
prec =precision(Decimal)
155
+
156
+
# We are computing
157
+
#
158
+
# (x.c * 10^x.q) / (y.c * 10^y.q)
159
+
# = (x.c / y.c) * 10^(x.q - y.q).
160
+
#
161
+
# The coefficient `x.c / y.c` is not an integer in general.
162
+
# We could just compute the division, resulting in a BigFloat, and round
163
+
# the result. However, we would have to use `setprecision` to ensure the
164
+
# BigFloat has enough precision. To avoid that, we compute the division
0 commit comments