@@ -430,7 +430,7 @@ function Base.Checked.mul_with_overflow(x::FD{T,f}, y::FD{T,f}) where {T<:Intege
430
430
powt = coefficient (FD{T, f})
431
431
quotient, remainder = fldmodinline (_widemul (x. i, y. i), powt)
432
432
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))
434
434
end
435
435
436
436
# 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.
445
445
function div_with_overflow (x:: FD{T,f} , y:: FD{T,f} ) where {T<: Integer ,f}
446
446
C = coefficient (FD{T, f})
447
447
# This case will break the div call below.
448
- if x . i == typemin (T) && y . i == - 1
448
+ if y . i == - 1 && T <: Signed && hasmethod ( typemin, (Type{T},)) && x . i == typemin (T)
449
449
# To perform the div and overflow means reaching the max and adding 1, so typemin.
450
450
return (x, true )
451
451
end
@@ -469,9 +469,8 @@ See also:
469
469
"""
470
470
function fld_with_overflow (x:: FD{T,f} , y:: FD{T,f} ) where {T<: Integer ,f}
471
471
C = coefficient (FD{T, f})
472
- # This case will break the fld call below. This can only happen when f is 0 as y.i
473
- # cannot be -1 otherwise.
474
- if T <: Signed && x. i == typemin (T) && y. i == - 1
472
+ # This case will break the fld call below.
473
+ if y. i == - 1 && T <: Signed && hasmethod (typemin, (Type{T},)) && x. i == typemin (T)
475
474
# To fld and overflow means reaching the max and adding 1, so typemin (x).
476
475
return (x, true )
477
476
end
@@ -514,7 +513,7 @@ function rdiv_with_overflow(x::Integer, y::FD{T, f}) where {T<:Integer, f}
514
513
return (reinterpret (FD{T,f}, rem (v, T)), v < typemin (T) || v > typemax (T))
515
514
end
516
515
function rdiv_with_overflow (x:: FD{T, f} , y:: Integer ) where {T<: Integer , f}
517
- if T <: Signed && x . i == typemin (T) && y == - 1
516
+ if y == - 1 && T <: Signed && hasmethod ( typemin, (Type{T},)) && x . i == typemin (T)
518
517
# typemin / -1 for signed integers wraps, giving typemin (x) again.
519
518
return (x, true )
520
519
end
0 commit comments