Skip to content

Commit

Permalink
Add comment about x.i comparisons in negative / abs checks
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Dec 19, 2023
1 parent e9089f0 commit 00079e8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/FixedPointDecimals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,12 @@ end

function Base.checked_neg(x::T) where {T<:FD}
r = -x
(x.i<0) & (r<0) && Base.Checked.throw_overflowerr_negation(x)
# Simplify the compiler's job, no need to call the FD,Int comparison
(x.i<0) & (r.i<0) && Base.Checked.throw_overflowerr_negation(x)
return r
end
function Base.checked_abs(x::FD)
# Simplify the compiler's job, no need to call the FD,Int comparison
r = ifelse(x.i<0, -x, x)
r.i<0 || return r
_throw_overflow_abs(x)
Expand Down

0 comments on commit 00079e8

Please sign in to comment.