Skip to content

Commit 5cd504f

Browse files
committed
Subtraction: dectests + implementation
1 parent f432460 commit 5cd504f

File tree

3 files changed

+1203
-2
lines changed

3 files changed

+1203
-2
lines changed

src/arithmetic.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ function Base.:(+)(x::Decimal, y::Decimal)
110110
end
111111
end
112112

113-
# Subtraction
114-
Base.:(-)(x::Decimal, y::Decimal) = +(x, -y)
113+
function Base.:(-)(x::Decimal, y::Decimal)
114+
# Doing `x + (-y)` might involve intermediate rounding due to `-y`
115+
y = Decimal(!y.s, y.c, y.q)
116+
return x + y
117+
end
115118

116119
function Base.:(*)(x::Decimal, y::Decimal)
117120
s = x.s != y.s

0 commit comments

Comments
 (0)