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)
Functions
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_no_zero(
a: RangedInt(a),
b: BigInt,
) -> Result(Result(RangedInt(a), Overflow), Nil)
pub fn overflow(
op: Result(RangedInt(Overflowable), Overflow),
interface: GenericInterface(Overflowable),
) -> RangedInt(Overflowable)
pub fn remainder_no_zero(
a: RangedInt(a),
b: BigInt,
) -> Result(Result(RangedInt(a), Overflow), Nil)