bigi
Types
Functions
pub fn compare(a: BigInt, with b: BigInt) -> Order
Compare two big integers, returning an order that denotes if b
is lower,
bigger than, or equal to a
.
pub fn decode(dyn: Dynamic) -> Result(BigInt, List(DecodeError))
Decode a gleam/dynamic
value into a big integer, if possible.
pub fn digits(bigint: BigInt) -> List(Int)
Get the digits in a given bigint as a list of integers.
The list is ordered starting from the most significant digit.
pub fn divide(dividend a: BigInt, divisor b: BigInt) -> BigInt
Divide the dividend with the divisor using integer division.
Follows the standard Gleam divide-by-zero rule of 0 when the divisor is 0.
pub fn divide_no_zero(
dividend a: BigInt,
divisor b: BigInt,
) -> Result(BigInt, Nil)
Divide the dividend with the divisor using integer division.
Returns an error if the divisor is 0.
pub fn from_int(int: Int) -> BigInt
Create a big integer from a regular integer.
Note that in the JavaScript target, if your integer is bigger than the maximum safe integer or smaller than the minimum safe integer, you may lose precision when operating on it, including when converting it into a big integer (as the JavaScript Number type has already reduced the precision of the value).
pub fn from_string(str: String) -> Result(BigInt, Nil)
Convert a string into a big integer.
If the string does not represent a big integer in base 10, an error is returned. Trailing non-digit content is not allowed.
pub fn modulo(dividend a: BigInt, divisor b: BigInt) -> BigInt
Calculate a mathematical modulo operation.
Follows the standard Gleam divide-by-zero rule of 0 when the divisor is 0.
pub fn modulo_no_zero(
dividend a: BigInt,
divisor b: BigInt,
) -> Result(BigInt, Nil)
Calculate a mathematical modulo operation.
Returns an error if the divisor is 0.
pub fn power(
base a: BigInt,
exponent b: BigInt,
) -> Result(BigInt, Nil)
Raise the base to the exponent.
If the exponent is negative, an error is returned.
pub fn remainder(dividend a: BigInt, divisor b: BigInt) -> BigInt
Divide the dividend with the divisor using integer division and return the remainder.
Follows the standard Gleam divide-by-zero rule of 0 when the divisor is 0.
pub fn remainder_no_zero(
dividend a: BigInt,
divisor b: BigInt,
) -> Result(BigInt, Nil)
Divide the dividend with the divisor using integer division and return the remainder.
Returns an error if the divisor is 0.
pub fn subtract(
minuend a: BigInt,
subtrahend b: BigInt,
) -> BigInt
Subtract the subtrahend from the minuend.
pub fn to_int(bigint: BigInt) -> Result(Int, Nil)
Convert a big integer to a regular integer.
In Erlang, this cannot fail, as all Erlang integers are big integers. In the JavaScript target, this will fail if the integer is bigger than the maximum safe integer or smaller than the minimum safe integer.
pub fn to_string(bigint: BigInt) -> String
Convert the big integer into a simple string - a sequence of digits.