Skip to content

Commit 6976457

Browse files
committed
Address
1 parent d0cdb98 commit 6976457

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/FixedPointDecimals.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 fld call below.
448-
if T <: Signed && x.i == typemin(T) && y.i == -1
448+
if y.i == -1 && T <: Signed && hasmethod(typemin, (Type{T},)) && x.i == typemin(T)
449449
# To perform the div and overflow means reaching the max and adding 1, so typemin.
450450
return (x, true)
451451
end
@@ -470,7 +470,7 @@ See also:
470470
function fld_with_overflow(x::FD{T,f}, y::FD{T,f}) where {T<:Integer,f}
471471
C = coefficient(FD{T, f})
472472
# This case will break the fld call below.
473-
if T <: Signed && x.i == typemin(T) && y.i == -1
473+
if y.i == -1 && T <: Signed && hasmethod(typemin, (Type{T},)) && x.i == typemin(T)
474474
# To fld and overflow means reaching the max and adding 1, so typemin (x).
475475
return (x, true)
476476
end
@@ -513,7 +513,7 @@ function rdiv_with_overflow(x::Integer, y::FD{T, f}) where {T<:Integer, f}
513513
return (reinterpret(FD{T,f}, rem(v, T)), v < typemin(T) || v > typemax(T))
514514
end
515515
function rdiv_with_overflow(x::FD{T, f}, y::Integer) where {T<:Integer, f}
516-
if T <: Signed && x.i == typemin(T) && y == -1
516+
if y == -1 && T <: Signed && hasmethod(typemin, (Type{T},)) && x.i == typemin(T)
517517
# typemin / -1 for signed integers wraps, giving typemin (x) again.
518518
return (x, true)
519519
end

test/FixedDecimal.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ end
796796
@test rdiv_with_overflow(FD{Int16,2}(-165), FD{Int16,2}(0.5)) == (FD{Int16,2}(325.36), true)
797797
@test rdiv_with_overflow(typemin(FD{Int64,8}), Int32(-1)) == (typemin(FD{Int64,8}), true)
798798
@test rdiv_with_overflow(typemin(FD{Int64,0}), FD{Int64,0}(-1)) == (typemin(FD{Int64,0}), true)
799+
@test rdiv_with_overflow(typemin(FD{Int8,2}), FD{Int8,2}(-1)) == (typemin(FD{Int8,2}), true)
799800

800801
@test fld_with_overflow(FD{Int8,2}(-1), FD{Int8,2}(0.9)) == (FD{Int8,2}(0.56), true)
801802
@test fld_with_overflow(typemin(FD{Int64,0}), FD{Int64,0}(-1)) == (typemin(FD{Int64,0}), true)
@@ -884,6 +885,7 @@ end
884885
@test fld_with_overflow(FD{Int64,8}(20.5), FD{Int64,8}(2.1)) == (FD{Int64,8}(9), false)
885886
@test fld_with_overflow(FD{Int8,0}(-5), FD{Int8,0}(-1)) == (FD{Int8,0}(5), false)
886887
@test fld_with_overflow(FD{Int8,2}(0.99), FD{Int8,2}(0.5)) == (FD{Int8,2}(1), false)
888+
@test fld_with_overflow(typemin(FD{Int8,2}), FD{Int8,2}(-1)) == (FD{Int8,2}(1), false)
887889
end
888890
end
889891

0 commit comments

Comments
 (0)