clz / bsr functions on Integer

Why is there no `countLeadingZeros` function for Integer? This seems particularly strange because gmp provides mp_bitcnt_t mpz_scan0 (const mpz_t op, mp_bitcnt_t starting_bit) More importantly, what is the recommended way to access it?

Hi – there is a countLeadingZeros function. It applies to instances of FiniteBits, such as Int (a fixed bit-size integer): GHCi, version 8.10.7: https://www.haskell.org/ghc/ :? for help Loaded package environment from C:\Users\David\AppData\Roaming\ghc\x86_64-mingw32-8.10.7\environments\default
:m +Data.Bits countLeadingZeros (23 :: Int) 59
The Integer type represents unbounded integers, so countLeadingZeros doesn’t really make sense. (ps. you can seach for functions like countLeadingZeros on Hooglehttps://hoogle.haskell.org/). Hope that helps, David. From: james fauremailto:james.faure@epitech.eu Sent: 13 November 2021 00:16 To: haskell-cafe@haskell.orgmailto:haskell-cafe@haskell.org Subject: [Haskell-cafe] clz / bsr functions on Integer Why is there no `countLeadingZeros` function for Integer? This seems particularly strange because gmp provides mp_bitcnt_t mpz_scan0 (const mpz_t op, mp_bitcnt_t starting_bit) More importantly, what is the recommended way to access it?

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.htm... https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Raw-Unsafe.h... together with https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Utils.html#v... See the example at the top of that module page. Claude -- https://mathr.co.uk

"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
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.htm... https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Raw-Unsafe.h...
together with
https://hackage.haskell.org/package/hgmp-0.1.2/docs/Numeric-GMP-Utils.html#v...
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@gmail.com
participants (4)
-
Brandon Allbery
-
Claude Heiland-Allen
-
David James
-
james faure