Skip to content

Commit 9eede46

Browse files
committed
Subtraction: dectests + implementation
1 parent 484f618 commit 9eede46

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
# Multiplication
117120
function Base.:(*)(x::Decimal, y::Decimal)

0 commit comments

Comments
 (0)