We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7b83a9c commit 6eb1f42Copy full SHA for 6eb1f42
base/gmp.jl
@@ -9,7 +9,7 @@ import Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
9
ndigits, promote_rule, rem, show, isqrt, string, powermod,
10
sum, trailing_zeros, trailing_ones, count_ones, base, tryparse_internal,
11
bin, oct, dec, hex, isequal, invmod, prevpow2, nextpow2, ndigits0zpb,
12
- widen, signed, unsafe_trunc, trunc, iszero, big, flipsign, signbit
+ widen, signed, unsafe_trunc, trunc, iszero, big, flipsign, signbit, hastypemax
13
14
if Clong == Int32
15
const ClongMax = Union{Int8, Int16, Int32}
@@ -228,6 +228,8 @@ signed(x::BigInt) = x
228
229
convert(::Type{BigInt}, x::BigInt) = x
230
231
+hastypemax(::Type{BigInt}) = false
232
+
233
function tryparse_internal(::Type{BigInt}, s::AbstractString, startpos::Int, endpos::Int, base_::Integer, raise::Bool)
234
_n = Nullable{BigInt}()
235
base/int.jl
@@ -29,6 +29,8 @@ const BitIntegerSmall = Union{BitIntegerSmall_types...}
29
const BitSigned64T = Union{Type{Int8}, Type{Int16}, Type{Int32}, Type{Int64}}
30
const BitUnsigned64T = Union{Type{UInt8}, Type{UInt16}, Type{UInt32}, Type{UInt64}}
31
32
+const BitIntegerType = Union{map(T->Type{T}, BitInteger_types)...}
33
34
throw_inexacterror(f::Symbol, ::Type{T}, val) where T =
35
(@_noinline_meta; throw(InexactError(f, T, val)))
36
base/intfuncs.jl
@@ -743,6 +743,14 @@ function digits(T::Type{<:Integer}, n::Integer, base::Integer=10, pad::Integer=1
743
digits!(zeros(T, ndigits(n, base, pad)), n, base)
744
end
745
746
+"""
747
+ hastypemax(T::Type) -> Bool
748
749
+Return `true` if and only if `typemax(T)` is defined.
750
751
+hastypemax(::Base.BitIntegerType) = true
752
+hastypemax(::Type{T}) where {T} = applicable(typemax, T)
753
754
"""
755
digits!(array, n::Integer, base::Integer=10)
756
@@ -772,7 +780,8 @@ julia> digits!([2,2,2,2,2,2], 10, 2)
772
780
function digits!(a::AbstractVector{T}, n::Integer, base::Integer=10) where T<:Integer
773
781
base < 0 && isa(n, Unsigned) && return digits!(a, convert(Signed, n), base)
774
782
2 <= abs(base) || throw(ArgumentError("base must be ≥ 2 or ≤ -2, got $base"))
775
- abs(base) - 1 <= typemax(T) || throw(ArgumentError("type $T too small for base $base"))
783
+ hastypemax(T) && abs(base) - 1 > typemax(T) &&
784
+ throw(ArgumentError("type $T too small for base $base"))
776
785
for i in eachindex(a)
777
786
if base > 0
778
787
a[i] = rem(n, base)
base/random.jl
@@ -28,8 +28,7 @@ mutable struct Close1Open2 <: FloatInterval end
28
## RandomDevice
-const BitIntegerType = Union{map(T->Type{T}, Base.BitInteger_types)...}
-const BoolBitIntegerType = Union{Type{Bool},BitIntegerType}
+const BoolBitIntegerType = Union{Type{Bool},Base.BitIntegerType}
const BoolBitIntegerArray = Union{Array{Bool},Base.BitIntegerArray}
if Sys.iswindows()
test/bigint.jl
@@ -289,6 +289,9 @@ end
289
290
@test Base.ndigits0zpb(big(0), big(rand(2:100))) == 0
291
292
+# digits with BigInt bases (#16844)
293
+@test digits(big(2)^256, big(2)^128) == [0, 0, 1]
294
295
# conversion from float
296
@test BigInt(2.0) == BigInt(2.0f0) == BigInt(big(2.0)) == 2
297
@test_throws InexactError convert(BigInt, 2.1)
0 commit comments