[Haskell-cafe] clz / bsr functions on Integer
Claude Heiland-Allen
claude at mathr.co.uk
Sat Nov 13 11:08:10 UTC 2021
Hi,
On 13/11/2021 00:13, james faure wrote:
> Why is there no `countLeadingZeros` function for Integer? This seems
> particularly strange because gmp provides
> /mp_bitcnt_t/*mpz_scan0*/(const mpz_top, mp_bitcnt_tstarting_bit)/
Integer is not always implemented with GMP.
> More importantly, what is the recommended way to access it?
If you do have an Integer implemented with GMP (the default case with
GHC), you can use one of
https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Raw-Safe.html#v:mpz_scan0
https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Raw-Unsafe.html#v:mpz_scan0
together with
https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Utils.html#v:withInInteger
See the example at the top of that module page.
Claude
--
https://mathr.co.uk
More information about the Haskell-Cafe
mailing list