Package Crypto :: Package Util :: Module _number_new
[frames] | no frames]

Module _number_new

Functions
 
ceil_shift(n, b)
Return ceil(n / 2**b) without performing any floating-point or division operations.
 
ceil_div(a, b)
Return ceil(a / b) without performing any floating-point operations.
 
floor_div(a, b)
 
exact_log2(num)
Find and return an integer i >= 0 such that num == 2**i.
 
exact_div(p, d, allow_divzero=False)
Find and return an integer n such that p == n * d
Function Details

ceil_shift(n, b)

 

Return ceil(n / 2**b) without performing any floating-point or division operations.

This is done by right-shifting n by b bits and incrementing the result by 1 if any '1' bits were shifted out.

exact_log2(num)

 

Find and return an integer i >= 0 such that num == 2**i.

If no such integer exists, this function raises ValueError.

exact_div(p, d, allow_divzero=False)

 

Find and return an integer n such that p == n * d

If no such integer exists, this function raises ValueError.

Both operands must be integers.

If the second operand is zero, this function will raise ZeroDivisionError unless allow_divzero is true (default: False).