# Math routines

Part of this API below is available to C through [lib/math.h].

log2mod ( n -- mod n )
  Return the logarithm of n to the base 2 as well as the modulo of that
  operation. Example: $103 log2 yields n=8 mod=3

log2 ( n -- n )
  Same as log2mod, but without the modulo.

log2# ( n -- n )
  Same as log2, but yields an error if modulo is not zero.

pow2 ( n -- n )
  Return 2 to the power of n.

roundpow2 ( n pow -- n )
  Round "n" up to the nearest power of 2 "pow". Example: 3 3 roundpow2 --> 8

isqrt ( n -- n )
  Return the integer square root of n. Example: 27 isqrt --> 5

sex8 ( n -- n )
  Sign-extend 8-bit number "n". Example: $80 sex8 --> $ffffff80

sex16 ( n -- n )
  Sign-extend 16-bit number "n". Example: $8000 sex16 --> $ffff8000
