[Haskell-cafe] clz / bsr functions on Integer

David James dj112358 at outlook.com
Sat Nov 13 11:03:48 UTC 2021

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)

The Integer type represents unbounded integers, so countLeadingZeros doesn’t really make sense.

(ps. you can seach for functions like countLeadingZeros on Hoogle<https://hoogle.haskell.org/>).

Hope that helps, David.

From: james faure<mailto:james.faure at epitech.eu>
Sent: 13 November 2021 00:16
To: haskell-cafe at haskell.org<mailto:haskell-cafe at 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?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20211113/620763b0/attachment.html>

More information about the Haskell-Cafe mailing list