Multiple Precision Integers

Index

mpi/add mpi/clear-bit mpi/div mpi/flip-sign mpi/gcd mpi/get-bit mpi/inverse-mod mpi/is-negative mpi/is-positive mpi/is-prime mpi/is-zero mpi/lshift mpi/mod-mul mpi/mul mpi/new mpi/new-random mpi/num-bytes mpi/pow-mod mpi/rshift mpi/set-bit mpi/sub mpi/swap mpi/to-bin mpi/to-hex mpi/to-int mpi/to-u32

Reference

mpi/addcfunction
(mpi/add mpi-obj x)

Add x to `mpi-obj` and return the new `mpi-obj`. `x` can be either `mpi-obj` or u32 number.

mpi/clear-bitcfunction
(mpi/clear-bit mpi-obj bit)

Clears the specified `bit` of `mpi-obj`. Returns `mpi-obj`.

mpi/divcfunction
(mpi/div mpi-obj-1 mpi-obj-2)

Divide `mpi-obj-1` by `mpi-obj-2`. Create new quotient `mpi-obj` and remainder `mpi-obj`. Return quotient `mpi-obj` and remainder `mpi-obj` in tuple.

mpi/flip-signcfunction
(mpi/flip-sign mpi-obj)

Flip the sign of `mpi-obj`. Returns `mpi-obj`.

mpi/gcdcfunction
(mpi/gcd mpi-obj mpi-obj2)

Return a new `mpi-obj` representing the greatest common divisor of `mpi-obj` and `mpi-obj2`.

mpi/get-bitcfunction
(mpi/get-bit mpi-obj bit)

Returns 0 if the specified `bit` of `mpi-obj` is not set, 1 if it is set.

(mpi/inverse-mod mpi-obj modulus)

Create the inverse of `mpi-obj` modulo `modulus`, or nil if no inverse exists.Returns new `mpi-obj`.

(mpi/is-negative mpi-obj)

Return true if `mpi-obj` is less than zero, otherwise return false.

(mpi/is-positive mpi-obj)

Return true if `mpi-obj` is greater than or equal to zero. otherwise return false.

mpi/is-primecfunction
(mpi/is-prime mpi-obj rng &opt prob)

Return true if `mpi-obj` is prime, otherwise returns false. Default value of prob is 128.

mpi/is-zerocfunction
(mpi/is-zero mpi-obj)

Return true if `mpi-obj` is zero, otherwise returns false.

mpi/lshiftcfunction
(mpi/lshift mpi-obj shift)

Left shift by specified `shift` bit count. Return new `mpj-obj`.

mpi/mod-mulcfunction
(mpi/mod-mul mpi-obj mpi-obj2 modulus)

Return a new `mpi-obj` representing (`mpi-obj` * `mpi-obj2`) modulo `modulus`. `mpi-obj2` and `modulus` are also `mpi-obj` objects.

mpi/mulcfunction
(mpi/sub mpi-obj-1 mpi-obj-2)

Multiply two `mpi-obj` and return the new `mpi-obj` as a result.

mpi/newcfunction
(mpi/new &opt value radix)

Create a new MPI object with optional `value` and `radix`:
* No arguments: Returns a zero-valued MPI
* `value` is an MPI object: Creates an MPI from another MPI
* `value` is an integer: Creates an MPI with that integer value
* `value` is a string: Creates an MPI from the string
(`radix` determines how the string is interpreted)
* `radix = 16`: Treats the string as a hexadecimal value
* `radix` not given: Treats the string as a base-10 integer
Returns `mpi-obj`.

(mpi/new-random bits &opt rng)

Create a `bits` sizes random MPI object. Use `rng` if provided. Returns `mpi-obj`.

mpi/num-bytescfunction
(mpi/num-bytes mpi-obj)

Return the number of significant bytes in the `mpi-obj`.

mpi/pow-modcfunction
(mpi/pow-mod mpi-obj exponent modulus)

Return a new `mpi-obj` representing (`mpi-obj` ^ `exponent`) mod `modulus`.`exponent` and `modulus` are also `mpi-obj` objects.

mpi/rshiftcfunction
(mpi/rshift mpi-obj shift)

Right shift by specified `shift` bit count. Return new `mpj-obj`.

mpi/set-bitcfunction
(mpi/set-bit mpi-obj bit)

Set the specified `bit` of `mpi-obj`. Returns `mpi-obj`.

mpi/subcfunction
(mpi/sub mpi-obj x)

Subtract x from `mpi-obj` and return the new `mpi-obj`. `x` can be either `mpi-obj` or u32 number.

mpi/swapcfunction
(mpi/swap mpi-obj-1 mpi-obj-2)

Swap `mpi-obj-1` and `mpi-obj-2` values, Return `mpi-obj-1`.

mpi/to-bincfunction
(mpi/to-bin mpi-obj)

Convert the `mpi-obj` to a binary and return as a string.

mpi/to-hexcfunction
(mpi/to-hex mpi-obj)

Convert the `mpi-obj` to a hex string and return as a string.

mpi/to-intcfunction
(mpi/to-int mpi-obj)

Convert the `mpi-obj` to an integer string and return as a string.

mpi/to-u32cfunction
(mpi/to-u32 mpi-obj)

Convert the `mpi-obj` to a uint32_t, if possible. Fails if `mpi-obj` is negative or too large.