Skip to content

Commit 859f054

Browse files
committed
max_exp10 now returns -1 for BigInt
Using -1 to indicate that the given type should not overflow.
1 parent 007523b commit 859f054

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/FixedPointDecimals.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ immutable FixedDecimal{T <: Integer, f} <: Real
8282

8383
# inner constructor
8484
function Base.reinterpret{T, f}(::Type{FixedDecimal{T, f}}, i::Integer)
85-
if T != BigInt && 0 <= f <= max_exp10(T) || T == BigInt && f >= 0
85+
n = max_exp10(T)
86+
if f >= 0 && (n < 0 || f <= n)
8687
new{T, f}(i % T)
8788
else
8889
throw(ArgumentError(
@@ -398,9 +399,11 @@ end
398399
"""
399400
max_exp10(T)
400401
401-
The highest value of `x` which does not result in an overflow when evaluating `T(10)^x`.
402+
The highest value of `x` which does not result in an overflow when evaluating `T(10)^x`. For
403+
types of `T` that do not overflow -1 will be returned.
402404
"""
403405
function max_exp10{T <: Integer}(::Type{T})
406+
applicable(typemax, T) || return -1
404407
W = widen(T)
405408
type_max = W(typemax(T))
406409

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ end
8181
@test FixedPointDecimals.max_exp10(UInt8) == 2
8282
@test FixedPointDecimals.max_exp10(UInt64) == 19
8383
@test FixedPointDecimals.max_exp10(UInt128) == 38
84-
@test_throws MethodError FixedPointDecimals.max_exp10(BigInt)
84+
@test FixedPointDecimals.max_exp10(BigInt) == -1
8585

8686
for T in CONTAINER_TYPES
8787
x = FixedPointDecimals.max_exp10(T)

0 commit comments

Comments
 (0)