mirror of
https://github.com/logos-storage/nim-groth16.git
synced 2026-01-07 08:03:07 +00:00
29 lines
578 B
Nim
29 lines
578 B
Nim
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
func floorLog2* (x : int) : int =
|
|
var k = -1
|
|
var y = x
|
|
while (y > 0):
|
|
k += 1
|
|
y = y shr 1
|
|
return k
|
|
|
|
func ceilingLog2* (x : int) : int =
|
|
if (x==0):
|
|
return -1
|
|
else:
|
|
return (floorLog2(x-1) + 1)
|
|
|
|
#
|
|
# import std/math
|
|
#
|
|
# proc sanityCheckLog2* () =
|
|
# for i in 0..18:
|
|
# let x = float64(i)
|
|
# echo( i," | ",floorLog2(i),"=",floor(log2(x))," | ",ceilingLog2(i),"=",ceil(log2(x)) )
|
|
#
|
|
|
|
#-------------------------------------------------------------------------------
|