Skip to content

Commit 588bdb2

Browse files
authored
Better handle different backing types. (#111)
1 parent 0b5d756 commit 588bdb2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/FixedPointDecimals.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ function Base.Checked.mul_with_overflow(x::FD{T,f}, y::FD{T,f}) where {T<:Intege
430430
powt = coefficient(FD{T, f})
431431
quotient, remainder = fldmodinline(_widemul(x.i, y.i), powt)
432432
v = _round_to_nearest(quotient, remainder, powt)
433-
return (reinterpret(FD{T,f}, Base.trunc_int(T, v)), v < typemin(T) || v > typemax(T))
433+
return (reinterpret(FD{T,f}, rem(v, T)), v < typemin(T) || v > typemax(T))
434434
end
435435

436436
# This does not exist in Base so is just part of this package.
@@ -445,7 +445,7 @@ overflow/underflow did in fact happen. Throws a DivideError on divide-by-zero.
445445
function div_with_overflow(x::FD{T,f}, y::FD{T,f}) where {T<:Integer,f}
446446
C = coefficient(FD{T, f})
447447
# This case will break the div call below.
448-
if x.i == typemin(T) && y.i == -1
448+
if T <: Signed && x.i == typemin(T) && y.i == -1
449449
# To perform the div and overflow means reaching the max and adding 1, so typemin.
450450
return (x, true)
451451
end

0 commit comments

Comments
 (0)