Skip to content

Commit c5347cb

Browse files
committed
digits!: check for typemax only when applicable
1 parent 6de9e97 commit c5347cb

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

base/intfuncs.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ end
325325

326326
function digits!{T<:Integer}(a::AbstractArray{T,1}, n::Integer, base::Integer=10)
327327
2 <= base || throw(ArgumentError("base must be ≥ 2, got $base"))
328-
base - 1 <= typemax(T) || throw(ArgumentError("type $T too small for base $base"))
328+
!applicable(typemax, T) ||
329+
base - 1 <= typemax(T) || throw(ArgumentError("type $T too small for base $base"))
329330
for i in eachindex(a)
330331
a[i] = rem(n, base)
331332
n = div(n, base)

test/bigint.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ ndigits(rand(big(-999:999)), big(2)^rand(2:999))
280280

281281
@test_throws DomainError ndigits(rand(big(-999:999)), rand(typemin(Int):1))
282282

283+
# digits with big bases
284+
@test digits(big(2)^256, big(2)^128) == [0, 0, 1]
285+
283286
# conversion from float
284287
@test BigInt(2.0) == BigInt(2.0f0) == BigInt(big(2.0)) == 2
285288
@test_throws InexactError convert(BigInt, 2.1)

0 commit comments

Comments
 (0)