note
danaj
<p><i>Dana replaced popcnt with mpu_popcount_string in Math::Prime::Util v0.62.</i></p>
<p>I moved the native popcnt to <a href="https://github.com/danaj/Math-Prime-Util/blob/94f31a32a4d2f8f8f1ffb14b55fa78617f49e2b1/util.h#L311">util.h</a>. <code>mpu_popcount_string</code> is a new function to handle bigints or sufficiently magic input without using a bigint library. It's faster than getting Math::BigInt involved until the numbers get over 500 digits. It should be optimized, but it's not exactly the common case.</p>
<p>It's also useful for making sure we don't get really slow for 64-bit numbers on a 32-bit Perl. Not as fast as forcing 64-bit code, but that's further narrowing down the space -- people on 64-bit machines who install a 32-bit Perl.</p>
<p>Using Math::BigInt to handle a long digit string would be something like:
<code>
use Math::BigInt;
my $n = "16" x 1000;
say 0 + (Math::BigInt->new("$n")->as_bin() =~ tr/1//);
</code>
where only the last part is needed if it's already a bigint. Math::GMPz has <code>Rmpz_popcount</code> which is ridiculously fast if the input is already a Math::GMPz object.
</p>
1199987
1199998