Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

faster digits(::BigInt) #37075

Merged
merged 14 commits into from
Aug 18, 2020
8 changes: 8 additions & 0 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,14 @@ function string(n::BigInt; base::Integer = 10, pad::Integer = 1)
String(sv)
end

function digits(n::BigInt; base::Integer = 10, pad::Integer = 1)
if base ≤ 62
stevengj marked this conversation as resolved.
Show resolved Hide resolved
return reverse!(map(x -> Int(x > 0x39 ? x-0x41 : x-0x30), codeunits(string(n; base, pad))))
else
return invoke(digits, (Integer,), n; base, pad) # slow generic method
end
end

function ndigits0zpb(x::BigInt, b::Integer)
b < 2 && throw(DomainError(b, "`b` cannot be less than 2."))
x.size == 0 && return 0 # for consistency with other ndigits0z methods
Expand Down