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 Hoogle).

 

Hope that helps, David.

 

 

From: james faure
Sent: 13 November 2021 00:16
To: 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?