ranged_int/builtin/generic

A generic ranged integer.

This module is meant for cases where the integer range cannot be known at compile time. Generic ranged integers are less type safe and have lower performance. It’s always suggested to use one of the builtin types or to create your own type when you can.

Types

The interface of a generic ranged integer.

pub opaque type GenericInterface(overflow_mode)

A generic ranged integer, carrying its own interface along with the data.

pub opaque type RangedInt(overflow_mode)

Functions

pub fn absolute(
  a: RangedInt(a),
) -> Result(RangedInt(a), Overflow)
pub fn add(
  a: RangedInt(a),
  b: BigInt,
) -> Result(RangedInt(a), Overflow)
pub fn compare(a: RangedInt(a), b: RangedInt(a)) -> Order
pub fn divide(
  a: RangedInt(a),
  b: BigInt,
) -> Result(RangedInt(a), Overflow)
pub fn divide_no_zero(
  a: RangedInt(a),
  b: BigInt,
) -> Result(Result(RangedInt(a), Overflow), Nil)
pub fn eject(
  op: Result(RangedInt(a), Overflow),
  interface: GenericInterface(a),
) -> BigInt
pub fn from_bigint_max(
  value: BigInt,
  max max: BigInt,
) -> Result(RangedInt(NonOverflowable), Overflow)

Create from a big integer and a maximum value, inclusive.

pub fn from_bigint_min(
  value: BigInt,
  min min: BigInt,
) -> Result(RangedInt(NonOverflowable), Overflow)

Create from a big integer and a minimum value, inclusive.

pub fn from_bigint_overflowable(
  value: BigInt,
  min min: BigInt,
  max max: BigInt,
) -> Result(RangedInt(Overflowable), Overflow)

Create from a big integer and a minimum and maximum value, both inclusive. The created integer can be used with overflow.

pub fn get_interface(int: RangedInt(a)) -> GenericInterface(a)

Get the interface of the integer. This interface is required for overflow and eject.

pub fn modulo(
  a: RangedInt(a),
  b: BigInt,
) -> Result(RangedInt(a), Overflow)
pub fn modulo_no_zero(
  a: RangedInt(a),
  b: BigInt,
) -> Result(Result(RangedInt(a), Overflow), Nil)
pub fn multiply(
  a: RangedInt(a),
  b: BigInt,
) -> Result(RangedInt(a), Overflow)
pub fn overflow(
  op: Result(RangedInt(Overflowable), Overflow),
  interface: GenericInterface(Overflowable),
) -> RangedInt(Overflowable)
pub fn power(
  a: RangedInt(a),
  b: Uint,
) -> Result(RangedInt(a), Overflow)
pub fn remainder(
  a: RangedInt(a),
  b: BigInt,
) -> Result(RangedInt(a), Overflow)
pub fn remainder_no_zero(
  a: RangedInt(a),
  b: BigInt,
) -> Result(Result(RangedInt(a), Overflow), Nil)
pub fn subtract(
  a: RangedInt(a),
  b: BigInt,
) -> Result(RangedInt(a), Overflow)
pub fn to_bigint(int: RangedInt(a)) -> BigInt
Search Document