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
Prev Previous commit
Next Next commit
simplify
  • Loading branch information
stevengj committed Aug 17, 2020
commit 802c7cff014eb91ab7ad7fd43a314832afe35afd
7 changes: 2 additions & 5 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,11 @@ function string(n::BigInt; base::Integer = 10, pad::Integer = 1)
end

function digits(n::BigInt; base::Integer = 10, pad::Integer = 1)
if base == 10
dig = map(x -> Int(x-0x30), codeunits(string(n; base, pad)))
elseif base ≤ 62
dig = map(x -> Int(x > 0x39 ? x-0x41 : x-0x30), codeunits(string(n; base, pad)))
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
return reverse!(dig)
end

function ndigits0zpb(x::BigInt, b::Integer)
Expand Down