Skip to content

Commit

Permalink
optimize top_set_bit(::BigInt)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lilith Hafner authored and Lilith Hafner committed May 30, 2023
1 parent 7cd40ed commit 356ff95
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ Number of ones in the binary representation of abs(x).
count_ones_abs(x::BigInt) = iszero(x) ? 0 : MPZ.mpn_popcount(x)

function top_set_bit(x::BigInt)
x < 0 && throw(DomainError(x, "top_set_bit only supports negative arguments when they have type BitSigned."))
x == 0 && return 0
isneg(x) && throw(DomainError(x, "top_set_bit only supports negative arguments when they have type BitSigned."))
iszero(x) && return 0
Int(ccall((:__gmpz_sizeinbase, :libgmp), Csize_t, (Base.GMP.MPZ.mpz_t, Cint), x, 2))
end

Expand Down

0 comments on commit 356ff95

Please sign in to comment.