maths/routines

This module contains mathematical routines.

Functions

powmod(n: Int, e: Int, q: Int) -> Int

Calculate n to the power of e modulo q using the exponentiation by squaring method. At each multiplication a modulo is calculated, allowing very large n and e values.

routines.powmod(3, 2, 5)

base_q(n: Int, q: Int) -> List<Int>

Convert a integer n into some base q. This method should scale with any integer and any logical base.

routines.base_q(123, 7)

to_int(self: ByteArray) -> Int

Convert a hexadecimal bytearray into its base 10 representation. This only works with even length bytearrays so arbitrary numbers in hexadecimal form will not in general work.

routines.to_int(#"acab")

from_int(self: Int) -> ByteArray

Convert a integer into a hexadecimal bytearray. This works for all integers but odd length bytearrays will be prefixed with a zero. This function combined with the to_int function allows a string to represent a number and still be used for calculations, pushing the 2^64 - 1 integer boundary.

routines.from_int(44203)
Search Document