Skip to content

Commit

Permalink
faster iseven(::BigInt) (JuliaLang#40850)
Browse files Browse the repository at this point in the history
This method was depending on the generic implementation
`iseven(x::Integer) = !isodd(x)` for its efficiency, but this was removed
in JuliaLang#38976, making `iseven(::BigInt)` 30 times slower.
  • Loading branch information
rfourquet authored and Amit Shirodkar committed Jun 9, 2021
1 parent 07a36c6 commit 66dcfeb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
sum, trailing_zeros, trailing_ones, count_ones, tryparse_internal,
bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb,
widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit,
sign, hastypemax, isodd, digits!
sign, hastypemax, isodd, iseven, digits!

if Clong == Int32
const ClongMax = Union{Int8, Int16, Int32}
Expand Down Expand Up @@ -343,6 +343,7 @@ end
rem(x::Integer, ::Type{BigInt}) = BigInt(x)

isodd(x::BigInt) = MPZ.tstbit(x, 0)
iseven(x::BigInt) = !isodd(x)

function (::Type{T})(x::BigInt) where T<:Base.BitUnsigned
if sizeof(T) < sizeof(Limb)
Expand Down

0 comments on commit 66dcfeb

Please sign in to comment.