[Haskell-cafe] clz / bsr functions on Integer

Brandon Allbery allbery.b at gmail.com
Sat Nov 13 12:26:47 UTC 2021


"Default case" is part of the problem. The ghc developers are working
on having hot-swappable Integer implementations (right now you have to
build the compiler with a specific Integer backend); what happens to
`countLeadingZeros` in that case?

On Sat, Nov 13, 2021 at 6:15 AM Claude Heiland-Allen <claude at mathr.co.uk> wrote:
>
> 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
>
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.



-- 
brandon s allbery kf8nh
allbery.b at gmail.com


More information about the Haskell-Cafe mailing list