On 2026-09-19 21:52, Johann "Myrkraverk" Oskarsson wrote:
For instance, here is the utility function in LibTomMath, mp_cnt_lsb(),
chosen because I was looking at the Jacobi Symbol algorithm in Tom St
Denis' book, /BigNum Math/ when I came across this little optimization.

   https://github.com/libtom/libtommath/blob/develop/mp_cnt_lsb.c

…

So, presuming this is a standard function in all multiprecision arith-
metical libraries, why can't we just do this directly in Python?


If it’s present in multi‐precision arithmetic libraries why not use one?

For example:

>>> import gmpy2
>>> gmpy2.bit_scan1(1)
0
>>> gmpy2.bit_scan1(2)
1
>>> gmpy2.bit_scan1(5)
0
>>> gmpy2.bit_scan1(5 << 1000)
1000

https://gmpy-skirpichev.readthedocs.io/en/latest/mpz.html#gmpy2.bit_scan1

Simon

--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to