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 3, 2024
1 parent f432460 commit c903fa3
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

function Base.:(*)(x::Decimal, y::Decimal)
s = x.s != y.s
Expand Down
Loading

0 comments on commit c903fa3

Please sign in to comment.