Skip to content

Commit

Permalink
Subtraction: dectests + implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
barucden committed Nov 1, 2024
1 parent 484f618 commit 9eede46
Show file tree
Hide file tree
Showing 3 changed files with 1,203 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ function Base.:(+)(x::Decimal, y::Decimal)
end
end

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

# Multiplication
function Base.:(*)(x::Decimal, y::Decimal)
Expand Down
Loading

0 comments on commit 9eede46

Please sign in to comment.