iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Math.Utils

Synopsis

Documentation

floorSqrt :: Int -> Int Source #

>>> floorSqrt 0
0
>>> floorSqrt 1
1
>>> floorSqrt 2
1
>>> floorSqrt 4
2
>>> floorSqrt (12345 * 12345)
12345
>>> floorSqrt (2^52 + 2^27)
67108864
>>> floorSqrt maxBound
3037000499

floorLog2 :: Int -> Int Source #

BSR (Bit Scan Reverse)

>>> floorLog2 0
-1
>>> floorLog2 1
0
>>> floorLog2 2
1
>>> floorLog2 1023
9
>>> floorLog2 1024
10
>>> floorLog2 maxBound
62