bigi

Types

A big integer.

pub type BigInt

Functions

pub fn absolute(bigint: BigInt) -> BigInt

Get the absolute value of a big integer.

pub fn add(a: BigInt, b: BigInt) -> BigInt

Add two big integers together.

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 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.

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 multiply(a: BigInt, b: BigInt) -> BigInt

Multiply two big integers together.

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 the 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.

pub fn zero() -> BigInt

Create a big integer representing zero.

Search Document