Num

U8

default : -> U8

Returns the default U8 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect U8.default() == 0
highest : U8

The highest value representable by a U8, which is 255.

expect U8.highest == 255
lowest : U8

The lowest value representable by a U8, which is 0.

expect U8.lowest == 0
to_str : U8 -> Str

Convert a U8 to its decimal string representation.

expect U8.to_str(42) == "42"
is_zero : U8 -> Bool

Returns Bool.True if the value is 0.

expect U8.is_zero(0)

expect !U8.is_zero(7)
is_eq : U8, U8 -> Bool

Returns Bool.True if the two values are equal.

expect U8.is_eq(3, 3)

expect !U8.is_eq(3, 4)
is_gt : U8, U8 -> Bool

Returns Bool.True if the first value is greater than the second.

expect U8.is_gt(5, 3)

expect !U8.is_gt(3, 3)
is_gte : U8, U8 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect U8.is_gte(3, 3)

expect !U8.is_gte(2, 3)
is_lt : U8, U8 -> Bool

Returns Bool.True if the first value is less than the second.

expect U8.is_lt(3, 5)

expect !U8.is_lt(3, 3)
is_lte : U8, U8 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect U8.is_lte(3, 3)

expect !U8.is_lte(5, 3)
compare : U8, U8 -> [LT, EQ, GT]

Compare two U8 values and return their ordering.

expect U8.compare(1, 2) == LT

expect U8.compare(2, 2) == EQ

expect U8.compare(3, 2) == GT
is_even : U8 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect U8.is_even(4)

expect !U8.is_even(5)
is_odd : U8 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect U8.is_odd(5)

expect !U8.is_odd(4)
is_multiple_of : U8, U8 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect U8.is_multiple_of(12, 3)

expect U8.is_multiple_of(0, 0)

expect !U8.is_multiple_of(5, 0)
max : U8, U8 -> U8

Returns the greater of two U8 values.

expect U8.max(5, 3) == 5
min : U8, U8 -> U8

Returns the smaller of two U8 values.

expect U8.min(5, 3) == 3
plus : U8, U8 -> U8

Add two U8 values.

expect U8.plus(2, 3) == 5
add_try : U8, U8 -> Try(U8, [Overflow, ..])

Add two U8 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U8.

plus_saturated : U8, U8 -> U8

Add two U8 values, saturating at U8.highest on overflow rather than wrapping around.

expect U8.plus_saturated(U8.highest, 1) == U8.highest

expect U8.plus_saturated(2, 3) == 5
minus : U8, U8 -> U8

Subtract the second U8 from the first.

expect U8.minus(5, 3) == 2
sub_try : U8, U8 -> Try(U8, [Overflow, ..])

Subtract the second U8 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in a U8.

minus_saturated : U8, U8 -> U8

Subtract the second U8 from the first, saturating at the nearest bound on overflow.

expect U8.minus_saturated(0, 1) == 0

expect U8.minus_saturated(5, 3) == 2
times : U8, U8 -> U8

Multiply two U8 values.

expect U8.times(4, 3) == 12
mul_try : U8, U8 -> Try(U8, [Overflow, ..])

Multiply two U8 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U8.

times_saturated : U8, U8 -> U8

Multiply two U8 values, saturating at the nearest bound on overflow.

expect U8.times_saturated(U8.highest, 2) == U8.highest

expect U8.times_saturated(4, 3) == 12
pow : U8, U8 -> U8

Raise the first U8 value to the power of the second. Crashes if the exact result does not fit in U8.

expect U8.pow(2, 3) == 8

expect U8.pow(5, 0) == 1
pow_try : U8, U8 -> Try(U8, [Overflow, ..])

Raise the first U8 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect U8.pow_try(2, 3) == Ok(8)

expect U8.pow_try(U8.highest, 2) == Err(Overflow)
div_by : U8, U8 -> U8

Divide the first U8 by the second, discarding any remainder. Crashes if the second U8 is zero.

expect U8.div_by(10, 2) == 5

expect U8.div_by(11, 2) == 5
div_try : U8, U8 -> Try(U8, [DivByZero, ..])

Divide the first U8 by the second, returning Err(DivByZero) instead of crashing if the divisor is zero.

div_ceil_by : U8, U8 -> U8

Divide the first U8 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in U8.

expect U8.div_ceil_by(7, 2) == 4

expect U8.div_ceil_by(8, 2) == 4
div_ceil_try : U8, U8 -> Try(U8, [DivByZero, ..])

Divide the first U8 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect U8.div_ceil_try(7, 2) == Ok(4)

expect U8.div_ceil_try(1, 0) == Err(DivByZero)
div_trunc_by : U8, U8 -> U8

Divide the first U8 by the second, truncating down (toward zero). For unsigned integers this behaves the same as U8.div_by.

expect U8.div_trunc_by(7, 2) == 3
rem_by : U8, U8 -> U8

Return the remainder of dividing the first U8 by the second.

expect U8.rem_by(7, 3) == 1
mod_by : U8, U8 -> U8

Return the modulus of the first U8 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the divisor. For unsigned integers this behaves the same as U8.rem_by.

expect U8.mod_by(7, 3) == 1
abs_diff : U8, U8 -> U8

Return the absolute difference between two U8 values.

expect U8.abs_diff(2, 5) == 3

expect U8.abs_diff(5, 2) == 3
shift_left_by : U8, U8 -> U8

Shift the bits of a U8 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right. Each left shift by one is equivalent to multiplying by 2 (modulo 256).

expect U8.shift_left_by(1, 3) == 8

expect U8.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : U8, U8 -> U8

Shift the bits of a U8 to the right by the given number of positions. Bits shifted past the least significant bit are discarded, and zeros are shifted in on the left. Each right shift by one is equivalent to integer division by 2. For unsigned integers this behaves the same as U8.shift_right_zf_by.

expect U8.shift_right_by(32, 2) == 8

expect U8.shift_right_by(0b1010_0000, 3) == 0b0001_0100
shift_right_zf_by : U8, U8 -> U8

Shift the bits of a U8 to the right by the given number of positions, filling the vacated high bits with zeros ("zero-fill"). For unsigned integers this behaves the same as U8.shift_right_by.

expect U8.shift_right_zf_by(32, 2) == 8

expect U8.shift_right_zf_by(0b1010_0000, 3) == 0b0001_0100
bitwise_and : U8, U8 -> U8

Returns the bitwise AND of two U8 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect U8.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : U8, U8 -> U8

Returns the bitwise OR of two U8 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect U8.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : U8, U8 -> U8

Returns the bitwise XOR of two U8 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect U8.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : U8 -> U8

Returns the bitwise NOT of a U8 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0.

expect U8.bitwise_not(0) == 255
count_leading_zero_bits : U8 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect U8.count_leading_zero_bits(1) == 7

expect U8.count_leading_zero_bits(0) == 8
count_trailing_zero_bits : U8 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect U8.count_trailing_zero_bits(8) == 3

expect U8.count_trailing_zero_bits(0) == 8
count_one_bits : U8 -> U8

Count the one bits in the value.

expect U8.count_one_bits(0b1011) == 3

expect U8.count_one_bits(0) == 0
from_int_digits : List(U8) -> Try(U8, [OutOfRange])

Build a U8 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a U8 (0 to 255), or if any element is not a valid digit.

expect U8.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(U8, [InvalidNumeral(Str)])

Convert a numeric literal into a U8. This is the hook the compiler uses when a literal is given type U8; most code should parse user text with U8.from_str instead.

from_str : Str -> Try(U8, [BadNumStr, ..])

Parse a U8 from a Str. Returns Err(BadNumStr) if the string is not a valid non-negative integer, or if the parsed value does not fit in a U8 (0 to 255).

expect U8.from_str("42") == Ok(42)

expect U8.from_str("-1") == Err(BadNumStr)
to : U8, U8 -> Iter(U8)

Iterator of integers beginning with this U8 and ending with the other U8. (Use U8.until instead to end with the other U8 minus one.) Returns an empty iterator if this U8 is greater than the other.

expect Iter.fold(U8.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(U8.to(3, 3), [], |acc, item| acc.append(item)) == [3]

expect Iter.fold(U8.to(5, 2), [], |acc, item| acc.append(item)) == []
until : U8, U8 -> Iter(U8)

Iterator of integers beginning with this U8 and ending with the other U8 minus one. (Use U8.to instead to end with the other U8 exactly, instead of minus one.) Returns an empty iterator if this U8 is greater than or equal to the other.

expect Iter.fold(U8.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(U8.until(3, 3), [], |acc, item| acc.append(item)) == []

expect Iter.fold(U8.until(5, 2), [], |acc, item| acc.append(item)) == []
to_i8_wrap : U8 -> I8

Convert a U8 to an I8, wrapping on overflow. Values from 0 to 127 are preserved; values from 128 to 255 wrap into the negative range -128 to -1 (two's complement reinterpretation of the bits).

expect U8.to_i8_wrap(42) == 42

expect U8.to_i8_wrap(200) == -56
to_i8_try : U8 -> Try(I8, [OutOfRange, ..])

Convert a U8 to an I8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 127 succeed; values from 128 to 255 return Err(OutOfRange).

expect U8.to_i8_try(42) == Ok(42)

expect U8.to_i8_try(200) == Err(OutOfRange)
to_i16 : U8 -> I16

Convert a U8 to an I16. This widening conversion preserves every U8 value exactly.

to_i32 : U8 -> I32

Convert a U8 to an I32. This widening conversion preserves every U8 value exactly.

to_i64 : U8 -> I64

Convert a U8 to an I64. This widening conversion preserves every U8 value exactly.

to_i128 : U8 -> I128

Convert a U8 to an I128. This widening conversion preserves every U8 value exactly.

to_u16 : U8 -> U16

Convert a U8 to a U16. This widening conversion preserves every U8 value exactly.

to_u32 : U8 -> U32

Convert a U8 to a U32. This widening conversion preserves every U8 value exactly.

to_u64 : U8 -> U64

Convert a U8 to a U64. This widening conversion preserves every U8 value exactly.

to_u128 : U8 -> U128

Convert a U8 to a U128. This widening conversion preserves every U8 value exactly.

encode : U8, fmt -> Try(encoded, err) where { fmt.encode_u8 : fmt, U8 -> Try(encoded, err) }

Encode a U8 using a format that provides encode_u8

decode : src, fmt -> (Try(U8, err), src) where { fmt.decode_u8 : fmt, src -> (Try(U8, err), src) }

Decode a U8 using a format that provides decode_u8

I8

default : -> I8

Returns the default I8 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect I8.default() == 0
highest : I8

The highest value representable by an I8, which is 127.

expect I8.highest == 127
lowest : I8

The lowest value representable by an I8, which is -128.

expect I8.lowest == -128
to_str : I8 -> Str

Convert an I8 to its decimal string representation.

expect I8.to_str(42) == "42"

expect I8.to_str(-42) == "-42"
is_zero : I8 -> Bool

Returns Bool.True if the value is 0.

expect I8.is_zero(0)

expect !I8.is_zero(7)
is_negative : I8 -> Bool

Returns Bool.True if the value is less than 0.

expect I8.is_negative(-3)

expect !I8.is_negative(0)
is_positive : I8 -> Bool

Returns Bool.True if the value is greater than 0.

expect I8.is_positive(3)

expect !I8.is_positive(0)
is_eq : I8, I8 -> Bool

Returns Bool.True if the two values are equal.

expect I8.is_eq(3, 3)

expect !I8.is_eq(3, 4)
is_gt : I8, I8 -> Bool

Returns Bool.True if the first value is greater than the second.

expect I8.is_gt(5, 3)

expect !I8.is_gt(3, 3)
is_gte : I8, I8 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect I8.is_gte(3, 3)

expect !I8.is_gte(2, 3)
is_lt : I8, I8 -> Bool

Returns Bool.True if the first value is less than the second.

expect I8.is_lt(3, 5)

expect !I8.is_lt(3, 3)
is_lte : I8, I8 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect I8.is_lte(3, 3)

expect !I8.is_lte(5, 3)
compare : I8, I8 -> [LT, EQ, GT]

Compare two I8 values and return their ordering.

expect I8.compare(1, 2) == LT

expect I8.compare(2, 2) == EQ

expect I8.compare(3, 2) == GT
is_even : I8 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect I8.is_even(4)

expect !I8.is_even(5)
is_odd : I8 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect I8.is_odd(5)

expect !I8.is_odd(4)
is_multiple_of : I8, I8 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect I8.is_multiple_of(12, 3)

expect I8.is_multiple_of(0, 0)

expect !I8.is_multiple_of(5, 0)

expect I8.is_multiple_of(I8.lowest, -1)
max : I8, I8 -> I8

Returns the greater of two I8 values.

expect I8.max(5, 3) == 5

expect I8.max(-3, -1) == -1
min : I8, I8 -> I8

Returns the smaller of two I8 values.

expect I8.min(5, 3) == 3

expect I8.min(-3, -1) == -3
negate : I8 -> I8

Negate an I8. Crashes on -128, since 128 does not fit in an I8.

expect I8.negate(3) == -3

expect I8.negate(-3) == 3
abs : I8 -> I8

Return the absolute value of an I8. Crashes on -128, since 128 does not fit in an I8.

expect I8.abs(3) == 3

expect I8.abs(-3) == 3
plus : I8, I8 -> I8

Add two I8 values.

expect I8.plus(2, 3) == 5
add_try : I8, I8 -> Try(I8, [Overflow, ..])

Add two I8 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I8.

plus_saturated : I8, I8 -> I8

Add two I8 values, saturating at I8.highest or I8.lowest on overflow rather than wrapping around.

expect I8.plus_saturated(I8.highest, 1) == I8.highest

expect I8.plus_saturated(I8.lowest, -1) == I8.lowest

expect I8.plus_saturated(2, 3) == 5
minus : I8, I8 -> I8

Subtract the second I8 from the first.

expect I8.minus(5, 3) == 2
sub_try : I8, I8 -> Try(I8, [Overflow, ..])

Subtract the second I8 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in an I8.

minus_saturated : I8, I8 -> I8

Subtract the second I8 from the first, saturating at the nearest bound on overflow.

expect I8.minus_saturated(I8.lowest, 1) == I8.lowest

expect I8.minus_saturated(I8.highest, -1) == I8.highest

expect I8.minus_saturated(5, 3) == 2
times : I8, I8 -> I8

Multiply two I8 values.

expect I8.times(4, 3) == 12
mul_try : I8, I8 -> Try(I8, [Overflow, ..])

Multiply two I8 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I8.

times_saturated : I8, I8 -> I8

Multiply two I8 values, saturating at the nearest bound on overflow.

expect I8.times_saturated(I8.highest, 2) == I8.highest

expect I8.times_saturated(I8.lowest, 2) == I8.lowest

expect I8.times_saturated(4, 3) == 12
pow : I8, I8 -> I8

Raise the first I8 value to the power of the second. Crashes if the exact result does not fit in I8.

expect I8.pow(2, 3) == 8

expect I8.pow(5, 0) == 1
pow_try : I8, I8 -> Try(I8, [Overflow, Underflow, ..])

Raise the first I8 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect I8.pow_try(2, 3) == Ok(8)

expect I8.pow_try(I8.highest, 2) == Err(Overflow)

expect I8.pow_try(2, -1) == Err(Underflow)

expect I8.pow_try(-1, -3) == Ok(-1)
div_by : I8, I8 -> I8

Divide the first I8 by the second, discarding any remainder. Crashes if the second I8 is zero.

expect I8.div_by(10, 2) == 5

expect I8.div_by(11, 2) == 5
div_try : I8, I8 -> Try(I8, [DivByZero, Overflow, ..])

Divide the first I8 by the second. Returns Err(DivByZero) if the divisor is zero, or Err(Overflow) for I8.lowest / -1.

div_ceil_by : I8, I8 -> I8

Divide the first I8 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in I8.

expect I8.div_ceil_by(7, 2) == 4

expect I8.div_ceil_by(8, 2) == 4

expect I8.div_ceil_by(-7, 2) == -3

expect I8.div_ceil_by(-7, -2) == 4
div_ceil_try : I8, I8 -> Try(I8, [DivByZero, Overflow, ..])

Divide the first I8 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect I8.div_ceil_try(7, 2) == Ok(4)

expect I8.div_ceil_try(1, 0) == Err(DivByZero)

expect I8.div_ceil_try(I8.lowest, -1) == Err(Overflow)
div_trunc_by : I8, I8 -> I8

Divide the first I8 by the second, truncating toward zero.

expect I8.div_trunc_by(7, 2) == 3

expect I8.div_trunc_by(-7, 2) == -3
rem_by : I8, I8 -> I8

Return the remainder of dividing the first I8 by the second. The sign of the result matches the sign of the dividend.

expect I8.rem_by(7, 3) == 1

expect I8.rem_by(-7, 3) == -1
mod_by : I8, I8 -> I8

Return the modulus of the first I8 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the absolute value of the divisor. Unlike I8.rem_by, the sign of the result matches the sign of the divisor.

expect I8.mod_by(7, 3) == 1

expect I8.mod_by(-7, 3) == 2
abs_diff : I8, I8 -> U8

Return the absolute difference between two I8 values as a U8. The result is a U8 because the difference between two I8 values can be as large as 255, which does not fit in an I8.

expect I8.abs_diff(2, 5) == 3

expect I8.abs_diff(-1, 5) == 6
shift_left_by : I8, U8 -> I8

Shift the bits of an I8 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right.

expect I8.shift_left_by(1, 3) == 8

expect I8.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : I8, U8 -> I8

Shift the bits of an I8 to the right by the given number of positions, preserving the sign ("arithmetic shift"). The sign bit is shifted in on the left, so negative values remain negative. Each right shift by one is equivalent to integer division by 2 (rounding toward negative infinity).

expect I8.shift_right_by(32, 2) == 8

expect I8.shift_right_by(-32, 2) == -8
shift_right_zf_by : I8, U8 -> I8

Shift the bits of an I8 to the right by the given number of positions.

expect I8.shift_right_zf_by(32, 2) == 8

expect I8.shift_right_zf_by(0b0101_0000, 3) == 0b0000_1010
bitwise_and : I8, I8 -> I8

Returns the bitwise AND of two I8 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect I8.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : I8, I8 -> I8

Returns the bitwise OR of two I8 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect I8.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : I8, I8 -> I8

Returns the bitwise XOR of two I8 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect I8.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : I8 -> I8

Returns the bitwise NOT of an I8 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0. For signed integers this is equivalent to -value - 1.

expect I8.bitwise_not(5) == -6
count_leading_zero_bits : I8 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect I8.count_leading_zero_bits(-1) == 0

expect I8.count_leading_zero_bits(0) == 8
count_trailing_zero_bits : I8 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect I8.count_trailing_zero_bits(-8) == 3

expect I8.count_trailing_zero_bits(0) == 8
count_one_bits : I8 -> U8

Count the one bits in the value.

expect I8.count_one_bits(-1) == 8

expect I8.count_one_bits(0) == 0
to : I8, I8 -> Iter(I8)

Iterator of integers beginning with this I8 and ending with the other I8. (Use I8.until instead to end with the other I8 minus one.) Returns an empty iterator if this I8 is greater than the other.

expect Iter.fold(I8.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(I8.to(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0, 1]

expect Iter.fold(I8.to(5, 2), [], |acc, item| acc.append(item)) == []
until : I8, I8 -> Iter(I8)

Iterator of integers beginning with this I8 and ending with the other I8 minus one. (Use I8.to instead to end with the other I8 exactly, instead of minus one.) Returns an empty iterator if this I8 is greater than or equal to the other.

expect Iter.fold(I8.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(I8.until(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0]

expect Iter.fold(I8.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(I8, [OutOfRange])

Build an I8 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an I8 (-128 to 127), or if any element is not a valid digit. The result is always non-negative; to build a negative value, I8.negate the result.

expect I8.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(I8, [InvalidNumeral(Str)])

Convert a numeric literal into an I8. This is the hook the compiler uses when a literal is given type I8; most code should parse user text with I8.from_str instead.

from_str : Str -> Try(I8, [BadNumStr, ..])

Parse an I8 from a Str. Returns Err(BadNumStr) if the string is not a valid integer, or if the parsed value does not fit in an I8 (-128 to 127).

expect I8.from_str("42") == Ok(42)

expect I8.from_str("-1") == Ok(-1)

expect I8.from_str("200") == Err(BadNumStr)
to_i16 : I8 -> I16

Convert an I8 to an I16. This widening conversion preserves every I8 value exactly.

to_i32 : I8 -> I32

Convert an I8 to an I32. This widening conversion preserves every I8 value exactly.

to_i64 : I8 -> I64

Convert an I8 to an I64. This widening conversion preserves every I8 value exactly.

to_i128 : I8 -> I128

Convert an I8 to an I128. This widening conversion preserves every I8 value exactly.

to_u8_wrap : I8 -> U8

Convert an I8 to a U8, wrapping on overflow. Values from 0 to 127 are preserved; values from -128 to -1 wrap into the range 128 to 255 (two's complement reinterpretation of the bits).

expect I8.to_u8_wrap(42) == 42

expect I8.to_u8_wrap(-56) == 200
to_u8_try : I8 -> Try(U8, [OutOfRange, ..])

Convert an I8 to a U8, returning Err(OutOfRange) if the value is negative. Values from 0 to 127 succeed; negative values return Err(OutOfRange).

expect I8.to_u8_try(42) == Ok(42)

expect I8.to_u8_try(-1) == Err(OutOfRange)
to_u16_wrap : I8 -> U16

Convert an I8 to a U16, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U16 range (two's complement reinterpretation of the sign-extended bits).

expect I8.to_u16_wrap(42) == 42

expect I8.to_u16_wrap(-1) == 65535
to_u16_try : I8 -> Try(U16, [OutOfRange, ..])

Convert an I8 to a U16, returning Err(OutOfRange) if the value is negative. Values from 0 to 127 succeed; negative values return Err(OutOfRange).

expect I8.to_u16_try(42) == Ok(42)

expect I8.to_u16_try(-1) == Err(OutOfRange)
to_u32_wrap : I8 -> U32

Convert an I8 to a U32, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U32 range (two's complement reinterpretation of the sign-extended bits).

expect I8.to_u32_wrap(42) == 42

expect I8.to_u32_wrap(-1) == 4294967295
to_u32_try : I8 -> Try(U32, [OutOfRange, ..])

Convert an I8 to a U32, returning Err(OutOfRange) if the value is negative. Values from 0 to 127 succeed; negative values return Err(OutOfRange).

expect I8.to_u32_try(42) == Ok(42)

expect I8.to_u32_try(-1) == Err(OutOfRange)
to_u64_wrap : I8 -> U64

Convert an I8 to a U64, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U64 range (two's complement reinterpretation of the sign-extended bits).

expect I8.to_u64_wrap(42) == 42

expect I8.to_u64_wrap(-1) == 18446744073709551615
to_u64_try : I8 -> Try(U64, [OutOfRange, ..])

Convert an I8 to a U64, returning Err(OutOfRange) if the value is negative. Values from 0 to 127 succeed; negative values return Err(OutOfRange).

expect I8.to_u64_try(42) == Ok(42)

expect I8.to_u64_try(-1) == Err(OutOfRange)
to_u128_wrap : I8 -> U128

Convert an I8 to a U128, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U128 range (two's complement reinterpretation of the sign-extended bits).

expect I8.to_u128_wrap(42) == 42
to_u128_try : I8 -> Try(U128, [OutOfRange, ..])

Convert an I8 to a U128, returning Err(OutOfRange) if the value is negative. Values from 0 to 127 succeed; negative values return Err(OutOfRange).

expect I8.to_u128_try(42) == Ok(42)

expect I8.to_u128_try(-1) == Err(OutOfRange)
encode : I8, fmt -> Try(encoded, err) where { fmt.encode_i8 : fmt, I8 -> Try(encoded, err) }

Encode an I8 using a format that provides encode_i8

decode : src, fmt -> (Try(I8, err), src) where { fmt.decode_i8 : fmt, src -> (Try(I8, err), src) }

Decode an I8 using a format that provides decode_i8

U16

default : -> U16

Returns the default U16 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect U16.default() == 0
highest : U16

The highest value representable by a U16, which is 65535.

expect U16.highest == 65535
lowest : U16

The lowest value representable by a U16, which is 0.

expect U16.lowest == 0
to_str : U16 -> Str

Convert a U16 to its decimal string representation.

expect U16.to_str(42) == "42"
is_zero : U16 -> Bool

Returns Bool.True if the value is 0.

expect U16.is_zero(0)

expect !U16.is_zero(7)
is_eq : U16, U16 -> Bool

Returns Bool.True if the two values are equal.

expect U16.is_eq(3, 3)

expect !U16.is_eq(3, 4)
is_gt : U16, U16 -> Bool

Returns Bool.True if the first value is greater than the second.

expect U16.is_gt(5, 3)

expect !U16.is_gt(3, 3)
is_gte : U16, U16 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect U16.is_gte(3, 3)

expect !U16.is_gte(2, 3)
is_lt : U16, U16 -> Bool

Returns Bool.True if the first value is less than the second.

expect U16.is_lt(3, 5)

expect !U16.is_lt(3, 3)
is_lte : U16, U16 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect U16.is_lte(3, 3)

expect !U16.is_lte(5, 3)
compare : U16, U16 -> [LT, EQ, GT]

Compare two U16 values and return their ordering.

expect U16.compare(1, 2) == LT

expect U16.compare(2, 2) == EQ

expect U16.compare(3, 2) == GT
is_even : U16 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect U16.is_even(4)

expect !U16.is_even(5)
is_odd : U16 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect U16.is_odd(5)

expect !U16.is_odd(4)
is_multiple_of : U16, U16 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect U16.is_multiple_of(12, 3)

expect U16.is_multiple_of(0, 0)

expect !U16.is_multiple_of(5, 0)
max : U16, U16 -> U16

Returns the greater of two U16 values.

expect U16.max(5, 3) == 5
min : U16, U16 -> U16

Returns the smaller of two U16 values.

expect U16.min(5, 3) == 3
add_try : U16, U16 -> Try(U16, [Overflow, ..])

Add two U16 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U16.

plus_saturated : U16, U16 -> U16

Add two U16 values, saturating at U16.highest on overflow rather than wrapping around.

expect U16.plus_saturated(U16.highest, 1) == U16.highest

expect U16.plus_saturated(2, 3) == 5
minus : U16, U16 -> U16

Subtract the second U16 from the first.

expect U16.minus(5, 3) == 2
sub_try : U16, U16 -> Try(U16, [Overflow, ..])

Subtract the second U16 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in a U16.

minus_saturated : U16, U16 -> U16

Subtract the second U16 from the first, saturating at the nearest bound on overflow.

expect U16.minus_saturated(0, 1) == 0

expect U16.minus_saturated(5, 3) == 2
mul_try : U16, U16 -> Try(U16, [Overflow, ..])

Multiply two U16 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U16.

times_saturated : U16, U16 -> U16

Multiply two U16 values, saturating at the nearest bound on overflow.

expect U16.times_saturated(U16.highest, 2) == U16.highest

expect U16.times_saturated(4, 3) == 12
pow : U16, U16 -> U16

Raise the first U16 value to the power of the second. Crashes if the exact result does not fit in U16.

expect U16.pow(2, 3) == 8

expect U16.pow(5, 0) == 1
pow_try : U16, U16 -> Try(U16, [Overflow, ..])

Raise the first U16 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect U16.pow_try(2, 3) == Ok(8)

expect U16.pow_try(U16.highest, 2) == Err(Overflow)
div_by : U16, U16 -> U16

Divide the first U16 by the second, discarding any remainder. Crashes if the second U16 is zero.

expect U16.div_by(10, 2) == 5

expect U16.div_by(11, 2) == 5
div_try : U16, U16 -> Try(U16, [DivByZero, ..])

Divide the first U16 by the second, returning Err(DivByZero) instead of crashing if the divisor is zero.

div_ceil_by : U16, U16 -> U16

Divide the first U16 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in U16.

expect U16.div_ceil_by(7, 2) == 4

expect U16.div_ceil_by(8, 2) == 4
div_ceil_try : U16, U16 -> Try(U16, [DivByZero, ..])

Divide the first U16 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect U16.div_ceil_try(7, 2) == Ok(4)

expect U16.div_ceil_try(1, 0) == Err(DivByZero)
div_trunc_by : U16, U16 -> U16

Divide the first U16 by the second, truncating down (toward zero). For unsigned integers this behaves the same as U16.div_by.

expect U16.div_trunc_by(7, 2) == 3
rem_by : U16, U16 -> U16

Return the remainder of dividing the first U16 by the second.

expect U16.rem_by(7, 3) == 1
mod_by : U16, U16 -> U16

Return the modulus of the first U16 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the divisor. For unsigned integers this behaves the same as U16.rem_by.

expect U16.mod_by(7, 3) == 1
abs_diff : U16, U16 -> U16

Return the absolute difference between two U16 values.

expect U16.abs_diff(2, 5) == 3

expect U16.abs_diff(5, 2) == 3
shift_left_by : U16, U8 -> U16

Shift the bits of a U16 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right. Each left shift by one is equivalent to multiplying by 2 (modulo 65536).

expect U16.shift_left_by(1, 3) == 8

expect U16.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : U16, U8 -> U16

Shift the bits of a U16 to the right by the given number of positions. Bits shifted past the least significant bit are discarded, and zeros are shifted in on the left. Each right shift by one is equivalent to integer division by 2. For unsigned integers this behaves the same as U16.shift_right_zf_by.

expect U16.shift_right_by(32, 2) == 8

expect U16.shift_right_by(0b1010_0000, 3) == 0b0001_0100
shift_right_zf_by : U16, U8 -> U16

Shift the bits of a U16 to the right by the given number of positions, filling the vacated high bits with zeros ("zero-fill"). For unsigned integers this behaves the same as U16.shift_right_by.

expect U16.shift_right_zf_by(32, 2) == 8

expect U16.shift_right_zf_by(0b1010_0000, 3) == 0b0001_0100
bitwise_and : U16, U16 -> U16

Returns the bitwise AND of two U16 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect U16.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : U16, U16 -> U16

Returns the bitwise OR of two U16 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect U16.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : U16, U16 -> U16

Returns the bitwise XOR of two U16 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect U16.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : U16 -> U16

Returns the bitwise NOT of a U16 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0.

expect U16.bitwise_not(0) == 65535
count_leading_zero_bits : U16 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect U16.count_leading_zero_bits(1) == 15

expect U16.count_leading_zero_bits(0) == 16
count_trailing_zero_bits : U16 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect U16.count_trailing_zero_bits(8) == 3

expect U16.count_trailing_zero_bits(0) == 16
count_one_bits : U16 -> U8

Count the one bits in the value.

expect U16.count_one_bits(0b1011) == 3

expect U16.count_one_bits(0) == 0
to : U16, U16 -> Iter(U16)

Iterator of integers beginning with this U16 and ending with the other U16. (Use U16.until instead to end with the other U16 minus one.) Returns an empty iterator if this U16 is greater than the other.

expect Iter.fold(U16.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(U16.to(3, 3), [], |acc, item| acc.append(item)) == [3]

expect Iter.fold(U16.to(5, 2), [], |acc, item| acc.append(item)) == []
until : U16, U16 -> Iter(U16)

Iterator of integers beginning with this U16 and ending with the other U16 minus one. (Use U16.to instead to end with the other U16 exactly, instead of minus one.) Returns an empty iterator if this U16 is greater than or equal to the other.

expect Iter.fold(U16.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(U16.until(3, 3), [], |acc, item| acc.append(item)) == []

expect Iter.fold(U16.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(U16, [OutOfRange])

Build a U16 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a U16 (0 to 65535), or if any element is not a valid digit.

expect U16.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(U16, [InvalidNumeral(Str)])

Convert a numeric literal into a U16. This is the hook the compiler uses when a literal is given type U16; most code should parse user text with U16.from_str instead.

from_str : Str -> Try(U16, [BadNumStr, ..])

Parse a U16 from a Str. Returns Err(BadNumStr) if the string is not a valid non-negative integer, or if the parsed value does not fit in a U16 (0 to 65535).

expect U16.from_str("42") == Ok(42)

expect U16.from_str("-1") == Err(BadNumStr)
to_i8_wrap : U16 -> I8

Convert a U16 to an I8, wrapping on overflow. Values from 0 to 127 are preserved; larger values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect U16.to_i8_wrap(42) == 42

expect U16.to_i8_wrap(200) == -56
to_i8_try : U16 -> Try(I8, [OutOfRange, ..])

Convert a U16 to an I8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 127 succeed; values from 128 to 65535 return Err(OutOfRange).

expect U16.to_i8_try(42) == Ok(42)

expect U16.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : U16 -> I16

Convert a U16 to an I16, wrapping on overflow. Values from 0 to 32767 are preserved; values from 32768 to 65535 wrap into the negative range -32768 to -1 (two's complement reinterpretation of the bits).

expect U16.to_i16_wrap(42) == 42

expect U16.to_i16_wrap(40000) == -25536
to_i16_try : U16 -> Try(I16, [OutOfRange, ..])

Convert a U16 to an I16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 32767 succeed; values from 32768 to 65535 return Err(OutOfRange).

expect U16.to_i16_try(42) == Ok(42)

expect U16.to_i16_try(40000) == Err(OutOfRange)
to_i32 : U16 -> I32

Convert a U16 to an I32. This widening conversion preserves every U16 value exactly.

to_i64 : U16 -> I64

Convert a U16 to an I64. This widening conversion preserves every U16 value exactly.

to_u8_wrap : U16 -> U8

Convert a U16 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; larger values wrap by truncating to the low 8 bits.

expect U16.to_u8_wrap(42) == 42

expect U16.to_u8_wrap(300) == 44
to_u8_try : U16 -> Try(U8, [OutOfRange, ..])

Convert a U16 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; values from 256 to 65535 return Err(OutOfRange).

expect U16.to_u8_try(42) == Ok(42)

expect U16.to_u8_try(300) == Err(OutOfRange)
to_u32 : U16 -> U32

Convert a U16 to a U32. This widening conversion preserves every U16 value exactly.

to_u64 : U16 -> U64

Convert a U16 to a U64. This widening conversion preserves every U16 value exactly.

encode : U16, fmt -> Try(encoded, err) where { fmt.encode_u16 : fmt, U16 -> Try(encoded, err) }
decode : src, fmt -> (Try(U16, err), src) where { fmt.decode_u16 : fmt, src -> (Try(U16, err), src) }

I16

default : -> I16

Returns the default I16 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect I16.default() == 0
highest : I16

The highest value representable by an I16, which is 32767.

expect I16.highest == 32767
lowest : I16

The lowest value representable by an I16, which is -32768.

expect I16.lowest == -32768
to_str : I16 -> Str

Convert an I16 to its decimal string representation.

expect I16.to_str(42) == "42"

expect I16.to_str(-42) == "-42"
is_zero : I16 -> Bool

Returns Bool.True if the value is 0.

expect I16.is_zero(0)

expect !I16.is_zero(7)
is_negative : I16 -> Bool

Returns Bool.True if the value is less than 0.

expect I16.is_negative(-3)

expect !I16.is_negative(0)
is_positive : I16 -> Bool

Returns Bool.True if the value is greater than 0.

expect I16.is_positive(3)

expect !I16.is_positive(0)
is_eq : I16, I16 -> Bool

Returns Bool.True if the two values are equal.

expect I16.is_eq(3, 3)

expect !I16.is_eq(3, 4)
is_gt : I16, I16 -> Bool

Returns Bool.True if the first value is greater than the second.

expect I16.is_gt(5, 3)

expect !I16.is_gt(3, 3)
is_gte : I16, I16 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect I16.is_gte(3, 3)

expect !I16.is_gte(2, 3)
is_lt : I16, I16 -> Bool

Returns Bool.True if the first value is less than the second.

expect I16.is_lt(3, 5)

expect !I16.is_lt(3, 3)
is_lte : I16, I16 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect I16.is_lte(3, 3)

expect !I16.is_lte(5, 3)
compare : I16, I16 -> [LT, EQ, GT]

Compare two I16 values and return their ordering.

expect I16.compare(1, 2) == LT

expect I16.compare(2, 2) == EQ

expect I16.compare(3, 2) == GT
is_even : I16 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect I16.is_even(4)

expect !I16.is_even(5)
is_odd : I16 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect I16.is_odd(5)

expect !I16.is_odd(4)
is_multiple_of : I16, I16 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect I16.is_multiple_of(12, 3)

expect I16.is_multiple_of(0, 0)

expect !I16.is_multiple_of(5, 0)

expect I16.is_multiple_of(I16.lowest, -1)
max : I16, I16 -> I16

Returns the greater of two I16 values.

expect I16.max(5, 3) == 5

expect I16.max(-3, -1) == -1
min : I16, I16 -> I16

Returns the smaller of two I16 values.

expect I16.min(5, 3) == 3

expect I16.min(-3, -1) == -3
negate : I16 -> I16

Negate an I16. Crashes on -32768, since 32768 does not fit in an I16.

expect I16.negate(3) == -3

expect I16.negate(-3) == 3
abs : I16 -> I16

Return the absolute value of an I16. Crashes on -32768, since 32768 does not fit in an I16.

expect I16.abs(3) == 3

expect I16.abs(-3) == 3
add_try : I16, I16 -> Try(I16, [Overflow, ..])

Add two I16 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I16.

plus_saturated : I16, I16 -> I16

Add two I16 values, saturating at I16.highest or I16.lowest on overflow rather than wrapping around.

expect I16.plus_saturated(I16.highest, 1) == I16.highest

expect I16.plus_saturated(I16.lowest, -1) == I16.lowest

expect I16.plus_saturated(2, 3) == 5
minus : I16, I16 -> I16

Subtract the second I16 from the first.

expect I16.minus(5, 3) == 2
sub_try : I16, I16 -> Try(I16, [Overflow, ..])

Subtract the second I16 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in an I16.

minus_saturated : I16, I16 -> I16

Subtract the second I16 from the first, saturating at the nearest bound on overflow.

expect I16.minus_saturated(I16.lowest, 1) == I16.lowest

expect I16.minus_saturated(I16.highest, -1) == I16.highest

expect I16.minus_saturated(5, 3) == 2
mul_try : I16, I16 -> Try(I16, [Overflow, ..])

Multiply two I16 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I16.

times_saturated : I16, I16 -> I16

Multiply two I16 values, saturating at the nearest bound on overflow.

expect I16.times_saturated(I16.highest, 2) == I16.highest

expect I16.times_saturated(I16.lowest, 2) == I16.lowest

expect I16.times_saturated(4, 3) == 12
pow : I16, I16 -> I16

Raise the first I16 value to the power of the second. Crashes if the exact result does not fit in I16.

expect I16.pow(2, 3) == 8

expect I16.pow(5, 0) == 1
pow_try : I16, I16 -> Try(I16, [Overflow, Underflow, ..])

Raise the first I16 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect I16.pow_try(2, 3) == Ok(8)

expect I16.pow_try(I16.highest, 2) == Err(Overflow)

expect I16.pow_try(2, -1) == Err(Underflow)

expect I16.pow_try(-1, -3) == Ok(-1)
div_by : I16, I16 -> I16

Divide the first I16 by the second, discarding any remainder. Crashes if the second I16 is zero.

expect I16.div_by(10, 2) == 5

expect I16.div_by(11, 2) == 5
div_try : I16, I16 -> Try(I16, [DivByZero, Overflow, ..])

Divide the first I16 by the second. Returns Err(DivByZero) if the divisor is zero, or Err(Overflow) for I16.lowest / -1.

div_ceil_by : I16, I16 -> I16

Divide the first I16 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in I16.

expect I16.div_ceil_by(7, 2) == 4

expect I16.div_ceil_by(8, 2) == 4

expect I16.div_ceil_by(-7, 2) == -3

expect I16.div_ceil_by(-7, -2) == 4
div_ceil_try : I16, I16 -> Try(I16, [DivByZero, Overflow, ..])

Divide the first I16 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect I16.div_ceil_try(7, 2) == Ok(4)

expect I16.div_ceil_try(1, 0) == Err(DivByZero)

expect I16.div_ceil_try(I16.lowest, -1) == Err(Overflow)
div_trunc_by : I16, I16 -> I16

Divide the first I16 by the second, truncating toward zero.

expect I16.div_trunc_by(7, 2) == 3

expect I16.div_trunc_by(-7, 2) == -3
rem_by : I16, I16 -> I16

Return the remainder of dividing the first I16 by the second. The sign of the result matches the sign of the dividend.

expect I16.rem_by(7, 3) == 1

expect I16.rem_by(-7, 3) == -1
mod_by : I16, I16 -> I16

Return the modulus of the first I16 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the absolute value of the divisor. Unlike I16.rem_by, the sign of the result matches the sign of the divisor.

expect I16.mod_by(7, 3) == 1

expect I16.mod_by(-7, 3) == 2
abs_diff : I16, I16 -> U16

Return the absolute difference between two I16 values as a U16. The result is a U16 because the difference between two I16 values can be as large as 65535, which does not fit in an I16.

expect I16.abs_diff(2, 5) == 3

expect I16.abs_diff(-1, 5) == 6
shift_left_by : I16, U8 -> I16

Shift the bits of an I16 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right.

expect I16.shift_left_by(1, 3) == 8

expect I16.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : I16, U8 -> I16

Shift the bits of an I16 to the right by the given number of positions, preserving the sign ("arithmetic shift"). The sign bit is shifted in on the left, so negative values remain negative. Each right shift by one is equivalent to integer division by 2 (rounding toward negative infinity).

expect I16.shift_right_by(32, 2) == 8

expect I16.shift_right_by(-32, 2) == -8
shift_right_zf_by : I16, U8 -> I16

Shift the bits of an I16 to the right by the given number of positions.

expect I16.shift_right_zf_by(32, 2) == 8

expect I16.shift_right_zf_by(0b0101_0000, 3) == 0b0000_1010
bitwise_and : I16, I16 -> I16

Returns the bitwise AND of two I16 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect I16.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : I16, I16 -> I16

Returns the bitwise OR of two I16 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect I16.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : I16, I16 -> I16

Returns the bitwise XOR of two I16 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect I16.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : I16 -> I16

Returns the bitwise NOT of an I16 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0. For signed integers this is equivalent to -value - 1.

expect I16.bitwise_not(5) == -6
count_leading_zero_bits : I16 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect I16.count_leading_zero_bits(-1) == 0

expect I16.count_leading_zero_bits(0) == 16
count_trailing_zero_bits : I16 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect I16.count_trailing_zero_bits(-8) == 3

expect I16.count_trailing_zero_bits(0) == 16
count_one_bits : I16 -> U8

Count the one bits in the value.

expect I16.count_one_bits(-1) == 16

expect I16.count_one_bits(0) == 0
to : I16, I16 -> Iter(I16)

Iterator of integers beginning with this I16 and ending with the other I16. (Use I16.until instead to end with the other I16 minus one.) Returns an empty iterator if this I16 is greater than the other.

expect Iter.fold(I16.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(I16.to(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0, 1]

expect Iter.fold(I16.to(5, 2), [], |acc, item| acc.append(item)) == []
until : I16, I16 -> Iter(I16)

Iterator of integers beginning with this I16 and ending with the other I16 minus one. (Use I16.to instead to end with the other I16 exactly, instead of minus one.) Returns an empty iterator if this I16 is greater than or equal to the other.

expect Iter.fold(I16.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(I16.until(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0]

expect Iter.fold(I16.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(I16, [OutOfRange])

Build an I16 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an I16 (-32768 to 32767), or if any element is not a valid digit. The result is always non-negative; to build a negative value, I16.negate the result.

expect I16.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(I16, [InvalidNumeral(Str)])

Convert a numeric literal into an I16. This is the hook the compiler uses when a literal is given type I16; most code should parse user text with I16.from_str instead.

from_str : Str -> Try(I16, [BadNumStr, ..])

Parse an I16 from a Str. Returns Err(BadNumStr) if the string is not a valid integer, or if the parsed value does not fit in an I16 (-32768 to 32767).

expect I16.from_str("42") == Ok(42)

expect I16.from_str("-1") == Ok(-1)

expect I16.from_str("40000") == Err(BadNumStr)
to_i8_wrap : I16 -> I8

Convert an I16 to an I8, wrapping on overflow. Values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect I16.to_i8_wrap(42) == 42

expect I16.to_i8_wrap(200) == -56
to_i8_try : I16 -> Try(I8, [OutOfRange, ..])

Convert an I16 to an I8, returning Err(OutOfRange) if the value does not fit. Values from -128 to 127 succeed; other values return Err(OutOfRange).

expect I16.to_i8_try(42) == Ok(42)

expect I16.to_i8_try(200) == Err(OutOfRange)
to_i32 : I16 -> I32

Convert an I16 to an I32. This widening conversion preserves every I16 value exactly.

to_i64 : I16 -> I64

Convert an I16 to an I64. This widening conversion preserves every I16 value exactly.

to_u8_wrap : I16 -> U8

Convert an I16 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; other values wrap by truncating to the low 8 bits (two's complement reinterpretation of those bits).

expect I16.to_u8_wrap(42) == 42

expect I16.to_u8_wrap(-1) == 255
to_u8_try : I16 -> Try(U8, [OutOfRange, ..])

Convert an I16 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; other values return Err(OutOfRange).

expect I16.to_u8_try(42) == Ok(42)

expect I16.to_u8_try(-1) == Err(OutOfRange)
to_u16_wrap : I16 -> U16

Convert an I16 to a U16, wrapping on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U16 range (two's complement reinterpretation of the bits).

expect I16.to_u16_wrap(42) == 42

expect I16.to_u16_wrap(-1) == 65535
to_u16_try : I16 -> Try(U16, [OutOfRange, ..])

Convert an I16 to a U16, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I16.to_u16_try(42) == Ok(42)

expect I16.to_u16_try(-1) == Err(OutOfRange)
to_u32_wrap : I16 -> U32

Convert an I16 to a U32, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U32 range (two's complement reinterpretation of the sign-extended bits).

expect I16.to_u32_wrap(42) == 42

expect I16.to_u32_wrap(-1) == 4294967295
to_u32_try : I16 -> Try(U32, [OutOfRange, ..])

Convert an I16 to a U32, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I16.to_u32_try(42) == Ok(42)

expect I16.to_u32_try(-1) == Err(OutOfRange)
to_u64_wrap : I16 -> U64

Convert an I16 to a U64, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U64 range (two's complement reinterpretation of the sign-extended bits).

expect I16.to_u64_wrap(42) == 42

expect I16.to_u64_wrap(-1) == 18446744073709551615
to_u64_try : I16 -> Try(U64, [OutOfRange, ..])

Convert an I16 to a U64, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I16.to_u64_try(42) == Ok(42)

expect I16.to_u64_try(-1) == Err(OutOfRange)
to_u128_wrap : I16 -> U128

Convert an I16 to a U128, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U128 range (two's complement reinterpretation of the sign-extended bits).

expect I16.to_u128_wrap(42) == 42
to_u128_try : I16 -> Try(U128, [OutOfRange, ..])

Convert an I16 to a U128, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I16.to_u128_try(42) == Ok(42)

expect I16.to_u128_try(-1) == Err(OutOfRange)
encode : I16, fmt -> Try(encoded, err) where { fmt.encode_i16 : fmt, I16 -> Try(encoded, err) }
decode : src, fmt -> (Try(I16, err), src) where { fmt.decode_i16 : fmt, src -> (Try(I16, err), src) }

U32

default : -> U32

Returns the default U32 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect U32.default() == 0
highest : U32

The highest value representable by a U32, which is 4294967295.

expect U32.highest == 4294967295
lowest : U32

The lowest value representable by a U32, which is 0.

expect U32.lowest == 0
to_str : U32 -> Str

Convert a U32 to its decimal string representation.

expect U32.to_str(42) == "42"
is_zero : U32 -> Bool

Returns Bool.True if the value is 0.

expect U32.is_zero(0)

expect !U32.is_zero(7)
is_eq : U32, U32 -> Bool

Returns Bool.True if the two values are equal.

expect U32.is_eq(3, 3)

expect !U32.is_eq(3, 4)
is_gt : U32, U32 -> Bool

Returns Bool.True if the first value is greater than the second.

expect U32.is_gt(5, 3)

expect !U32.is_gt(3, 3)
is_gte : U32, U32 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect U32.is_gte(3, 3)

expect !U32.is_gte(2, 3)
is_lt : U32, U32 -> Bool

Returns Bool.True if the first value is less than the second.

expect U32.is_lt(3, 5)

expect !U32.is_lt(3, 3)
is_lte : U32, U32 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect U32.is_lte(3, 3)

expect !U32.is_lte(5, 3)
compare : U32, U32 -> [LT, EQ, GT]

Compare two U32 values and return their ordering.

expect U32.compare(1, 2) == LT

expect U32.compare(2, 2) == EQ

expect U32.compare(3, 2) == GT
is_even : U32 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect U32.is_even(4)

expect !U32.is_even(5)
is_odd : U32 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect U32.is_odd(5)

expect !U32.is_odd(4)
is_multiple_of : U32, U32 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect U32.is_multiple_of(12, 3)

expect U32.is_multiple_of(0, 0)

expect !U32.is_multiple_of(5, 0)
max : U32, U32 -> U32

Returns the greater of two U32 values.

expect U32.max(5, 3) == 5
min : U32, U32 -> U32

Returns the smaller of two U32 values.

expect U32.min(5, 3) == 3
add_try : U32, U32 -> Try(U32, [Overflow, ..])

Add two U32 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U32.

plus_saturated : U32, U32 -> U32

Add two U32 values, saturating at U32.highest on overflow rather than wrapping around.

expect U32.plus_saturated(U32.highest, 1) == U32.highest

expect U32.plus_saturated(2, 3) == 5
minus : U32, U32 -> U32

Subtract the second U32 from the first.

expect U32.minus(5, 3) == 2
sub_try : U32, U32 -> Try(U32, [Overflow, ..])

Subtract the second U32 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in a U32.

minus_saturated : U32, U32 -> U32

Subtract the second U32 from the first, saturating at the nearest bound on overflow.

expect U32.minus_saturated(0, 1) == 0

expect U32.minus_saturated(5, 3) == 2
mul_try : U32, U32 -> Try(U32, [Overflow, ..])

Multiply two U32 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U32.

times_saturated : U32, U32 -> U32

Multiply two U32 values, saturating at the nearest bound on overflow.

expect U32.times_saturated(U32.highest, 2) == U32.highest

expect U32.times_saturated(4, 3) == 12
pow : U32, U32 -> U32

Raise the first U32 value to the power of the second. Crashes if the exact result does not fit in U32.

expect U32.pow(2, 3) == 8

expect U32.pow(5, 0) == 1
pow_try : U32, U32 -> Try(U32, [Overflow, ..])

Raise the first U32 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect U32.pow_try(2, 3) == Ok(8)

expect U32.pow_try(U32.highest, 2) == Err(Overflow)
div_by : U32, U32 -> U32

Divide the first U32 by the second, discarding any remainder. Crashes if the second U32 is zero.

expect U32.div_by(10, 2) == 5

expect U32.div_by(11, 2) == 5
div_try : U32, U32 -> Try(U32, [DivByZero, ..])

Divide the first U32 by the second, returning Err(DivByZero) instead of crashing if the divisor is zero.

div_ceil_by : U32, U32 -> U32

Divide the first U32 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in U32.

expect U32.div_ceil_by(7, 2) == 4

expect U32.div_ceil_by(8, 2) == 4
div_ceil_try : U32, U32 -> Try(U32, [DivByZero, ..])

Divide the first U32 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect U32.div_ceil_try(7, 2) == Ok(4)

expect U32.div_ceil_try(1, 0) == Err(DivByZero)
div_trunc_by : U32, U32 -> U32

Divide the first U32 by the second, truncating down (toward zero). For unsigned integers this behaves the same as U32.div_by.

expect U32.div_trunc_by(7, 2) == 3
rem_by : U32, U32 -> U32

Return the remainder of dividing the first U32 by the second.

expect U32.rem_by(7, 3) == 1
mod_by : U32, U32 -> U32

Return the modulus of the first U32 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the divisor. For unsigned integers this behaves the same as U32.rem_by.

expect U32.mod_by(7, 3) == 1
abs_diff : U32, U32 -> U32

Return the absolute difference between two U32 values.

expect U32.abs_diff(2, 5) == 3

expect U32.abs_diff(5, 2) == 3
shift_left_by : U32, U8 -> U32

Shift the bits of a U32 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right. Each left shift by one is equivalent to multiplying by 2 (modulo 4294967296).

expect U32.shift_left_by(1, 3) == 8

expect U32.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : U32, U8 -> U32

Shift the bits of a U32 to the right by the given number of positions. Bits shifted past the least significant bit are discarded, and zeros are shifted in on the left. Each right shift by one is equivalent to integer division by 2. For unsigned integers this behaves the same as U32.shift_right_zf_by.

expect U32.shift_right_by(32, 2) == 8

expect U32.shift_right_by(0b1010_0000, 3) == 0b0001_0100
shift_right_zf_by : U32, U8 -> U32

Shift the bits of a U32 to the right by the given number of positions, filling the vacated high bits with zeros ("zero-fill"). For unsigned integers this behaves the same as U32.shift_right_by.

expect U32.shift_right_zf_by(32, 2) == 8

expect U32.shift_right_zf_by(0b1010_0000, 3) == 0b0001_0100
bitwise_and : U32, U32 -> U32

Returns the bitwise AND of two U32 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect U32.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : U32, U32 -> U32

Returns the bitwise OR of two U32 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect U32.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : U32, U32 -> U32

Returns the bitwise XOR of two U32 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect U32.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : U32 -> U32

Returns the bitwise NOT of a U32 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0.

expect U32.bitwise_not(0) == 4294967295
count_leading_zero_bits : U32 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect U32.count_leading_zero_bits(1) == 31

expect U32.count_leading_zero_bits(0) == 32
count_trailing_zero_bits : U32 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect U32.count_trailing_zero_bits(8) == 3

expect U32.count_trailing_zero_bits(0) == 32
count_one_bits : U32 -> U8

Count the one bits in the value.

expect U32.count_one_bits(0b1011) == 3

expect U32.count_one_bits(0) == 0
to : U32, U32 -> Iter(U32)

Iterator of integers beginning with this U32 and ending with the other U32. (Use U32.until instead to end with the other U32 minus one.) Returns an empty iterator if this U32 is greater than the other.

expect Iter.fold(U32.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(U32.to(3, 3), [], |acc, item| acc.append(item)) == [3]

expect Iter.fold(U32.to(5, 2), [], |acc, item| acc.append(item)) == []
until : U32, U32 -> Iter(U32)

Iterator of integers beginning with this U32 and ending with the other U32 minus one. (Use U32.to instead to end with the other U32 exactly, instead of minus one.) Returns an empty iterator if this U32 is greater than or equal to the other.

expect Iter.fold(U32.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(U32.until(3, 3), [], |acc, item| acc.append(item)) == []

expect Iter.fold(U32.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(U32, [OutOfRange])

Build a U32 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a U32 (0 to 4294967295), or if any element is not a valid digit.

expect U32.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(U32, [InvalidNumeral(Str)])

Convert a numeric literal into a U32. This is the hook the compiler uses when a literal is given type U32; most code should parse user text with U32.from_str instead.

from_str : Str -> Try(U32, [BadNumStr, ..])

Parse a U32 from a Str. Returns Err(BadNumStr) if the string is not a valid non-negative integer, or if the parsed value does not fit in a U32 (0 to 4294967295).

expect U32.from_str("42") == Ok(42)

expect U32.from_str("-1") == Err(BadNumStr)
to_i8_wrap : U32 -> I8

Convert a U32 to an I8, wrapping on overflow. Values from 0 to 127 are preserved; larger values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect U32.to_i8_wrap(42) == 42

expect U32.to_i8_wrap(200) == -56
to_i8_try : U32 -> Try(I8, [OutOfRange, ..])

Convert a U32 to an I8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 127 succeed; larger values return Err(OutOfRange).

expect U32.to_i8_try(42) == Ok(42)

expect U32.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : U32 -> I16

Convert a U32 to an I16, wrapping on overflow. Values from 0 to 32767 are preserved; larger values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect U32.to_i16_wrap(42) == 42

expect U32.to_i16_wrap(40000) == -25536
to_i16_try : U32 -> Try(I16, [OutOfRange, ..])

Convert a U32 to an I16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 32767 succeed; larger values return Err(OutOfRange).

expect U32.to_i16_try(42) == Ok(42)

expect U32.to_i16_try(40000) == Err(OutOfRange)
to_i32_wrap : U32 -> I32

Convert a U32 to an I32, wrapping on overflow. Values from 0 to 2147483647 are preserved; values from 2147483648 to 4294967295 wrap into the negative range -2147483648 to -1 (two's complement reinterpretation of the bits).

expect U32.to_i32_wrap(42) == 42

expect U32.to_i32_wrap(3000000000) == -1294967296
to_i32_try : U32 -> Try(I32, [OutOfRange, ..])

Convert a U32 to an I32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 2147483647 succeed; values from 2147483648 to 4294967295 return Err(OutOfRange).

expect U32.to_i32_try(42) == Ok(42)

expect U32.to_i32_try(3000000000) == Err(OutOfRange)
to_i64 : U32 -> I64

Convert a U32 to an I64. This widening conversion preserves every U32 value exactly.

to_u8_wrap : U32 -> U8

Convert a U32 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; larger values wrap by truncating to the low 8 bits.

expect U32.to_u8_wrap(42) == 42

expect U32.to_u8_wrap(300) == 44
to_u8_try : U32 -> Try(U8, [OutOfRange, ..])

Convert a U32 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; larger values return Err(OutOfRange).

expect U32.to_u8_try(42) == Ok(42)

expect U32.to_u8_try(300) == Err(OutOfRange)
to_u16_wrap : U32 -> U16

Convert a U32 to a U16, wrapping on overflow. Values from 0 to 65535 are preserved; larger values wrap by truncating to the low 16 bits.

expect U32.to_u16_wrap(42) == 42

expect U32.to_u16_wrap(70000) == 4464
to_u16_try : U32 -> Try(U16, [OutOfRange, ..])

Convert a U32 to a U16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 65535 succeed; larger values return Err(OutOfRange).

expect U32.to_u16_try(42) == Ok(42)

expect U32.to_u16_try(70000) == Err(OutOfRange)
to_u64 : U32 -> U64

Convert a U32 to a U64. This widening conversion preserves every U32 value exactly.

to_f32 : U32 -> F32

Convert a U32 to an F32. This conversion may round because F32 has fewer integer precision bits than U32.

encode : U32, fmt -> Try(encoded, err) where { fmt.encode_u32 : fmt, U32 -> Try(encoded, err) }
decode : src, fmt -> (Try(U32, err), src) where { fmt.decode_u32 : fmt, src -> (Try(U32, err), src) }

I32

default : -> I32

Returns the default I32 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect I32.default() == 0
highest : I32

The highest value representable by an I32, which is 2147483647.

expect I32.highest == 2147483647
lowest : I32

The lowest value representable by an I32, which is -2147483648.

expect I32.lowest == -2147483648
to_str : I32 -> Str

Convert an I32 to its decimal string representation.

expect I32.to_str(42) == "42"

expect I32.to_str(-42) == "-42"
is_zero : I32 -> Bool

Returns Bool.True if the value is 0.

expect I32.is_zero(0)

expect !I32.is_zero(7)
is_negative : I32 -> Bool

Returns Bool.True if the value is less than 0.

expect I32.is_negative(-3)

expect !I32.is_negative(0)
is_positive : I32 -> Bool

Returns Bool.True if the value is greater than 0.

expect I32.is_positive(3)

expect !I32.is_positive(0)
is_eq : I32, I32 -> Bool

Returns Bool.True if the two values are equal.

expect I32.is_eq(3, 3)

expect !I32.is_eq(3, 4)
is_gt : I32, I32 -> Bool

Returns Bool.True if the first value is greater than the second.

expect I32.is_gt(5, 3)

expect !I32.is_gt(3, 3)
is_gte : I32, I32 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect I32.is_gte(3, 3)

expect !I32.is_gte(2, 3)
is_lt : I32, I32 -> Bool

Returns Bool.True if the first value is less than the second.

expect I32.is_lt(3, 5)

expect !I32.is_lt(3, 3)
is_lte : I32, I32 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect I32.is_lte(3, 3)

expect !I32.is_lte(5, 3)
compare : I32, I32 -> [LT, EQ, GT]

Compare two I32 values and return their ordering.

expect I32.compare(1, 2) == LT

expect I32.compare(2, 2) == EQ

expect I32.compare(3, 2) == GT
is_even : I32 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect I32.is_even(4)

expect !I32.is_even(5)
is_odd : I32 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect I32.is_odd(5)

expect !I32.is_odd(4)
is_multiple_of : I32, I32 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect I32.is_multiple_of(12, 3)

expect I32.is_multiple_of(0, 0)

expect !I32.is_multiple_of(5, 0)

expect I32.is_multiple_of(I32.lowest, -1)
max : I32, I32 -> I32

Returns the greater of two I32 values.

expect I32.max(5, 3) == 5

expect I32.max(-3, -1) == -1
min : I32, I32 -> I32

Returns the smaller of two I32 values.

expect I32.min(5, 3) == 3

expect I32.min(-3, -1) == -3
negate : I32 -> I32

Negate an I32. Crashes on -2147483648, since 2147483648 does not fit in an I32.

expect I32.negate(3) == -3

expect I32.negate(-3) == 3
abs : I32 -> I32

Return the absolute value of an I32. Crashes on -2147483648, since 2147483648 does not fit in an I32.

expect I32.abs(3) == 3

expect I32.abs(-3) == 3
add_try : I32, I32 -> Try(I32, [Overflow, ..])

Add two I32 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I32.

plus_saturated : I32, I32 -> I32

Add two I32 values, saturating at I32.highest or I32.lowest on overflow rather than wrapping around.

expect I32.plus_saturated(I32.highest, 1) == I32.highest

expect I32.plus_saturated(I32.lowest, -1) == I32.lowest

expect I32.plus_saturated(2, 3) == 5
minus : I32, I32 -> I32

Subtract the second I32 from the first.

expect I32.minus(5, 3) == 2
sub_try : I32, I32 -> Try(I32, [Overflow, ..])

Subtract the second I32 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in an I32.

minus_saturated : I32, I32 -> I32

Subtract the second I32 from the first, saturating at the nearest bound on overflow.

expect I32.minus_saturated(I32.lowest, 1) == I32.lowest

expect I32.minus_saturated(I32.highest, -1) == I32.highest

expect I32.minus_saturated(5, 3) == 2
mul_try : I32, I32 -> Try(I32, [Overflow, ..])

Multiply two I32 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I32.

times_saturated : I32, I32 -> I32

Multiply two I32 values, saturating at the nearest bound on overflow.

expect I32.times_saturated(I32.highest, 2) == I32.highest

expect I32.times_saturated(I32.lowest, 2) == I32.lowest

expect I32.times_saturated(4, 3) == 12
pow : I32, I32 -> I32

Raise the first I32 value to the power of the second. Crashes if the exact result does not fit in I32.

expect I32.pow(2, 3) == 8

expect I32.pow(5, 0) == 1
pow_try : I32, I32 -> Try(I32, [Overflow, Underflow, ..])

Raise the first I32 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect I32.pow_try(2, 3) == Ok(8)

expect I32.pow_try(I32.highest, 2) == Err(Overflow)

expect I32.pow_try(2, -1) == Err(Underflow)

expect I32.pow_try(-1, -3) == Ok(-1)
div_by : I32, I32 -> I32

Divide the first I32 by the second, discarding any remainder. Crashes if the second I32 is zero.

expect I32.div_by(10, 2) == 5

expect I32.div_by(11, 2) == 5
div_try : I32, I32 -> Try(I32, [DivByZero, Overflow, ..])

Divide the first I32 by the second. Returns Err(DivByZero) if the divisor is zero, or Err(Overflow) for I32.lowest / -1.

div_ceil_by : I32, I32 -> I32

Divide the first I32 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in I32.

expect I32.div_ceil_by(7, 2) == 4

expect I32.div_ceil_by(8, 2) == 4

expect I32.div_ceil_by(-7, 2) == -3

expect I32.div_ceil_by(-7, -2) == 4
div_ceil_try : I32, I32 -> Try(I32, [DivByZero, Overflow, ..])

Divide the first I32 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect I32.div_ceil_try(7, 2) == Ok(4)

expect I32.div_ceil_try(1, 0) == Err(DivByZero)

expect I32.div_ceil_try(I32.lowest, -1) == Err(Overflow)
div_trunc_by : I32, I32 -> I32

Divide the first I32 by the second, truncating toward zero.

expect I32.div_trunc_by(7, 2) == 3

expect I32.div_trunc_by(-7, 2) == -3
rem_by : I32, I32 -> I32

Return the remainder of dividing the first I32 by the second. The sign of the result matches the sign of the dividend.

expect I32.rem_by(7, 3) == 1

expect I32.rem_by(-7, 3) == -1
mod_by : I32, I32 -> I32

Return the modulus of the first I32 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the absolute value of the divisor. Unlike I32.rem_by, the sign of the result matches the sign of the divisor.

expect I32.mod_by(7, 3) == 1

expect I32.mod_by(-7, 3) == 2
abs_diff : I32, I32 -> U32

Return the absolute difference between two I32 values as a U32. The result is a U32 because the difference between two I32 values can be as large as 4294967295, which does not fit in an I32.

expect I32.abs_diff(2, 5) == 3

expect I32.abs_diff(-1, 5) == 6
shift_left_by : I32, U8 -> I32

Shift the bits of an I32 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right.

expect I32.shift_left_by(1, 3) == 8

expect I32.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : I32, U8 -> I32

Shift the bits of an I32 to the right by the given number of positions, preserving the sign ("arithmetic shift"). The sign bit is shifted in on the left, so negative values remain negative. Each right shift by one is equivalent to integer division by 2 (rounding toward negative infinity).

expect I32.shift_right_by(32, 2) == 8

expect I32.shift_right_by(-32, 2) == -8
shift_right_zf_by : I32, U8 -> I32

Shift the bits of an I32 to the right by the given number of positions.

expect I32.shift_right_zf_by(32, 2) == 8

expect I32.shift_right_zf_by(0b0101_0000, 3) == 0b0000_1010
bitwise_and : I32, I32 -> I32

Returns the bitwise AND of two I32 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect I32.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : I32, I32 -> I32

Returns the bitwise OR of two I32 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect I32.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : I32, I32 -> I32

Returns the bitwise XOR of two I32 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect I32.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : I32 -> I32

Returns the bitwise NOT of an I32 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0. For signed integers this is equivalent to -value - 1.

expect I32.bitwise_not(5) == -6
count_leading_zero_bits : I32 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect I32.count_leading_zero_bits(-1) == 0

expect I32.count_leading_zero_bits(0) == 32
count_trailing_zero_bits : I32 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect I32.count_trailing_zero_bits(-8) == 3

expect I32.count_trailing_zero_bits(0) == 32
count_one_bits : I32 -> U8

Count the one bits in the value.

expect I32.count_one_bits(-1) == 32

expect I32.count_one_bits(0) == 0
to : I32, I32 -> Iter(I32)

Iterator of integers beginning with this I32 and ending with the other I32. (Use I32.until instead to end with the other I32 minus one.) Returns an empty iterator if this I32 is greater than the other.

expect Iter.fold(I32.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(I32.to(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0, 1]

expect Iter.fold(I32.to(5, 2), [], |acc, item| acc.append(item)) == []
until : I32, I32 -> Iter(I32)

Iterator of integers beginning with this I32 and ending with the other I32 minus one. (Use I32.to instead to end with the other I32 exactly, instead of minus one.) Returns an empty iterator if this I32 is greater than or equal to the other.

expect Iter.fold(I32.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(I32.until(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0]

expect Iter.fold(I32.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(I32, [OutOfRange])

Build an I32 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an I32 (-2147483648 to 2147483647), or if any element is not a valid digit. The result is always non-negative; to build a negative value, I32.negate the result.

expect I32.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(I32, [InvalidNumeral(Str)])

Convert a numeric literal into an I32. This is the hook the compiler uses when a literal is given type I32; most code should parse user text with I32.from_str instead.

from_str : Str -> Try(I32, [BadNumStr, ..])

Parse an I32 from a Str. Returns Err(BadNumStr) if the string is not a valid integer, or if the parsed value does not fit in an I32 (-2147483648 to 2147483647).

expect I32.from_str("42") == Ok(42)

expect I32.from_str("-1") == Ok(-1)

expect I32.from_str("3000000000") == Err(BadNumStr)
to_i8_wrap : I32 -> I8

Convert an I32 to an I8, wrapping on overflow. Values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect I32.to_i8_wrap(42) == 42

expect I32.to_i8_wrap(200) == -56
to_i8_try : I32 -> Try(I8, [OutOfRange, ..])

Convert an I32 to an I8, returning Err(OutOfRange) if the value does not fit. Values from -128 to 127 succeed; other values return Err(OutOfRange).

expect I32.to_i8_try(42) == Ok(42)

expect I32.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : I32 -> I16

Convert an I32 to an I16, wrapping on overflow. Values from -32768 to 32767 are preserved; other values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect I32.to_i16_wrap(42) == 42

expect I32.to_i16_wrap(40000) == -25536
to_i16_try : I32 -> Try(I16, [OutOfRange, ..])

Convert an I32 to an I16, returning Err(OutOfRange) if the value does not fit. Values from -32768 to 32767 succeed; other values return Err(OutOfRange).

expect I32.to_i16_try(42) == Ok(42)

expect I32.to_i16_try(40000) == Err(OutOfRange)
to_i64 : I32 -> I64

Convert an I32 to an I64. This widening conversion preserves every I32 value exactly.

to_u8_wrap : I32 -> U8

Convert an I32 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; other values wrap by truncating to the low 8 bits (two's complement reinterpretation of those bits).

expect I32.to_u8_wrap(42) == 42

expect I32.to_u8_wrap(-1) == 255
to_u8_try : I32 -> Try(U8, [OutOfRange, ..])

Convert an I32 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; other values return Err(OutOfRange).

expect I32.to_u8_try(42) == Ok(42)

expect I32.to_u8_try(-1) == Err(OutOfRange)
to_u16_wrap : I32 -> U16

Convert an I32 to a U16, wrapping on overflow. Values from 0 to 65535 are preserved; other values wrap by truncating to the low 16 bits (two's complement reinterpretation of those bits).

expect I32.to_u16_wrap(42) == 42

expect I32.to_u16_wrap(-1) == 65535
to_u16_try : I32 -> Try(U16, [OutOfRange, ..])

Convert an I32 to a U16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 65535 succeed; other values return Err(OutOfRange).

expect I32.to_u16_try(42) == Ok(42)

expect I32.to_u16_try(-1) == Err(OutOfRange)
to_u32_wrap : I32 -> U32

Convert an I32 to a U32, wrapping on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U32 range (two's complement reinterpretation of the bits).

expect I32.to_u32_wrap(42) == 42

expect I32.to_u32_wrap(-1) == 4294967295
to_u32_try : I32 -> Try(U32, [OutOfRange, ..])

Convert an I32 to a U32, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I32.to_u32_try(42) == Ok(42)

expect I32.to_u32_try(-1) == Err(OutOfRange)
to_u64_wrap : I32 -> U64

Convert an I32 to a U64, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U64 range (two's complement reinterpretation of the sign-extended bits).

expect I32.to_u64_wrap(42) == 42

expect I32.to_u64_wrap(-1) == 18446744073709551615
to_u64_try : I32 -> Try(U64, [OutOfRange, ..])

Convert an I32 to a U64, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I32.to_u64_try(42) == Ok(42)

expect I32.to_u64_try(-1) == Err(OutOfRange)
to_u128_wrap : I32 -> U128

Convert an I32 to a U128, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U128 range (two's complement reinterpretation of the sign-extended bits).

expect I32.to_u128_wrap(42) == 42
to_u128_try : I32 -> Try(U128, [OutOfRange, ..])

Convert an I32 to a U128, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I32.to_u128_try(42) == Ok(42)

expect I32.to_u128_try(-1) == Err(OutOfRange)
to_f32 : I32 -> F32

Convert an I32 to an F32. This conversion may round because F32 has fewer integer precision bits than I32.

encode : I32, fmt -> Try(encoded, err) where { fmt.encode_i32 : fmt, I32 -> Try(encoded, err) }
decode : src, fmt -> (Try(I32, err), src) where { fmt.decode_i32 : fmt, src -> (Try(I32, err), src) }

U64

default : -> U64

Returns the default U64 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect U64.default() == 0
highest : U64

The highest value representable by a U64, which is 18446744073709551615.

expect U64.highest == 18446744073709551615
lowest : U64

The lowest value representable by a U64, which is 0.

expect U64.lowest == 0
to_str : U64 -> Str

Convert a U64 to its decimal string representation.

expect U64.to_str(42) == "42"
is_zero : U64 -> Bool

Returns Bool.True if the value is 0.

expect U64.is_zero(0)

expect !U64.is_zero(7)
is_eq : U64, U64 -> Bool

Returns Bool.True if the two values are equal.

expect U64.is_eq(3, 3)

expect !U64.is_eq(3, 4)
is_gt : U64, U64 -> Bool

Returns Bool.True if the first value is greater than the second.

expect U64.is_gt(5, 3)

expect !U64.is_gt(3, 3)
is_gte : U64, U64 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect U64.is_gte(3, 3)

expect !U64.is_gte(2, 3)
is_lt : U64, U64 -> Bool

Returns Bool.True if the first value is less than the second.

expect U64.is_lt(3, 5)

expect !U64.is_lt(3, 3)
is_lte : U64, U64 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect U64.is_lte(3, 3)

expect !U64.is_lte(5, 3)
compare : U64, U64 -> [LT, EQ, GT]

Compare two U64 values and return their ordering.

expect U64.compare(1, 2) == LT

expect U64.compare(2, 2) == EQ

expect U64.compare(3, 2) == GT
is_even : U64 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect U64.is_even(4)

expect !U64.is_even(5)
is_odd : U64 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect U64.is_odd(5)

expect !U64.is_odd(4)
is_multiple_of : U64, U64 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect U64.is_multiple_of(12, 3)

expect U64.is_multiple_of(0, 0)

expect !U64.is_multiple_of(5, 0)
max : U64, U64 -> U64

Returns the greater of two U64 values.

expect U64.max(5, 3) == 5
min : U64, U64 -> U64

Returns the smaller of two U64 values.

expect U64.min(5, 3) == 3
add_try : U64, U64 -> Try(U64, [Overflow, ..])

Add two U64 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U64.

plus_saturated : U64, U64 -> U64

Add two U64 values, saturating at U64.highest on overflow rather than wrapping around.

expect U64.plus_saturated(U64.highest, 1) == U64.highest

expect U64.plus_saturated(2, 3) == 5
minus : U64, U64 -> U64

Subtract the second U64 from the first.

expect U64.minus(5, 3) == 2
sub_try : U64, U64 -> Try(U64, [Overflow, ..])

Subtract the second U64 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in a U64.

minus_saturated : U64, U64 -> U64

Subtract the second U64 from the first, saturating at the nearest bound on overflow.

expect U64.minus_saturated(0, 1) == 0

expect U64.minus_saturated(5, 3) == 2
mul_try : U64, U64 -> Try(U64, [Overflow, ..])

Multiply two U64 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U64.

times_saturated : U64, U64 -> U64

Multiply two U64 values, saturating at the nearest bound on overflow.

expect U64.times_saturated(U64.highest, 2) == U64.highest

expect U64.times_saturated(4, 3) == 12
pow : U64, U64 -> U64

Raise the first U64 value to the power of the second. Crashes if the exact result does not fit in U64.

expect U64.pow(2, 3) == 8

expect U64.pow(5, 0) == 1
pow_try : U64, U64 -> Try(U64, [Overflow, ..])

Raise the first U64 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect U64.pow_try(2, 3) == Ok(8)

expect U64.pow_try(U64.highest, 2) == Err(Overflow)
div_by : U64, U64 -> U64

Divide the first U64 by the second, discarding any remainder. Crashes if the second U64 is zero.

expect U64.div_by(10, 2) == 5

expect U64.div_by(11, 2) == 5
div_try : U64, U64 -> Try(U64, [DivByZero, ..])

Divide the first U64 by the second, returning Err(DivByZero) instead of crashing if the divisor is zero.

div_ceil_by : U64, U64 -> U64

Divide the first U64 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in U64.

expect U64.div_ceil_by(7, 2) == 4

expect U64.div_ceil_by(8, 2) == 4
div_ceil_try : U64, U64 -> Try(U64, [DivByZero, ..])

Divide the first U64 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect U64.div_ceil_try(7, 2) == Ok(4)

expect U64.div_ceil_try(1, 0) == Err(DivByZero)
div_trunc_by : U64, U64 -> U64

Divide the first U64 by the second, truncating down (toward zero). For unsigned integers this behaves the same as U64.div_by.

expect U64.div_trunc_by(7, 2) == 3
rem_by : U64, U64 -> U64

Return the remainder of dividing the first U64 by the second.

expect U64.rem_by(7, 3) == 1
mod_by : U64, U64 -> U64

Return the modulus of the first U64 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the divisor. For unsigned integers this behaves the same as U64.rem_by.

expect U64.mod_by(7, 3) == 1
abs_diff : U64, U64 -> U64

Return the absolute difference between two U64 values.

expect U64.abs_diff(2, 5) == 3

expect U64.abs_diff(5, 2) == 3
shift_left_by : U64, U8 -> U64

Shift the bits of a U64 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right. Each left shift by one is equivalent to multiplying by 2 (modulo 2^64).

expect U64.shift_left_by(1, 3) == 8

expect U64.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : U64, U8 -> U64

Shift the bits of a U64 to the right by the given number of positions. Bits shifted past the least significant bit are discarded, and zeros are shifted in on the left. Each right shift by one is equivalent to integer division by 2. For unsigned integers this behaves the same as U64.shift_right_zf_by.

expect U64.shift_right_by(32, 2) == 8

expect U64.shift_right_by(0b1010_0000, 3) == 0b0001_0100
shift_right_zf_by : U64, U8 -> U64

Shift the bits of a U64 to the right by the given number of positions, filling the vacated high bits with zeros ("zero-fill"). For unsigned integers this behaves the same as U64.shift_right_by.

expect U64.shift_right_zf_by(32, 2) == 8

expect U64.shift_right_zf_by(0b1010_0000, 3) == 0b0001_0100
bitwise_and : U64, U64 -> U64

Returns the bitwise AND of two U64 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect U64.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : U64, U64 -> U64

Returns the bitwise OR of two U64 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect U64.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : U64, U64 -> U64

Returns the bitwise XOR of two U64 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect U64.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : U64 -> U64

Returns the bitwise NOT of a U64 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0.

expect U64.bitwise_not(0) == 18446744073709551615
count_leading_zero_bits : U64 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect U64.count_leading_zero_bits(1) == 63

expect U64.count_leading_zero_bits(0) == 64
count_trailing_zero_bits : U64 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect U64.count_trailing_zero_bits(8) == 3

expect U64.count_trailing_zero_bits(0) == 64
count_one_bits : U64 -> U8

Count the one bits in the value.

expect U64.count_one_bits(0b1011) == 3

expect U64.count_one_bits(0) == 0
to : U64, U64 -> Iter(U64)

Iterator of integers beginning with this U64 and ending with the other U64. (Use U64.until instead to end with the other U64 minus one.) Returns an empty iterator if this U64 is greater than the other.

expect Iter.fold(U64.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(U64.to(3, 3), [], |acc, item| acc.append(item)) == [3]

expect Iter.fold(U64.to(5, 2), [], |acc, item| acc.append(item)) == []
until : U64, U64 -> Iter(U64)

Iterator of integers beginning with this U64 and ending with the other U64 minus one. (Use U64.to instead to end with the other U64 exactly, instead of minus one.) Returns an empty iterator if this U64 is greater than or equal to the other.

expect Iter.fold(U64.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(U64.until(3, 3), [], |acc, item| acc.append(item)) == []

expect Iter.fold(U64.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(U64, [OutOfRange])

Build a U64 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a U64 (0 to 18446744073709551615), or if any element is not a valid digit.

expect U64.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(U64, [InvalidNumeral(Str)])

Convert a numeric literal into a U64. This is the hook the compiler uses when a literal is given type U64; most code should parse user text with U64.from_str instead.

from_str : Str -> Try(U64, [BadNumStr, ..])

Parse a U64 from a Str. Returns Err(BadNumStr) if the string is not a valid non-negative integer, or if the parsed value does not fit in a U64 (0 to 18446744073709551615).

expect U64.from_str("42") == Ok(42)

expect U64.from_str("-1") == Err(BadNumStr)
to_i8_wrap : U64 -> I8

Convert a U64 to an I8, wrapping on overflow. Values from 0 to 127 are preserved; larger values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect U64.to_i8_wrap(42) == 42

expect U64.to_i8_wrap(200) == -56
to_i8_try : U64 -> Try(I8, [OutOfRange, ..])

Convert a U64 to an I8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 127 succeed; larger values return Err(OutOfRange).

expect U64.to_i8_try(42) == Ok(42)

expect U64.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : U64 -> I16

Convert a U64 to an I16, wrapping on overflow. Values from 0 to 32767 are preserved; larger values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect U64.to_i16_wrap(42) == 42

expect U64.to_i16_wrap(40000) == -25536
to_i16_try : U64 -> Try(I16, [OutOfRange, ..])

Convert a U64 to an I16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 32767 succeed; larger values return Err(OutOfRange).

expect U64.to_i16_try(42) == Ok(42)

expect U64.to_i16_try(40000) == Err(OutOfRange)
to_i32_wrap : U64 -> I32

Convert a U64 to an I32, wrapping on overflow. Values from 0 to 2147483647 are preserved; larger values wrap by truncating to the low 32 bits and reinterpreting them in two's complement.

expect U64.to_i32_wrap(42) == 42

expect U64.to_i32_wrap(3000000000) == -1294967296
to_i32_try : U64 -> Try(I32, [OutOfRange, ..])

Convert a U64 to an I32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 2147483647 succeed; larger values return Err(OutOfRange).

expect U64.to_i32_try(42) == Ok(42)

expect U64.to_i32_try(3000000000) == Err(OutOfRange)
to_i64_wrap : U64 -> I64

Convert a U64 to an I64, wrapping on overflow. Values from 0 to 9223372036854775807 are preserved; values from 9223372036854775808 to 18446744073709551615 wrap into the negative range -9223372036854775808 to -1 (two's complement reinterpretation of the bits).

expect U64.to_i64_wrap(42) == 42

expect U64.to_i64_wrap(10000000000000000000) == -8446744073709551616
to_i64_try : U64 -> Try(I64, [OutOfRange, ..])

Convert a U64 to an I64, returning Err(OutOfRange) if the value does not fit. Values from 0 to 9223372036854775807 succeed; larger values return Err(OutOfRange).

expect U64.to_i64_try(42) == Ok(42)

expect U64.to_i64_try(10000000000000000000) == Err(OutOfRange)
to_u8_wrap : U64 -> U8

Convert a U64 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; larger values wrap by truncating to the low 8 bits.

expect U64.to_u8_wrap(42) == 42

expect U64.to_u8_wrap(300) == 44
to_u8_try : U64 -> Try(U8, [OutOfRange, ..])

Convert a U64 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; larger values return Err(OutOfRange).

expect U64.to_u8_try(42) == Ok(42)

expect U64.to_u8_try(300) == Err(OutOfRange)
to_u16_wrap : U64 -> U16

Convert a U64 to a U16, wrapping on overflow. Values from 0 to 65535 are preserved; larger values wrap by truncating to the low 16 bits.

expect U64.to_u16_wrap(42) == 42

expect U64.to_u16_wrap(70000) == 4464
to_u16_try : U64 -> Try(U16, [OutOfRange, ..])

Convert a U64 to a U16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 65535 succeed; larger values return Err(OutOfRange).

expect U64.to_u16_try(42) == Ok(42)

expect U64.to_u16_try(70000) == Err(OutOfRange)
to_u32_wrap : U64 -> U32

Convert a U64 to a U32, wrapping on overflow. Values from 0 to 4294967295 are preserved; larger values wrap by truncating to the low 32 bits.

expect U64.to_u32_wrap(42) == 42

expect U64.to_u32_wrap(5000000000) == 705032704
to_u32_try : U64 -> Try(U32, [OutOfRange, ..])

Convert a U64 to a U32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 4294967295 succeed; larger values return Err(OutOfRange).

expect U64.to_u32_try(42) == Ok(42)

expect U64.to_u32_try(5000000000) == Err(OutOfRange)
to_f32 : U64 -> F32

Convert a U64 to an F32. This conversion may round because F32 has fewer integer precision bits than U64.

to_f64 : U64 -> F64

Convert a U64 to an F64. This conversion may round because F64 has fewer integer precision bits than U64.

encode : U64, fmt -> Try(encoded, err) where { fmt.encode_u64 : fmt, U64 -> Try(encoded, err) }
decode : src, fmt -> (Try(U64, err), src) where { fmt.decode_u64 : fmt, src -> (Try(U64, err), src) }

I64

default : -> I64

Returns the default I64 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect I64.default() == 0
highest : I64

The highest value representable by an I64, which is 9223372036854775807.

expect I64.highest == 9223372036854775807
lowest : I64

The lowest value representable by an I64, which is -9223372036854775808.

expect I64.lowest == -9223372036854775808
to_str : I64 -> Str

Convert an I64 to its decimal string representation.

expect I64.to_str(42) == "42"

expect I64.to_str(-42) == "-42"
is_zero : I64 -> Bool

Returns Bool.True if the value is 0.

expect I64.is_zero(0)

expect !I64.is_zero(7)
is_negative : I64 -> Bool

Returns Bool.True if the value is less than 0.

expect I64.is_negative(-3)

expect !I64.is_negative(0)
is_positive : I64 -> Bool

Returns Bool.True if the value is greater than 0.

expect I64.is_positive(3)

expect !I64.is_positive(0)
is_eq : I64, I64 -> Bool

Returns Bool.True if the two values are equal.

expect I64.is_eq(3, 3)

expect !I64.is_eq(3, 4)
is_gt : I64, I64 -> Bool

Returns Bool.True if the first value is greater than the second.

expect I64.is_gt(5, 3)

expect !I64.is_gt(3, 3)
is_gte : I64, I64 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect I64.is_gte(3, 3)

expect !I64.is_gte(2, 3)
is_lt : I64, I64 -> Bool

Returns Bool.True if the first value is less than the second.

expect I64.is_lt(3, 5)

expect !I64.is_lt(3, 3)
is_lte : I64, I64 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect I64.is_lte(3, 3)

expect !I64.is_lte(5, 3)
compare : I64, I64 -> [LT, EQ, GT]

Compare two I64 values and return their ordering.

expect I64.compare(1, 2) == LT

expect I64.compare(2, 2) == EQ

expect I64.compare(3, 2) == GT
is_even : I64 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect I64.is_even(4)

expect !I64.is_even(5)
is_odd : I64 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect I64.is_odd(5)

expect !I64.is_odd(4)
is_multiple_of : I64, I64 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect I64.is_multiple_of(12, 3)

expect I64.is_multiple_of(0, 0)

expect !I64.is_multiple_of(5, 0)

expect I64.is_multiple_of(I64.lowest, -1)
max : I64, I64 -> I64

Returns the greater of two I64 values.

expect I64.max(5, 3) == 5

expect I64.max(-3, -1) == -1
min : I64, I64 -> I64

Returns the smaller of two I64 values.

expect I64.min(5, 3) == 3

expect I64.min(-3, -1) == -3
negate : I64 -> I64

Negate an I64. Crashes on -9223372036854775808, since 9223372036854775808 does not fit in an I64.

expect I64.negate(3) == -3

expect I64.negate(-3) == 3
abs : I64 -> I64

Return the absolute value of an I64. Crashes on -9223372036854775808, since 9223372036854775808 does not fit in an I64.

expect I64.abs(3) == 3

expect I64.abs(-3) == 3
add_try : I64, I64 -> Try(I64, [Overflow, ..])

Add two I64 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I64.

plus_saturated : I64, I64 -> I64

Add two I64 values, saturating at I64.highest or I64.lowest on overflow rather than wrapping around.

expect I64.plus_saturated(I64.highest, 1) == I64.highest

expect I64.plus_saturated(I64.lowest, -1) == I64.lowest

expect I64.plus_saturated(2, 3) == 5
minus : I64, I64 -> I64

Subtract the second I64 from the first.

expect I64.minus(5, 3) == 2
sub_try : I64, I64 -> Try(I64, [Overflow, ..])

Subtract the second I64 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in an I64.

minus_saturated : I64, I64 -> I64

Subtract the second I64 from the first, saturating at the nearest bound on overflow.

expect I64.minus_saturated(I64.lowest, 1) == I64.lowest

expect I64.minus_saturated(I64.highest, -1) == I64.highest

expect I64.minus_saturated(5, 3) == 2
mul_try : I64, I64 -> Try(I64, [Overflow, ..])

Multiply two I64 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I64.

times_saturated : I64, I64 -> I64

Multiply two I64 values, saturating at the nearest bound on overflow.

expect I64.times_saturated(I64.highest, 2) == I64.highest

expect I64.times_saturated(I64.lowest, 2) == I64.lowest

expect I64.times_saturated(4, 3) == 12
pow : I64, I64 -> I64

Raise the first I64 value to the power of the second. Crashes if the exact result does not fit in I64.

expect I64.pow(2, 3) == 8

expect I64.pow(5, 0) == 1
pow_try : I64, I64 -> Try(I64, [Overflow, Underflow, ..])

Raise the first I64 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect I64.pow_try(2, 3) == Ok(8)

expect I64.pow_try(I64.highest, 2) == Err(Overflow)

expect I64.pow_try(2, -1) == Err(Underflow)

expect I64.pow_try(-1, -3) == Ok(-1)
div_by : I64, I64 -> I64

Divide the first I64 by the second, discarding any remainder. Crashes if the second I64 is zero.

expect I64.div_by(10, 2) == 5

expect I64.div_by(11, 2) == 5
div_try : I64, I64 -> Try(I64, [DivByZero, Overflow, ..])

Divide the first I64 by the second. Returns Err(DivByZero) if the divisor is zero, or Err(Overflow) for I64.lowest / -1.

div_ceil_by : I64, I64 -> I64

Divide the first I64 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in I64.

expect I64.div_ceil_by(7, 2) == 4

expect I64.div_ceil_by(8, 2) == 4

expect I64.div_ceil_by(-7, 2) == -3

expect I64.div_ceil_by(-7, -2) == 4
div_ceil_try : I64, I64 -> Try(I64, [DivByZero, Overflow, ..])

Divide the first I64 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect I64.div_ceil_try(7, 2) == Ok(4)

expect I64.div_ceil_try(1, 0) == Err(DivByZero)

expect I64.div_ceil_try(I64.lowest, -1) == Err(Overflow)
div_trunc_by : I64, I64 -> I64

Divide the first I64 by the second, truncating toward zero.

expect I64.div_trunc_by(7, 2) == 3

expect I64.div_trunc_by(-7, 2) == -3
rem_by : I64, I64 -> I64

Return the remainder of dividing the first I64 by the second. The sign of the result matches the sign of the dividend.

expect I64.rem_by(7, 3) == 1

expect I64.rem_by(-7, 3) == -1
mod_by : I64, I64 -> I64

Return the modulus of the first I64 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the absolute value of the divisor. Unlike I64.rem_by, the sign of the result matches the sign of the divisor.

expect I64.mod_by(7, 3) == 1

expect I64.mod_by(-7, 3) == 2
abs_diff : I64, I64 -> U64

Return the absolute difference between two I64 values as a U64. The result is a U64 because the difference between two I64 values can be as large as 18446744073709551615, which does not fit in an I64.

expect I64.abs_diff(2, 5) == 3

expect I64.abs_diff(-1, 5) == 6
shift_left_by : I64, U8 -> I64

Shift the bits of an I64 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right.

expect I64.shift_left_by(1, 3) == 8

expect I64.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : I64, U8 -> I64

Shift the bits of an I64 to the right by the given number of positions, preserving the sign ("arithmetic shift"). The sign bit is shifted in on the left, so negative values remain negative. Each right shift by one is equivalent to integer division by 2 (rounding toward negative infinity).

expect I64.shift_right_by(32, 2) == 8

expect I64.shift_right_by(-32, 2) == -8
shift_right_zf_by : I64, U8 -> I64

Shift the bits of an I64 to the right by the given number of positions.

expect I64.shift_right_zf_by(32, 2) == 8

expect I64.shift_right_zf_by(0b0101_0000, 3) == 0b0000_1010
bitwise_and : I64, I64 -> I64

Returns the bitwise AND of two I64 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect I64.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : I64, I64 -> I64

Returns the bitwise OR of two I64 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect I64.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : I64, I64 -> I64

Returns the bitwise XOR of two I64 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect I64.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : I64 -> I64

Returns the bitwise NOT of an I64 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0. For signed integers this is equivalent to -value - 1.

expect I64.bitwise_not(5) == -6
count_leading_zero_bits : I64 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect I64.count_leading_zero_bits(-1) == 0

expect I64.count_leading_zero_bits(0) == 64
count_trailing_zero_bits : I64 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect I64.count_trailing_zero_bits(-8) == 3

expect I64.count_trailing_zero_bits(0) == 64
count_one_bits : I64 -> U8

Count the one bits in the value.

expect I64.count_one_bits(-1) == 64

expect I64.count_one_bits(0) == 0
to : I64, I64 -> Iter(I64)

Iterator of integers beginning with this I64 and ending with the other I64. (Use I64.until instead to end with the other I64 minus one.) Returns an empty iterator if this I64 is greater than the other.

expect Iter.fold(I64.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(I64.to(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0, 1]

expect Iter.fold(I64.to(5, 2), [], |acc, item| acc.append(item)) == []
until : I64, I64 -> Iter(I64)

Iterator of integers beginning with this I64 and ending with the other I64 minus one. (Use I64.to instead to end with the other I64 exactly, instead of minus one.) Returns an empty iterator if this I64 is greater than or equal to the other.

expect Iter.fold(I64.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(I64.until(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0]

expect Iter.fold(I64.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(I64, [OutOfRange])

Build an I64 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an I64 (-9223372036854775808 to 9223372036854775807), or if any element is not a valid digit. The result is always non-negative; to build a negative value, I64.negate the result.

expect I64.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(I64, [InvalidNumeral(Str)])

Convert a numeric literal into an I64. This is the hook the compiler uses when a literal is given type I64; most code should parse user text with I64.from_str instead.

from_str : Str -> Try(I64, [BadNumStr, ..])

Parse an I64 from a Str. Returns Err(BadNumStr) if the string is not a valid integer, or if the parsed value does not fit in an I64 (-9223372036854775808 to 9223372036854775807).

expect I64.from_str("42") == Ok(42)

expect I64.from_str("-1") == Ok(-1)
to_i8_wrap : I64 -> I8

Convert an I64 to an I8, wrapping on overflow. Values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect I64.to_i8_wrap(42) == 42

expect I64.to_i8_wrap(200) == -56
to_i8_try : I64 -> Try(I8, [OutOfRange, ..])

Convert an I64 to an I8, returning Err(OutOfRange) if the value does not fit. Values from -128 to 127 succeed; other values return Err(OutOfRange).

expect I64.to_i8_try(42) == Ok(42)

expect I64.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : I64 -> I16

Convert an I64 to an I16, wrapping on overflow. Values from -32768 to 32767 are preserved; other values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect I64.to_i16_wrap(42) == 42

expect I64.to_i16_wrap(40000) == -25536
to_i16_try : I64 -> Try(I16, [OutOfRange, ..])

Convert an I64 to an I16, returning Err(OutOfRange) if the value does not fit. Values from -32768 to 32767 succeed; other values return Err(OutOfRange).

expect I64.to_i16_try(42) == Ok(42)

expect I64.to_i16_try(40000) == Err(OutOfRange)
to_i32_wrap : I64 -> I32

Convert an I64 to an I32, wrapping on overflow. Values from -2147483648 to 2147483647 are preserved; other values wrap by truncating to the low 32 bits and reinterpreting them in two's complement.

expect I64.to_i32_wrap(42) == 42

expect I64.to_i32_wrap(3000000000) == -1294967296
to_i32_try : I64 -> Try(I32, [OutOfRange, ..])

Convert an I64 to an I32, returning Err(OutOfRange) if the value does not fit. Values from -2147483648 to 2147483647 succeed; other values return Err(OutOfRange).

expect I64.to_i32_try(42) == Ok(42)

expect I64.to_i32_try(3000000000) == Err(OutOfRange)
to_u8_wrap : I64 -> U8

Convert an I64 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; other values wrap by truncating to the low 8 bits (two's complement reinterpretation of those bits).

expect I64.to_u8_wrap(42) == 42

expect I64.to_u8_wrap(-1) == 255
to_u8_try : I64 -> Try(U8, [OutOfRange, ..])

Convert an I64 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; other values return Err(OutOfRange).

expect I64.to_u8_try(42) == Ok(42)

expect I64.to_u8_try(-1) == Err(OutOfRange)
to_u16_wrap : I64 -> U16

Convert an I64 to a U16, wrapping on overflow. Values from 0 to 65535 are preserved; other values wrap by truncating to the low 16 bits (two's complement reinterpretation of those bits).

expect I64.to_u16_wrap(42) == 42

expect I64.to_u16_wrap(-1) == 65535
to_u16_try : I64 -> Try(U16, [OutOfRange, ..])

Convert an I64 to a U16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 65535 succeed; other values return Err(OutOfRange).

expect I64.to_u16_try(42) == Ok(42)

expect I64.to_u16_try(-1) == Err(OutOfRange)
to_u32_wrap : I64 -> U32

Convert an I64 to a U32, wrapping on overflow. Values from 0 to 4294967295 are preserved; other values wrap by truncating to the low 32 bits (two's complement reinterpretation of those bits).

expect I64.to_u32_wrap(42) == 42

expect I64.to_u32_wrap(-1) == 4294967295
to_u32_try : I64 -> Try(U32, [OutOfRange, ..])

Convert an I64 to a U32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 4294967295 succeed; other values return Err(OutOfRange).

expect I64.to_u32_try(42) == Ok(42)

expect I64.to_u32_try(-1) == Err(OutOfRange)
to_u64_wrap : I64 -> U64

Convert an I64 to a U64, wrapping on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U64 range (two's complement reinterpretation of the bits).

expect I64.to_u64_wrap(42) == 42

expect I64.to_u64_wrap(-1) == 18446744073709551615
to_u64_try : I64 -> Try(U64, [OutOfRange, ..])

Convert an I64 to a U64, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I64.to_u64_try(42) == Ok(42)

expect I64.to_u64_try(-1) == Err(OutOfRange)
to_u128_wrap : I64 -> U128

Convert an I64 to a U128, sign-extending the bits on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U128 range (two's complement reinterpretation of the sign-extended bits).

expect I64.to_u128_wrap(42) == 42
to_u128_try : I64 -> Try(U128, [OutOfRange, ..])

Convert an I64 to a U128, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I64.to_u128_try(42) == Ok(42)

expect I64.to_u128_try(-1) == Err(OutOfRange)
to_f32 : I64 -> F32

Convert an I64 to an F32. This conversion may round because F32 has fewer integer precision bits than I64.

to_f64 : I64 -> F64

Convert an I64 to an F64. This conversion may round because F64 has fewer integer precision bits than I64.

encode : I64, fmt -> Try(encoded, err) where { fmt.encode_i64 : fmt, I64 -> Try(encoded, err) }
decode : src, fmt -> (Try(I64, err), src) where { fmt.decode_i64 : fmt, src -> (Try(I64, err), src) }

U128

default : -> U128

Returns the default U128 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect U128.default() == 0
highest : U128

The highest value representable by a U128, which is 340282366920938463463374607431768211455.

expect U128.highest == 340282366920938463463374607431768211455
lowest : U128

The lowest value representable by a U128, which is 0.

expect U128.lowest == 0
to_str : U128 -> Str

Convert a U128 to its decimal string representation.

expect U128.to_str(42) == "42"
is_zero : U128 -> Bool

Returns Bool.True if the value is 0.

expect U128.is_zero(0)

expect !U128.is_zero(7)
is_eq : U128, U128 -> Bool

Returns Bool.True if the two values are equal.

expect U128.is_eq(3, 3)

expect !U128.is_eq(3, 4)
is_gt : U128, U128 -> Bool

Returns Bool.True if the first value is greater than the second.

expect U128.is_gt(5, 3)

expect !U128.is_gt(3, 3)
is_gte : U128, U128 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect U128.is_gte(3, 3)

expect !U128.is_gte(2, 3)
is_lt : U128, U128 -> Bool

Returns Bool.True if the first value is less than the second.

expect U128.is_lt(3, 5)

expect !U128.is_lt(3, 3)
is_lte : U128, U128 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect U128.is_lte(3, 3)

expect !U128.is_lte(5, 3)
compare : U128, U128 -> [LT, EQ, GT]

Compare two U128 values and return their ordering.

expect U128.compare(1, 2) == LT

expect U128.compare(2, 2) == EQ

expect U128.compare(3, 2) == GT
is_even : U128 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect U128.is_even(4)

expect !U128.is_even(5)
is_odd : U128 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect U128.is_odd(5)

expect !U128.is_odd(4)
is_multiple_of : U128, U128 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect U128.is_multiple_of(12, 3)

expect U128.is_multiple_of(0, 0)

expect !U128.is_multiple_of(5, 0)
add_try : U128, U128 -> Try(U128, [Overflow, ..])

Add two U128 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U128.

plus_saturated : U128, U128 -> U128

Add two U128 values, saturating at U128.highest on overflow rather than wrapping around.

expect U128.plus_saturated(U128.highest, 1) == U128.highest

expect U128.plus_saturated(2, 3) == 5
sub_try : U128, U128 -> Try(U128, [Overflow, ..])

Subtract the second U128 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in a U128.

minus_saturated : U128, U128 -> U128

Subtract the second U128 from the first, saturating at the nearest bound on overflow.

expect U128.minus_saturated(0, 1) == 0

expect U128.minus_saturated(5, 3) == 2
mul_try : U128, U128 -> Try(U128, [Overflow, ..])

Multiply two U128 values, returning Err(Overflow) instead of wrapping if the result does not fit in a U128.

times_saturated : U128, U128 -> U128

Multiply two U128 values, saturating at the nearest bound on overflow.

expect U128.times_saturated(U128.highest, 2) == U128.highest

expect U128.times_saturated(4, 3) == 12
pow : U128, U128 -> U128

Raise the first U128 value to the power of the second. Crashes if the exact result does not fit in U128.

expect U128.pow(2, 3) == 8

expect U128.pow(5, 0) == 1
pow_try : U128, U128 -> Try(U128, [Overflow, ..])

Raise the first U128 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect U128.pow_try(2, 3) == Ok(8)

expect U128.pow_try(U128.highest, 2) == Err(Overflow)
div_by : U128, U128 -> U128

Divide the first U128 by the second, discarding any remainder. Crashes if the second U128 is zero.

expect U128.div_by(10, 2) == 5

expect U128.div_by(11, 2) == 5
div_try : U128, U128 -> Try(U128, [DivByZero, ..])

Divide the first U128 by the second, returning Err(DivByZero) instead of crashing if the divisor is zero.

div_ceil_by : U128, U128 -> U128

Divide the first U128 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in U128.

expect U128.div_ceil_by(7, 2) == 4

expect U128.div_ceil_by(8, 2) == 4
div_ceil_try : U128, U128 -> Try(U128, [DivByZero, ..])

Divide the first U128 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect U128.div_ceil_try(7, 2) == Ok(4)

expect U128.div_ceil_try(1, 0) == Err(DivByZero)
div_trunc_by : U128, U128 -> U128

Divide the first U128 by the second, truncating down (toward zero). For unsigned integers this behaves the same as U128.div_by.

expect U128.div_trunc_by(7, 2) == 3
rem_by : U128, U128 -> U128

Return the remainder of dividing the first U128 by the second.

expect U128.rem_by(7, 3) == 1
mod_by : U128, U128 -> U128

Return the modulus of the first U128 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the divisor. For unsigned integers this behaves the same as U128.rem_by.

expect U128.mod_by(7, 3) == 1
abs_diff : U128, U128 -> U128

Return the absolute difference between two U128 values.

expect U128.abs_diff(2, 5) == 3

expect U128.abs_diff(5, 2) == 3
shift_left_by : U128, U8 -> U128

Shift the bits of a U128 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right. Each left shift by one is equivalent to multiplying by 2 (modulo 2^128).

expect U128.shift_left_by(1, 3) == 8

expect U128.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : U128, U8 -> U128

Shift the bits of a U128 to the right by the given number of positions. Bits shifted past the least significant bit are discarded, and zeros are shifted in on the left. Each right shift by one is equivalent to integer division by 2. For unsigned integers this behaves the same as U128.shift_right_zf_by.

expect U128.shift_right_by(32, 2) == 8

expect U128.shift_right_by(0b1010_0000, 3) == 0b0001_0100
shift_right_zf_by : U128, U8 -> U128

Shift the bits of a U128 to the right by the given number of positions, filling the vacated high bits with zeros ("zero-fill"). For unsigned integers this behaves the same as U128.shift_right_by.

expect U128.shift_right_zf_by(32, 2) == 8

expect U128.shift_right_zf_by(0b1010_0000, 3) == 0b0001_0100
bitwise_and : U128, U128 -> U128

Returns the bitwise AND of two U128 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect U128.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : U128, U128 -> U128

Returns the bitwise OR of two U128 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect U128.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : U128, U128 -> U128

Returns the bitwise XOR of two U128 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect U128.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : U128 -> U128

Returns the bitwise NOT of a U128 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0.

expect U128.bitwise_not(0) == 340282366920938463463374607431768211455
count_leading_zero_bits : U128 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect U128.count_leading_zero_bits(1) == 127

expect U128.count_leading_zero_bits(0) == 128
count_trailing_zero_bits : U128 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect U128.count_trailing_zero_bits(8) == 3

expect U128.count_trailing_zero_bits(0) == 128
count_one_bits : U128 -> U8

Count the one bits in the value.

expect U128.count_one_bits(0b1011) == 3

expect U128.count_one_bits(0) == 0
to : U128, U128 -> Iter(U128)

Iterator of integers beginning with this U128 and ending with the other U128. (Use U128.until instead to end with the other U128 minus one.) Returns an empty iterator if this U128 is greater than the other.

expect Iter.fold(U128.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(U128.to(3, 3), [], |acc, item| acc.append(item)) == [3]

expect Iter.fold(U128.to(5, 2), [], |acc, item| acc.append(item)) == []
until : U128, U128 -> Iter(U128)

Iterator of integers beginning with this U128 and ending with the other U128 minus one. (Use U128.to instead to end with the other U128 exactly, instead of minus one.) Returns an empty iterator if this U128 is greater than or equal to the other.

expect Iter.fold(U128.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(U128.until(3, 3), [], |acc, item| acc.append(item)) == []

expect Iter.fold(U128.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(U128, [OutOfRange])

Build a U128 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a U128 (0 to 340282366920938463463374607431768211455), or if any element is not a valid digit.

expect U128.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(U128, [InvalidNumeral(Str)])

Convert a numeric literal into a U128. This is the hook the compiler uses when a literal is given type U128; most code should parse user text with U128.from_str instead.

from_str : Str -> Try(U128, [BadNumStr, ..])

Parse a U128 from a Str. Returns Err(BadNumStr) if the string is not a valid non-negative integer, or if the parsed value does not fit in a U128 (0 to 340282366920938463463374607431768211455).

expect U128.from_str("42") == Ok(42)

expect U128.from_str("-1") == Err(BadNumStr)
to_i8_wrap : U128 -> I8

Convert a U128 to an I8, wrapping on overflow. Values from 0 to 127 are preserved; larger values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect U128.to_i8_wrap(42) == 42

expect U128.to_i8_wrap(200) == -56
to_i8_try : U128 -> Try(I8, [OutOfRange, ..])

Convert a U128 to an I8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 127 succeed; larger values return Err(OutOfRange).

expect U128.to_i8_try(42) == Ok(42)

expect U128.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : U128 -> I16

Convert a U128 to an I16, wrapping on overflow. Values from 0 to 32767 are preserved; larger values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect U128.to_i16_wrap(42) == 42

expect U128.to_i16_wrap(40000) == -25536
to_i16_try : U128 -> Try(I16, [OutOfRange, ..])

Convert a U128 to an I16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 32767 succeed; larger values return Err(OutOfRange).

expect U128.to_i16_try(42) == Ok(42)

expect U128.to_i16_try(40000) == Err(OutOfRange)
to_i32_wrap : U128 -> I32

Convert a U128 to an I32, wrapping on overflow. Values from 0 to 2147483647 are preserved; larger values wrap by truncating to the low 32 bits and reinterpreting them in two's complement.

expect U128.to_i32_wrap(42) == 42

expect U128.to_i32_wrap(3000000000) == -1294967296
to_i32_try : U128 -> Try(I32, [OutOfRange, ..])

Convert a U128 to an I32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 2147483647 succeed; larger values return Err(OutOfRange).

expect U128.to_i32_try(42) == Ok(42)

expect U128.to_i32_try(3000000000) == Err(OutOfRange)
to_i64_wrap : U128 -> I64

Convert a U128 to an I64, wrapping on overflow. Values from 0 to 9223372036854775807 are preserved; larger values wrap by truncating to the low 64 bits and reinterpreting them in two's complement.

expect U128.to_i64_wrap(42) == 42

expect U128.to_i64_wrap(10000000000000000000) == -8446744073709551616
to_i64_try : U128 -> Try(I64, [OutOfRange, ..])

Convert a U128 to an I64, returning Err(OutOfRange) if the value does not fit. Values from 0 to 9223372036854775807 succeed; larger values return Err(OutOfRange).

expect U128.to_i64_try(42) == Ok(42)

expect U128.to_i64_try(10000000000000000000) == Err(OutOfRange)
to_i128_wrap : U128 -> I128

Convert a U128 to an I128, wrapping on overflow. Values from 0 to 170141183460469231731687303715884105727 are preserved; larger values wrap into the negative range (two's complement reinterpretation of the bits).

expect U128.to_i128_wrap(42) == 42

expect U128.to_i128_wrap(200000000000000000000000000000000000000) == -140282366920938463463374607431768211456
to_i128_try : U128 -> Try(I128, [OutOfRange, ..])

Convert a U128 to an I128, returning Err(OutOfRange) if the value does not fit. Values from 0 to 170141183460469231731687303715884105727 succeed; larger values return Err(OutOfRange).

expect U128.to_i128_try(42) == Ok(42)

expect U128.to_i128_try(200000000000000000000000000000000000000) == Err(OutOfRange)
to_u8_wrap : U128 -> U8

Convert a U128 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; larger values wrap by truncating to the low 8 bits.

expect U128.to_u8_wrap(42) == 42

expect U128.to_u8_wrap(300) == 44
to_u8_try : U128 -> Try(U8, [OutOfRange, ..])

Convert a U128 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; larger values return Err(OutOfRange).

expect U128.to_u8_try(42) == Ok(42)

expect U128.to_u8_try(300) == Err(OutOfRange)
to_u16_wrap : U128 -> U16

Convert a U128 to a U16, wrapping on overflow. Values from 0 to 65535 are preserved; larger values wrap by truncating to the low 16 bits.

expect U128.to_u16_wrap(42) == 42

expect U128.to_u16_wrap(70000) == 4464
to_u16_try : U128 -> Try(U16, [OutOfRange, ..])

Convert a U128 to a U16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 65535 succeed; larger values return Err(OutOfRange).

expect U128.to_u16_try(42) == Ok(42)

expect U128.to_u16_try(70000) == Err(OutOfRange)
to_u32_wrap : U128 -> U32

Convert a U128 to a U32, wrapping on overflow. Values from 0 to 4294967295 are preserved; larger values wrap by truncating to the low 32 bits.

expect U128.to_u32_wrap(42) == 42

expect U128.to_u32_wrap(5000000000) == 705032704
to_u32_try : U128 -> Try(U32, [OutOfRange, ..])

Convert a U128 to a U32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 4294967295 succeed; larger values return Err(OutOfRange).

expect U128.to_u32_try(42) == Ok(42)

expect U128.to_u32_try(5000000000) == Err(OutOfRange)
to_u64_wrap : U128 -> U64

Convert a U128 to a U64, wrapping on overflow. Values from 0 to 18446744073709551615 are preserved; larger values wrap by truncating to the low 64 bits.

expect U128.to_u64_wrap(42) == 42
to_u64_try : U128 -> Try(U64, [OutOfRange, ..])

Convert a U128 to a U64, returning Err(OutOfRange) if the value does not fit. Values from 0 to 18446744073709551615 succeed; larger values return Err(OutOfRange).

expect U128.to_u64_try(42) == Ok(42)
to_dec_try : U128 -> Try(Dec, [OutOfRange])

Convert a U128 to a Dec, returning Err(OutOfRange) if the integer value does not fit in Dec's fixed-point range.

encode : U128, fmt -> Try(encoded, err) where { fmt.encode_u128 : fmt, U128 -> Try(encoded, err) }
decode : src, fmt -> (Try(U128, err), src) where { fmt.decode_u128 : fmt, src -> (Try(U128, err), src) }

I128

default : -> I128

Returns the default I128 value, which is 0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect I128.default() == 0
highest : I128

The highest value representable by an I128, which is 170141183460469231731687303715884105727.

expect I128.highest == 170141183460469231731687303715884105727
lowest : I128

The lowest value representable by an I128, which is -170141183460469231731687303715884105728.

expect I128.lowest == -170141183460469231731687303715884105728
to_str : I128 -> Str

Convert an I128 to its decimal string representation.

expect I128.to_str(42) == "42"

expect I128.to_str(-42) == "-42"
is_zero : I128 -> Bool

Returns Bool.True if the value is 0.

expect I128.is_zero(0)

expect !I128.is_zero(7)
is_negative : I128 -> Bool

Returns Bool.True if the value is less than 0.

expect I128.is_negative(-3)

expect !I128.is_negative(0)
is_positive : I128 -> Bool

Returns Bool.True if the value is greater than 0.

expect I128.is_positive(3)

expect !I128.is_positive(0)
is_eq : I128, I128 -> Bool

Returns Bool.True if the two values are equal.

expect I128.is_eq(3, 3)

expect !I128.is_eq(3, 4)
is_gt : I128, I128 -> Bool

Returns Bool.True if the first value is greater than the second.

expect I128.is_gt(5, 3)

expect !I128.is_gt(3, 3)
is_gte : I128, I128 -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect I128.is_gte(3, 3)

expect !I128.is_gte(2, 3)
is_lt : I128, I128 -> Bool

Returns Bool.True if the first value is less than the second.

expect I128.is_lt(3, 5)

expect !I128.is_lt(3, 3)
is_lte : I128, I128 -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect I128.is_lte(3, 3)

expect !I128.is_lte(5, 3)
compare : I128, I128 -> [LT, EQ, GT]

Compare two I128 values and return their ordering.

expect I128.compare(1, 2) == LT

expect I128.compare(2, 2) == EQ

expect I128.compare(3, 2) == GT
is_even : I128 -> Bool

Returns Bool.True if the value is evenly divisible by 2.

expect I128.is_even(4)

expect !I128.is_even(5)
is_odd : I128 -> Bool

Returns Bool.True if the value is not evenly divisible by 2.

expect I128.is_odd(5)

expect !I128.is_odd(4)
is_multiple_of : I128, I128 -> Bool

Returns Bool.True if the first value is a multiple of the second. A zero divisor returns Bool.True only when the first value is also zero.

expect I128.is_multiple_of(12, 3)

expect I128.is_multiple_of(0, 0)

expect !I128.is_multiple_of(5, 0)

expect I128.is_multiple_of(I128.lowest, -1)
max : I128, I128 -> I128

Returns the greater of two I128 values.

expect I128.max(5, 3) == 5

expect I128.max(-3, -1) == -1
min : I128, I128 -> I128

Returns the smaller of two I128 values.

expect I128.min(5, 3) == 3

expect I128.min(-3, -1) == -3
negate : I128 -> I128

Negate an I128. Crashes on -170141183460469231731687303715884105728, since 170141183460469231731687303715884105728 does not fit in an I128.

expect I128.negate(3) == -3

expect I128.negate(-3) == 3
abs : I128 -> I128

Return the absolute value of an I128. Crashes on -170141183460469231731687303715884105728, since 170141183460469231731687303715884105728 does not fit in an I128.

expect I128.abs(3) == 3

expect I128.abs(-3) == 3
add_try : I128, I128 -> Try(I128, [Overflow, ..])

Add two I128 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I128.

plus_saturated : I128, I128 -> I128

Add two I128 values, saturating at I128.highest or I128.lowest on overflow rather than wrapping around.

expect I128.plus_saturated(I128.highest, 1) == I128.highest

expect I128.plus_saturated(I128.lowest, -1) == I128.lowest

expect I128.plus_saturated(2, 3) == 5
sub_try : I128, I128 -> Try(I128, [Overflow, ..])

Subtract the second I128 from the first, returning Err(Overflow) instead of wrapping if the result does not fit in an I128.

minus_saturated : I128, I128 -> I128

Subtract the second I128 from the first, saturating at the nearest bound on overflow.

expect I128.minus_saturated(I128.lowest, 1) == I128.lowest

expect I128.minus_saturated(I128.highest, -1) == I128.highest

expect I128.minus_saturated(5, 3) == 2
mul_try : I128, I128 -> Try(I128, [Overflow, ..])

Multiply two I128 values, returning Err(Overflow) instead of wrapping if the result does not fit in an I128.

times_saturated : I128, I128 -> I128

Multiply two I128 values, saturating at the nearest bound on overflow.

expect I128.times_saturated(I128.highest, 2) == I128.highest

expect I128.times_saturated(I128.lowest, 2) == I128.lowest

expect I128.times_saturated(4, 3) == 12
pow : I128, I128 -> I128

Raise the first I128 value to the power of the second. Crashes if the exact result does not fit in I128.

expect I128.pow(2, 3) == 8

expect I128.pow(5, 0) == 1
pow_try : I128, I128 -> Try(I128, [Overflow, Underflow, ..])

Raise the first I128 value to the power of the second. Returns an error instead of crashing when the exact result does not fit.

expect I128.pow_try(2, 3) == Ok(8)

expect I128.pow_try(I128.highest, 2) == Err(Overflow)

expect I128.pow_try(2, -1) == Err(Underflow)

expect I128.pow_try(-1, -3) == Ok(-1)
div_by : I128, I128 -> I128

Divide the first I128 by the second, discarding any remainder. Crashes if the second I128 is zero.

expect I128.div_by(10, 2) == 5

expect I128.div_by(11, 2) == 5
div_try : I128, I128 -> Try(I128, [DivByZero, Overflow, ..])

Divide the first I128 by the second. Returns Err(DivByZero) if the divisor is zero, or Err(Overflow) for I128.lowest / -1.

div_ceil_by : I128, I128 -> I128

Divide the first I128 by the second, rounding the result toward positive infinity. Crashes if the divisor is zero or the exact result does not fit in I128.

expect I128.div_ceil_by(7, 2) == 4

expect I128.div_ceil_by(8, 2) == 4

expect I128.div_ceil_by(-7, 2) == -3

expect I128.div_ceil_by(-7, -2) == 4
div_ceil_try : I128, I128 -> Try(I128, [DivByZero, Overflow, ..])

Divide the first I128 by the second, rounding the result toward positive infinity. Returns an error instead of crashing when the divisor is zero or the exact result does not fit.

expect I128.div_ceil_try(7, 2) == Ok(4)

expect I128.div_ceil_try(1, 0) == Err(DivByZero)

expect I128.div_ceil_try(I128.lowest, -1) == Err(Overflow)
div_trunc_by : I128, I128 -> I128

Divide the first I128 by the second, truncating toward zero.

expect I128.div_trunc_by(7, 2) == 3

expect I128.div_trunc_by(-7, 2) == -3
rem_by : I128, I128 -> I128

Return the remainder of dividing the first I128 by the second. The sign of the result matches the sign of the dividend.

expect I128.rem_by(7, 3) == 1

expect I128.rem_by(-7, 3) == -1
mod_by : I128, I128 -> I128

Return the modulus of the first I128 by the second. The modulus is the remainder left after dividing one number by another, and is always in the range 0 up to (but not including) the absolute value of the divisor. Unlike I128.rem_by, the sign of the result matches the sign of the divisor.

expect I128.mod_by(7, 3) == 1

expect I128.mod_by(-7, 3) == 2
abs_diff : I128, I128 -> U128

Return the absolute difference between two I128 values as a U128. The result is a U128 because the difference between two I128 values can be as large as 340282366920938463463374607431768211455, which does not fit in an I128.

expect I128.abs_diff(2, 5) == 3

expect I128.abs_diff(-1, 5) == 6
shift_left_by : I128, U8 -> I128

Shift the bits of an I128 to the left by the given number of positions. Bits shifted past the most significant bit are discarded, and zeros are shifted in on the right.

expect I128.shift_left_by(1, 3) == 8

expect I128.shift_left_by(0b0000_0101, 2) == 0b0001_0100
shift_right_by : I128, U8 -> I128

Shift the bits of an I128 to the right by the given number of positions, preserving the sign ("arithmetic shift"). The sign bit is shifted in on the left, so negative values remain negative. Each right shift by one is equivalent to integer division by 2 (rounding toward negative infinity).

expect I128.shift_right_by(32, 2) == 8

expect I128.shift_right_by(-32, 2) == -8
shift_right_zf_by : I128, U8 -> I128

Shift the bits of an I128 to the right by the given number of positions.

expect I128.shift_right_zf_by(32, 2) == 8

expect I128.shift_right_zf_by(0b0101_0000, 3) == 0b0000_1010
bitwise_and : I128, I128 -> I128

Returns the bitwise AND of two I128 values. Each bit in the result is 1 only when the corresponding bit is 1 in both inputs.

expect I128.bitwise_and(0b1100, 0b1010) == 0b1000
bitwise_or : I128, I128 -> I128

Returns the bitwise OR of two I128 values. Each bit in the result is 1 when the corresponding bit is 1 in either input.

expect I128.bitwise_or(0b1100, 0b1010) == 0b1110
bitwise_xor : I128, I128 -> I128

Returns the bitwise XOR of two I128 values. Each bit in the result is 1 only when the corresponding bits of the inputs differ.

expect I128.bitwise_xor(0b1100, 0b1010) == 0b0110
bitwise_not : I128 -> I128

Returns the bitwise NOT of an I128 value, flipping every bit so that each 0 becomes 1 and each 1 becomes 0. For signed integers this is equivalent to -value - 1.

expect I128.bitwise_not(5) == -6
count_leading_zero_bits : I128 -> U8

Count the zero bits before the first one bit, starting at the most significant bit.

expect I128.count_leading_zero_bits(-1) == 0

expect I128.count_leading_zero_bits(0) == 128
count_trailing_zero_bits : I128 -> U8

Count the zero bits after the last one bit, starting at the least significant bit.

expect I128.count_trailing_zero_bits(-8) == 3

expect I128.count_trailing_zero_bits(0) == 128
count_one_bits : I128 -> U8

Count the one bits in the value.

expect I128.count_one_bits(-1) == 128

expect I128.count_one_bits(0) == 0
to : I128, I128 -> Iter(I128)

Iterator of integers beginning with this I128 and ending with the other I128. (Use I128.until instead to end with the other I128 minus one.) Returns an empty iterator if this I128 is greater than the other.

expect Iter.fold(I128.to(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3, 4]

expect Iter.fold(I128.to(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0, 1]

expect Iter.fold(I128.to(5, 2), [], |acc, item| acc.append(item)) == []
until : I128, I128 -> Iter(I128)

Iterator of integers beginning with this I128 and ending with the other I128 minus one. (Use I128.to instead to end with the other I128 exactly, instead of minus one.) Returns an empty iterator if this I128 is greater than or equal to the other.

expect Iter.fold(I128.until(1, 4), [], |acc, item| acc.append(item)) == [1, 2, 3]

expect Iter.fold(I128.until(-2, 1), [], |acc, item| acc.append(item)) == [-2, -1, 0]

expect Iter.fold(I128.until(5, 2), [], |acc, item| acc.append(item)) == []
from_int_digits : List(U8) -> Try(I128, [OutOfRange])

Build an I128 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an I128 (-170141183460469231731687303715884105728 to 170141183460469231731687303715884105727), or if any element is not a valid digit. The result is always non-negative; to build a negative value, I128.negate the result.

expect I128.from_int_digits([1, 2, 3]) == Ok(123)
from_numeral : Numeral -> Try(I128, [InvalidNumeral(Str)])

Convert a numeric literal into an I128. This is the hook the compiler uses when a literal is given type I128; most code should parse user text with I128.from_str instead.

from_str : Str -> Try(I128, [BadNumStr, ..])

Parse an I128 from a Str. Returns Err(BadNumStr) if the string is not a valid integer, or if the parsed value does not fit in an I128 (-170141183460469231731687303715884105728 to 170141183460469231731687303715884105727).

expect I128.from_str("42") == Ok(42)

expect I128.from_str("-1") == Ok(-1)
to_i8_wrap : I128 -> I8

Convert an I128 to an I8, wrapping on overflow. Values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect I128.to_i8_wrap(42) == 42

expect I128.to_i8_wrap(200) == -56
to_i8_try : I128 -> Try(I8, [OutOfRange, ..])

Convert an I128 to an I8, returning Err(OutOfRange) if the value does not fit. Values from -128 to 127 succeed; other values return Err(OutOfRange).

expect I128.to_i8_try(42) == Ok(42)

expect I128.to_i8_try(200) == Err(OutOfRange)
to_i16_wrap : I128 -> I16

Convert an I128 to an I16, wrapping on overflow. Values from -32768 to 32767 are preserved; other values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect I128.to_i16_wrap(42) == 42

expect I128.to_i16_wrap(40000) == -25536
to_i16_try : I128 -> Try(I16, [OutOfRange, ..])

Convert an I128 to an I16, returning Err(OutOfRange) if the value does not fit. Values from -32768 to 32767 succeed; other values return Err(OutOfRange).

expect I128.to_i16_try(42) == Ok(42)

expect I128.to_i16_try(40000) == Err(OutOfRange)
to_i32_wrap : I128 -> I32

Convert an I128 to an I32, wrapping on overflow. Values from -2147483648 to 2147483647 are preserved; other values wrap by truncating to the low 32 bits and reinterpreting them in two's complement.

expect I128.to_i32_wrap(42) == 42

expect I128.to_i32_wrap(3000000000) == -1294967296
to_i32_try : I128 -> Try(I32, [OutOfRange, ..])

Convert an I128 to an I32, returning Err(OutOfRange) if the value does not fit. Values from -2147483648 to 2147483647 succeed; other values return Err(OutOfRange).

expect I128.to_i32_try(42) == Ok(42)

expect I128.to_i32_try(3000000000) == Err(OutOfRange)
to_i64_wrap : I128 -> I64

Convert an I128 to an I64, wrapping on overflow. Values from -9223372036854775808 to 9223372036854775807 are preserved; other values wrap by truncating to the low 64 bits and reinterpreting them in two's complement.

expect I128.to_i64_wrap(42) == 42
to_i64_try : I128 -> Try(I64, [OutOfRange, ..])

Convert an I128 to an I64, returning Err(OutOfRange) if the value does not fit. Values from -9223372036854775808 to 9223372036854775807 succeed; other values return Err(OutOfRange).

expect I128.to_i64_try(42) == Ok(42)
to_u8_wrap : I128 -> U8

Convert an I128 to a U8, wrapping on overflow. Values from 0 to 255 are preserved; other values wrap by truncating to the low 8 bits (two's complement reinterpretation of those bits).

expect I128.to_u8_wrap(42) == 42

expect I128.to_u8_wrap(-1) == 255
to_u8_try : I128 -> Try(U8, [OutOfRange, ..])

Convert an I128 to a U8, returning Err(OutOfRange) if the value does not fit. Values from 0 to 255 succeed; other values return Err(OutOfRange).

expect I128.to_u8_try(42) == Ok(42)

expect I128.to_u8_try(-1) == Err(OutOfRange)
to_u16_wrap : I128 -> U16

Convert an I128 to a U16, wrapping on overflow. Values from 0 to 65535 are preserved; other values wrap by truncating to the low 16 bits (two's complement reinterpretation of those bits).

expect I128.to_u16_wrap(42) == 42

expect I128.to_u16_wrap(-1) == 65535
to_u16_try : I128 -> Try(U16, [OutOfRange, ..])

Convert an I128 to a U16, returning Err(OutOfRange) if the value does not fit. Values from 0 to 65535 succeed; other values return Err(OutOfRange).

expect I128.to_u16_try(42) == Ok(42)

expect I128.to_u16_try(-1) == Err(OutOfRange)
to_u32_wrap : I128 -> U32

Convert an I128 to a U32, wrapping on overflow. Values from 0 to 4294967295 are preserved; other values wrap by truncating to the low 32 bits (two's complement reinterpretation of those bits).

expect I128.to_u32_wrap(42) == 42

expect I128.to_u32_wrap(-1) == 4294967295
to_u32_try : I128 -> Try(U32, [OutOfRange, ..])

Convert an I128 to a U32, returning Err(OutOfRange) if the value does not fit. Values from 0 to 4294967295 succeed; other values return Err(OutOfRange).

expect I128.to_u32_try(42) == Ok(42)

expect I128.to_u32_try(-1) == Err(OutOfRange)
to_u64_wrap : I128 -> U64

Convert an I128 to a U64, wrapping on overflow. Values from 0 to 18446744073709551615 are preserved; other values wrap by truncating to the low 64 bits (two's complement reinterpretation of those bits).

expect I128.to_u64_wrap(42) == 42

expect I128.to_u64_wrap(-1) == 18446744073709551615
to_u64_try : I128 -> Try(U64, [OutOfRange, ..])

Convert an I128 to a U64, returning Err(OutOfRange) if the value does not fit. Values from 0 to 18446744073709551615 succeed; other values return Err(OutOfRange).

expect I128.to_u64_try(42) == Ok(42)

expect I128.to_u64_try(-1) == Err(OutOfRange)
to_u128_wrap : I128 -> U128

Convert an I128 to a U128, wrapping on overflow. Non-negative values are preserved; negative values wrap into the upper end of the U128 range (two's complement reinterpretation of the bits).

expect I128.to_u128_wrap(42) == 42

expect I128.to_u128_wrap(-1) == 340282366920938463463374607431768211455
to_u128_try : I128 -> Try(U128, [OutOfRange, ..])

Convert an I128 to a U128, returning Err(OutOfRange) if the value is negative. Non-negative values succeed; negative values return Err(OutOfRange).

expect I128.to_u128_try(42) == Ok(42)

expect I128.to_u128_try(-1) == Err(OutOfRange)
to_dec_try : I128 -> Try(Dec, [OutOfRange])

Convert an I128 to a Dec, returning Err(OutOfRange) if the integer value does not fit in Dec's fixed-point range.

encode : I128, fmt -> Try(encoded, err) where { fmt.encode_i128 : fmt, I128 -> Try(encoded, err) }

Encode an I128 using a format that provides encode_i128

decode : src, fmt -> (Try(I128, err), src) where { fmt.decode_i128 : fmt, src -> (Try(I128, err), src) }

Decode an I128 using a format that provides decode_i128

Dec

default : -> Dec

Returns the default Dec value, which is 0.0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect Dec.default() == 0.0
highest : Dec

The highest value representable by a Dec. Dec values have 18 fixed fractional decimal places, so this is 170141183460469231731.687303715884105727.

expect Dec.highest == 170141183460469231731.687303715884105727
lowest : Dec

The lowest value representable by a Dec. Dec values have 18 fixed fractional decimal places, so this is -170141183460469231731.687303715884105728.

expect Dec.lowest == -170141183460469231731.687303715884105728
e : Dec

Euler's number as a Dec, truncated to 18 fractional decimal places.

pi : Dec

The circle constant pi as a Dec, truncated to 18 fractional decimal places.

tau : Dec

The circle constant tau as a Dec, truncated to 18 fractional decimal places.

to_str : Dec -> Str

Convert a Dec to its decimal string representation.

expect Dec.to_str(42.5) == "42.5"

expect Dec.to_str(-42.5) == "-42.5"
is_zero : Dec -> Bool

Returns Bool.True if the value is 0.0.

expect Dec.is_zero(0.0)

expect !Dec.is_zero(0.1)
is_negative : Dec -> Bool

Returns Bool.True if the value is less than 0.0.

expect Dec.is_negative(-0.1)

expect !Dec.is_negative(0.0)
is_positive : Dec -> Bool

Returns Bool.True if the value is greater than 0.0.

expect Dec.is_positive(0.1)

expect !Dec.is_positive(0.0)
is_eq : Dec, Dec -> Bool

Returns Bool.True if the two values are equal.

expect Dec.is_eq(3.5, 3.5)

expect !Dec.is_eq(3.5, 4.0)
is_gt : Dec, Dec -> Bool

Returns Bool.True if the first value is greater than the second.

expect Dec.is_gt(5.0, 3.0)

expect !Dec.is_gt(3.0, 3.0)
is_gte : Dec, Dec -> Bool

Returns Bool.True if the first value is greater than or equal to the second.

expect Dec.is_gte(3.0, 3.0)

expect !Dec.is_gte(2.0, 3.0)
is_lt : Dec, Dec -> Bool

Returns Bool.True if the first value is less than the second.

expect Dec.is_lt(3.0, 5.0)

expect !Dec.is_lt(3.0, 3.0)
is_lte : Dec, Dec -> Bool

Returns Bool.True if the first value is less than or equal to the second.

expect Dec.is_lte(3.0, 3.0)

expect !Dec.is_lte(5.0, 3.0)
compare : Dec, Dec -> [LT, EQ, GT]

Compare two Dec values and return their ordering.

expect Dec.compare(1.0, 2.0) == LT

expect Dec.compare(2.0, 2.0) == EQ

expect Dec.compare(3.0, 2.0) == GT
max : Dec, Dec -> Dec

Returns the greater of two Dec values.

expect Dec.max(5, 3) == 5

expect Dec.max(-3, -1) == -1
min : Dec, Dec -> Dec

Returns the smaller of two Dec values.

expect Dec.min(5, 3) == 3

expect Dec.min(-3, -1) == -3
negate : Dec -> Dec

Negate a Dec.

expect Dec.negate(3.5) == -3.5

expect Dec.negate(-3.5) == 3.5
abs : Dec -> Dec

Return the absolute value of a Dec.

expect Dec.abs(3.5) == 3.5

expect Dec.abs(-3.5) == 3.5
steps_between : Dec, Dec -> [Known(U64), Unknown]

Conservative placeholder: always returns Unknown. Counting the steps in a fractional [start, end) range advancing by 1 would require ceil(end - start); until that is implemented, Unknown is always a correct (if imprecise) length hint.

plus_saturated : Dec, Dec -> Dec

Add two Dec values, saturating at Dec.highest or Dec.lowest on overflow rather than wrapping around.

expect Dec.plus_saturated(Dec.highest, 1.0) == Dec.highest

expect Dec.plus_saturated(Dec.lowest, -1.0) == Dec.lowest

expect Dec.plus_saturated(1.5, 2.5) == 4.0
minus : Dec, Dec -> Dec

Subtract the second Dec from the first.

expect Dec.minus(5.0, 3.5) == 1.5
minus_saturated : Dec, Dec -> Dec

Subtract the second Dec from the first, saturating at the nearest bound on overflow.

expect Dec.minus_saturated(Dec.lowest, 1.0) == Dec.lowest

expect Dec.minus_saturated(Dec.highest, -1.0) == Dec.highest

expect Dec.minus_saturated(5.0, 3.5) == 1.5
times : Dec, Dec -> Dec

Multiply two Dec values. The result is limited to Dec's fixed 18 fractional decimal places and crashes if it overflows.

expect Dec.times(2.5, 4.0) == 10.0
times_saturated : Dec, Dec -> Dec

Multiply two Dec values, saturating at the nearest bound on overflow.

expect Dec.times_saturated(Dec.highest, 2.0) == Dec.highest

expect Dec.times_saturated(Dec.lowest, 2.0) == Dec.lowest

expect Dec.times_saturated(2.5, 4.0) == 10.0
pow : Dec, Dec -> Dec

Raise a Dec to a Dec power. Results are limited to Dec's fixed 18 fractional decimal places. Fractional exponents require a positive base; non-positive bases with fractional exponents crash. Negative integer exponents divide by the positive power and crash when that division is undefined, such as 0.0 to a negative power.

sqrt : Dec -> Dec

Return the square root of a Dec. Crashes if the input is negative. The result is truncated to Dec's fixed 18 fractional decimal places.

sqrt_try : Dec -> Try(Dec, [SqrtOfNegative, ..])

Return the square root of a Dec, or Err(SqrtOfNegative) if the input is negative. The result is truncated to Dec's fixed 18 fractional decimal places.

sin : Dec -> Dec

Return the sine of a Dec angle in radians. This is a fixed-point approximation limited to 18 fractional decimal places.

cos : Dec -> Dec

Return the cosine of a Dec angle in radians. This is a fixed-point approximation limited to 18 fractional decimal places.

tan : Dec -> Dec

Return the tangent of a Dec angle in radians. This is computed as sine divided by cosine, so it can crash if the fixed-point cosine result is zero or the division overflows.

asin : Dec -> Dec

Return the arcsine of a Dec value in radians. Crashes if the input is outside -1.0 through 1.0.

acos : Dec -> Dec

Return the arccosine of a Dec value in radians. Crashes if the input is outside -1.0 through 1.0.

atan : Dec -> Dec

Return the arctangent of a Dec value in radians. This is a fixed-point approximation limited to 18 fractional decimal places.

div_by : Dec, Dec -> Dec

Divide the first Dec by the second. Crashes if the second Dec is zero or the result overflows. Results with more than 18 fractional decimal places are truncated to Dec precision.

expect Dec.div_by(10.0, 4.0) == 2.5
div_trunc_by : Dec, Dec -> Dec

Divide the first Dec by the second, truncating toward zero to produce a whole-number Dec result.

expect Dec.div_trunc_by(7.5, 2.0) == 3.0

expect Dec.div_trunc_by(-7.5, 2.0) == -3.0
rem_by : Dec, Dec -> Dec

Return the remainder of dividing the first Dec by the second. The sign of the result matches the sign of the dividend.

expect Dec.rem_by(7.5, 2.0) == 1.5

expect Dec.rem_by(-7.5, 2.0) == -1.5
abs_diff : Dec, Dec -> Dec

Return the absolute difference between two Dec values.

expect Dec.abs_diff(2.5, 5.0) == 2.5

expect Dec.abs_diff(-1.5, 5.0) == 6.5
round_to_i8 : Dec -> I8

Round a Dec to the nearest I8. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_i8(3.4) == 3
round_to_i16 : Dec -> I16

Round a Dec to the nearest I16. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_i16(3.4) == 3
round_to_i32 : Dec -> I32

Round a Dec to the nearest I32. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_i32(-3.6) == -4
round_to_i64 : Dec -> I64

Round a Dec to the nearest I64. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_i64(7.2) == 7
round_to_i128 : Dec -> I128

Round a Dec to the nearest I128. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_i128(7.2) == 7
round_to_u8 : Dec -> U8

Round a Dec to the nearest U8. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_u8(3.4) == 3
round_to_u16 : Dec -> U16

Round a Dec to the nearest U16. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_u16(3.4) == 3
round_to_u32 : Dec -> U32

Round a Dec to the nearest U32. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_u32(7.2) == 7
round_to_u64 : Dec -> U64

Round a Dec to the nearest U64. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_u64(7.2) == 7
round_to_u128 : Dec -> U128

Round a Dec to the nearest U128. Halfway values round away from zero. Crashes if the rounded value is out of range.

expect Dec.round_to_u128(7.2) == 7
floor_to_i8 : Dec -> I8

Round a Dec down to an I8. Crashes if the rounded value is out of range.

expect Dec.floor_to_i8(-3.2) == -4
floor_to_i16 : Dec -> I16

Round a Dec down to an I16. Crashes if the rounded value is out of range.

expect Dec.floor_to_i16(-3.2) == -4
floor_to_i32 : Dec -> I32

Round a Dec down to an I32. Crashes if the rounded value is out of range.

expect Dec.floor_to_i32(3.8) == 3
floor_to_i64 : Dec -> I64

Round a Dec down to an I64. Crashes if the rounded value is out of range.

expect Dec.floor_to_i64(3.8) == 3
floor_to_i128 : Dec -> I128

Round a Dec down to an I128. Crashes if the rounded value is out of range.

expect Dec.floor_to_i128(3.8) == 3
floor_to_u8 : Dec -> U8

Round a Dec down to a U8. Crashes if the rounded value is out of range.

expect Dec.floor_to_u8(3.8) == 3
floor_to_u16 : Dec -> U16

Round a Dec down to a U16. Crashes if the rounded value is out of range.

expect Dec.floor_to_u16(3.8) == 3
floor_to_u32 : Dec -> U32

Round a Dec down to a U32. Crashes if the rounded value is out of range.

expect Dec.floor_to_u32(3.8) == 3
floor_to_u64 : Dec -> U64

Round a Dec down to a U64. Crashes if the rounded value is out of range.

expect Dec.floor_to_u64(3.8) == 3
floor_to_u128 : Dec -> U128

Round a Dec down to a U128. Crashes if the rounded value is out of range.

expect Dec.floor_to_u128(3.8) == 3
ceiling_to_i8 : Dec -> I8

Round a Dec up to an I8. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_i8(-3.2) == -3
ceiling_to_i16 : Dec -> I16

Round a Dec up to an I16. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_i16(-3.2) == -3
ceiling_to_i32 : Dec -> I32

Round a Dec up to an I32. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_i32(3.2) == 4
ceiling_to_i64 : Dec -> I64

Round a Dec up to an I64. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_i64(3.2) == 4
ceiling_to_u8 : Dec -> U8

Round a Dec up to a U8. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_u8(3.2) == 4
ceiling_to_u16 : Dec -> U16

Round a Dec up to a U16. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_u16(3.2) == 4
ceiling_to_u32 : Dec -> U32

Round a Dec up to a U32. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_u32(3.2) == 4
ceiling_to_u64 : Dec -> U64

Round a Dec up to a U64. Crashes if the rounded value is out of range.

expect Dec.ceiling_to_u64(3.2) == 4
from_int_digits : List(U8) -> Try(Dec, [OutOfRange])

Build a Dec from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a Dec, or if any element is not a valid digit. The result is always non-negative; to build a negative value, Dec.negate the result.

expect Dec.from_int_digits([1, 2, 3]) == Ok(123.0)
from_dec_digits : (List(U8), List(U8)) -> Try(Dec, [OutOfRange])

Build a Dec from a tuple of (integer digits, fractional digits), each as a list of base-10 digits most significant first. Each element of both lists must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in a Dec, or if any element is not a valid digit. The result is always non-negative; to build a negative value, Dec.negate the result.

expect Dec.from_dec_digits(([1, 2], [5])) == Ok(12.5)
from_numeral : Numeral -> Try(Dec, [InvalidNumeral(Str)])

Convert a numeric literal into a Dec. This is the hook the compiler uses when a literal is given type Dec; most code should parse user text with Dec.from_str instead.

from_str : Str -> Try(Dec, [BadNumStr, ..])

Parse a Dec from a Str. Returns Err(BadNumStr) if the string is not a valid decimal number, or if the parsed value does not fit in a Dec.

expect Dec.from_str("42.5") == Ok(42.5)

expect Dec.from_str("-1.25") == Ok(-1.25)

expect Dec.from_str("not a number") == Err(BadNumStr)
to_i8_wrap : Dec -> I8

Convert a Dec to an I8. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement.

expect Dec.to_i8_wrap(42.7) == 42

expect Dec.to_i8_wrap(200.0) == -56
to_i8_try : Dec -> Try(I8, [OutOfRange])

Convert a Dec to an I8, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero. Integer-part values from -128 to 127 succeed; other values return Err(OutOfRange).

expect Dec.to_i8_try(42.7) == Ok(42)

expect Dec.to_i8_try(200.0) == Err(OutOfRange)
to_i16_wrap : Dec -> I16

Convert a Dec to an I16. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -32768 to 32767 are preserved; other values wrap by truncating to the low 16 bits and reinterpreting them in two's complement.

expect Dec.to_i16_wrap(42.5) == 42

expect Dec.to_i16_wrap(40000.0) == -25536
to_i16_try : Dec -> Try(I16, [OutOfRange])

Convert a Dec to an I16, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero. Integer-part values from -32768 to 32767 succeed; other values return Err(OutOfRange).

expect Dec.to_i16_try(42.5) == Ok(42)

expect Dec.to_i16_try(40000.0) == Err(OutOfRange)
to_i32_wrap : Dec -> I32

Convert a Dec to an I32. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -2147483648 to 2147483647 are preserved; other values wrap by truncating to the low 32 bits and reinterpreting them in two's complement.

expect Dec.to_i32_wrap(42.5) == 42

expect Dec.to_i32_wrap(3000000000.0) == -1294967296
to_i32_try : Dec -> Try(I32, [OutOfRange])

Convert a Dec to an I32, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero. Integer-part values from -2147483648 to 2147483647 succeed; other values return Err(OutOfRange).

expect Dec.to_i32_try(42.5) == Ok(42)

expect Dec.to_i32_try(3000000000.0) == Err(OutOfRange)
to_i64_wrap : Dec -> I64

Convert a Dec to an I64. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -9223372036854775808 to 9223372036854775807 are preserved; other values wrap by truncating to the low 64 bits and reinterpreting them in two's complement.

expect Dec.to_i64_wrap(42.5) == 42
to_i64_try : Dec -> Try(I64, [OutOfRange])

Convert a Dec to an I64, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero.

expect Dec.to_i64_try(42.5) == Ok(42)
to_i128_wrap : Dec -> I128

Convert a Dec to an I128. The fractional part is truncated toward zero. The entire integer part of any Dec fits in an I128, so no wrapping occurs in practice.

expect Dec.to_i128_wrap(42.5) == 42
to_i128_try : Dec -> Try(I128, [OutOfRange])

Convert a Dec to an I128, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero.

expect Dec.to_i128_try(42.5) == Ok(42)
to_u8_wrap : Dec -> U8

Convert a Dec to a U8. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from 0 to 255 are preserved; other values wrap by truncating to the low 8 bits (two's complement reinterpretation of those bits).

expect Dec.to_u8_wrap(42.7) == 42

expect Dec.to_u8_wrap(-1.0) == 255
to_u8_try : Dec -> Try(U8, [OutOfRange])

Convert a Dec to a U8, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero. Integer-part values from 0 to 255 succeed; other values return Err(OutOfRange).

expect Dec.to_u8_try(42.7) == Ok(42)

expect Dec.to_u8_try(-1.0) == Err(OutOfRange)
to_u16_wrap : Dec -> U16

Convert a Dec to a U16. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from 0 to 65535 are preserved; other values wrap by truncating to the low 16 bits (two's complement reinterpretation of those bits).

expect Dec.to_u16_wrap(42.5) == 42

expect Dec.to_u16_wrap(-1.0) == 65535
to_u16_try : Dec -> Try(U16, [OutOfRange])

Convert a Dec to a U16, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero. Integer-part values from 0 to 65535 succeed; other values return Err(OutOfRange).

expect Dec.to_u16_try(42.5) == Ok(42)

expect Dec.to_u16_try(-1.0) == Err(OutOfRange)
to_u32_wrap : Dec -> U32

Convert a Dec to a U32. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from 0 to 4294967295 are preserved; other values wrap by truncating to the low 32 bits (two's complement reinterpretation of those bits).

expect Dec.to_u32_wrap(42.5) == 42

expect Dec.to_u32_wrap(-1.0) == 4294967295
to_u32_try : Dec -> Try(U32, [OutOfRange])

Convert a Dec to a U32, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero. Integer-part values from 0 to 4294967295 succeed; other values return Err(OutOfRange).

expect Dec.to_u32_try(42.5) == Ok(42)

expect Dec.to_u32_try(-1.0) == Err(OutOfRange)
to_u64_wrap : Dec -> U64

Convert a Dec to a U64. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from 0 to 18446744073709551615 are preserved; other values wrap by truncating to the low 64 bits (two's complement reinterpretation of those bits).

expect Dec.to_u64_wrap(42.5) == 42

expect Dec.to_u64_wrap(-1.0) == 18446744073709551615
to_u64_try : Dec -> Try(U64, [OutOfRange])

Convert a Dec to a U64, returning Err(OutOfRange) if the integer part does not fit. The fractional part is truncated toward zero.

expect Dec.to_u64_try(42.5) == Ok(42)

expect Dec.to_u64_try(-1.0) == Err(OutOfRange)
to_u128_wrap : Dec -> U128

Convert a Dec to a U128. The fractional part is truncated toward zero. Non-negative integer parts are preserved; negative values wrap into the upper end of the U128 range (two's complement reinterpretation of the bits).

expect Dec.to_u128_wrap(42.5) == 42
to_u128_try : Dec -> Try(U128, [OutOfRange])

Convert a Dec to a U128, returning Err(OutOfRange) if the value is negative. The fractional part is truncated toward zero.

expect Dec.to_u128_try(42.5) == Ok(42)

expect Dec.to_u128_try(-1.0) == Err(OutOfRange)
to_f32_try : Dec -> Try(F32, [OutOfRange])

Convert a Dec to an F32, returning Err(OutOfRange) if the value does not fit in the finite F32 range. All current Dec values fit in that range, though precision may still be lost.

to_f64 : Dec -> F64

Convert a Dec to an F64. This conversion is lossy because Dec can have more decimal fractional precision than F64 can represent exactly.

to : Dec, Dec -> Iter(Dec)

Iterator of decimals beginning with this Dec and ending with the other Dec, stepping by 1.0. (Use Dec.until instead to end with the other Dec minus one.) Returns an empty iterator if this Dec is greater than the other.

expect Iter.fold(Dec.to(1.0, 4.0), [], |acc, item| acc.append(item)) == [1.0, 2.0, 3.0, 4.0]

expect Iter.fold(Dec.to(-2.0, 1.0), [], |acc, item| acc.append(item)) == [-2.0, -1.0, 0.0, 1.0]

expect Iter.fold(Dec.to(5.0, 2.0), [], |acc, item| acc.append(item)) == []
until : Dec, Dec -> Iter(Dec)

Iterator of decimals beginning with this Dec and ending with the other Dec minus one, stepping by 1.0. (Use Dec.to instead to end with the other Dec exactly, instead of minus one.) Returns an empty iterator if this Dec is greater than or equal to the other.

expect Iter.fold(Dec.until(1.0, 4.0), [], |acc, item| acc.append(item)) == [1.0, 2.0, 3.0]

expect Iter.fold(Dec.until(-2.0, 1.0), [], |acc, item| acc.append(item)) == [-2.0, -1.0, 0.0]

expect Iter.fold(Dec.until(5.0, 2.0), [], |acc, item| acc.append(item)) == []
encode : Dec, fmt -> Try(encoded, err) where { fmt.encode_dec : fmt, Dec -> Try(encoded, err) }

Encode a Dec using a format that provides encode_dec

decode : src, fmt -> (Try(Dec, err), src) where { fmt.decode_dec : fmt, src -> (Try(Dec, err), src) }

Decode a Dec using a format that provides decode_dec

F32

default : -> F32

Returns the default F32 value, which is 0.0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect F32.is_zero(F32.default())
highest : F32

The highest finite value representable by an F32, which is 3.40282347e38.

expect F32.to_bits(F32.highest) == 2139095039
lowest : F32

The lowest finite value representable by an F32, which is -3.40282347e38.

expect F32.to_bits(F32.lowest) == 4286578687
nan : F32

A quiet NaN F32 value.

expect F32.is_nan(F32.nan)
infinity : F32

Positive infinity as an F32.

expect F32.is_infinite(F32.infinity)

expect F32.infinity > F32.highest
e : F32

Euler's number as an F32.

expect F32.to_bits(F32.e) == 1076754516
pi : F32

The circle constant pi as an F32.

expect F32.to_bits(F32.pi) == 1078530011
tau : F32

The circle constant tau as an F32.

expect F32.to_bits(F32.tau) == 1086918619
to_str : F32 -> Str

Convert an F32 to its decimal string representation.

expect F32.to_str(42.5) == "42.5"

expect F32.to_str(-42.5) == "-42.5"
to_bits : F32 -> U32

Return the raw IEEE 754 bit pattern of an F32.

expect F32.to_bits(F32.from_bits(1069547520)) == 1069547520

expect F32.from_bits(F32.to_bits(1.5)).to_str() == "1.5"
from_bits : U32 -> F32

Build an F32 from a raw IEEE 754 bit pattern.

expect F32.from_bits(F32.to_bits(-0.0)).to_bits() == F32.to_bits(-0.0)

expect F32.from_bits(0).to_bits() == 0
is_nan : F32 -> Bool

Returns Bool.True if the value is NaN.

expect F32.is_nan(F32.nan)

expect !F32.is_nan(1.0)
is_infinite : F32 -> Bool

Returns Bool.True if the value is positive or negative infinity.

expect F32.is_infinite(F32.infinity)

expect F32.is_infinite(F32.negate(F32.infinity))

expect !F32.is_infinite(1.0)
is_finite : F32 -> Bool

Returns Bool.True if the value is neither NaN nor infinity.

expect F32.is_finite(1.0)

expect !F32.is_finite(F32.infinity)

expect !F32.is_finite(F32.nan)
is_zero : F32 -> Bool

Returns Bool.True if the value is 0.0. Both positive and negative zero return Bool.True.

expect F32.is_zero(0.0)

expect !F32.is_zero(0.5)
is_float_eq : F32, F32 -> Bool

Returns Bool.True if two F32 values compare equal using the IEEE 754 == operation. NaN does not compare equal to itself.

expect F32.is_float_eq(1.5, 1.5)

expect !F32.is_float_eq(F32.nan, F32.nan)
is_negative : F32 -> Bool

Returns Bool.True if the value is less than 0.0.

expect F32.is_negative(-0.5)

expect !F32.is_negative(0.0)
is_positive : F32 -> Bool

Returns Bool.True if the value is greater than 0.0.

expect F32.is_positive(0.5)

expect !F32.is_positive(0.0)
is_gt : F32, F32 -> Bool

Returns Bool.True if the first value is greater than the second. Comparisons involving NaN always return Bool.False.

expect F32.is_gt(5.0, 3.0)

expect !F32.is_gt(3.0, 3.0)
is_gte : F32, F32 -> Bool

Returns Bool.True if the first value is greater than or equal to the second. Comparisons involving NaN always return Bool.False.

expect F32.is_gte(3.0, 3.0)

expect !F32.is_gte(2.0, 3.0)
is_lt : F32, F32 -> Bool

Returns Bool.True if the first value is less than the second. Comparisons involving NaN always return Bool.False.

expect F32.is_lt(3.0, 5.0)

expect !F32.is_lt(3.0, 3.0)
is_lte : F32, F32 -> Bool

Returns Bool.True if the first value is less than or equal to the second. Comparisons involving NaN always return Bool.False.

expect F32.is_lte(3.0, 3.0)

expect !F32.is_lte(5.0, 3.0)
max : F32, F32 -> F32

Returns the greater of two F32 values.

expect F32.is_float_eq(F32.max(5, 3), 5)

expect F32.is_float_eq(F32.max(-3, -1), -1)
min : F32, F32 -> F32

Returns the smaller of two F32 values.

expect F32.is_float_eq(F32.min(5, 3), 3)

expect F32.is_float_eq(F32.min(-3, -1), -3)
negate : F32 -> F32

Negate an F32. Flips the sign bit, so negating 0.0 produces -0.0 and negating NaN produces NaN.

expect F32.negate(3.5).to_str() == "-3.5"

expect F32.negate(-3.5).to_str() == "3.5"
abs : F32 -> F32

Return the absolute value of an F32. The result of abs(NaN) is NaN.

expect F32.abs(3.5).to_str() == "3.5"

expect F32.abs(-3.5).to_str() == "3.5"
sqrt : F32 -> F32

Return the square root of an F32. Crashes if the input is negative. NaN and positive infinity follow IEEE 754 behavior: NaN returns NaN, and positive infinity returns positive infinity.

expect F32.to_str(F32.sqrt(9.0)) == "3"

expect F32.to_str(F32.sqrt(2.25)) == "1.5"
sqrt_try : F32 -> Try(F32, [SqrtOfNegative, ..])

Return the square root of an F32, or Err(SqrtOfNegative) if the input is negative. NaN and positive infinity return Ok with the IEEE 754 result.

expect F32.is_float_eq(F32.sqrt_try(9.0).ok_or(0.0), 3.0)

expect F32.sqrt_try(-1.0) == Err(SqrtOfNegative)
pow : F32, F32 -> F32

Raise an F32 to an F32 power. The result follows IEEE 754 behavior and may be inf, -inf, or NaN, such as when a negative base has a non-integer exponent.

expect F32.pow(2.0, 3.0).to_str() == "8"

expect F32.pow(9.0, 0.5).to_str() == "3"
sin : F32 -> F32

Return the sine of an F32 angle in radians. NaN and infinite inputs follow IEEE 754 behavior and return NaN.

expect F32.sin(0.0).to_str() == "0"
cos : F32 -> F32

Return the cosine of an F32 angle in radians. NaN and infinite inputs follow IEEE 754 behavior and return NaN.

expect F32.cos(0.0).to_str() == "1"
tan : F32 -> F32

Return the tangent of an F32 angle in radians. The result follows IEEE 754 behavior and may be inf, -inf, or NaN; NaN and infinite inputs return NaN.

expect F32.tan(0.0).to_str() == "0"
asin : F32 -> F32

Return the arcsine of an F32 value in radians. Inputs outside -1.0 through 1.0, NaN, and infinities return NaN.

expect F32.asin(0.0).to_str() == "0"
acos : F32 -> F32

Return the arccosine of an F32 value in radians. Inputs outside -1.0 through 1.0, NaN, and infinities return NaN.

expect F32.acos(1.0).to_str() == "0"
atan : F32 -> F32

Return the arctangent of an F32 value in radians. NaN returns NaN; infinities follow IEEE 754 behavior.

expect F32.atan(0.0).to_str() == "0"
plus : F32, F32 -> F32

Add two F32 values. Addition is subject to IEEE 754 rounding; the result may be inf, -inf, or NaN.

expect F32.plus(1.5, 2.5).to_str() == "4"
minus : F32, F32 -> F32

Subtract the second F32 from the first. Subtraction is subject to IEEE 754 rounding; the result may be inf, -inf, or NaN.

expect F32.minus(5.0, 3.5).to_str() == "1.5"
times : F32, F32 -> F32

Multiply two F32 values. Multiplication is subject to IEEE 754 rounding; the result may be inf, -inf, or NaN.

expect F32.times(2.5, 4.0).to_str() == "10"
div_by : F32, F32 -> F32

Divide the first F32 by the second. Unlike integer division, division by zero does not crash: it produces inf, -inf, or NaN as specified by IEEE 754.

expect F32.div_by(10.0, 4.0).to_str() == "2.5"
div_trunc_by : F32, F32 -> F32

Divide the first F32 by the second, truncating toward zero to produce a whole-number F32 result.

expect F32.div_trunc_by(7.5, 2.0).to_str() == "3"

expect F32.div_trunc_by(-7.5, 2.0).to_str() == "-3"
rem_by : F32, F32 -> F32

Return the remainder of dividing the first F32 by the second. The sign of the result matches the sign of the dividend.

expect F32.rem_by(7.5, 2.0).to_str() == "1.5"

expect F32.rem_by(-7.5, 2.0).to_str() == "-1.5"
abs_diff : F32, F32 -> F32

Return the absolute difference between two F32 values.

expect F32.abs_diff(2.5, 5.0).to_str() == "2.5"

expect F32.abs_diff(-1.5, 5.0).to_str() == "6.5"
round_to_i8 : F32 -> I8

Round an F32 to the nearest I8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_i8(3.4) == 3
round_to_i16 : F32 -> I16

Round an F32 to the nearest I16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_i16(3.4) == 3
round_to_i32 : F32 -> I32

Round an F32 to the nearest I32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_i32(-3.6) == -4
round_to_i64 : F32 -> I64

Round an F32 to the nearest I64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_i64(7.2) == 7
round_to_i128 : F32 -> I128

Round an F32 to the nearest I128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_i128(7.2) == 7
round_to_u8 : F32 -> U8

Round an F32 to the nearest U8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_u8(3.4) == 3
round_to_u16 : F32 -> U16

Round an F32 to the nearest U16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_u16(3.4) == 3
round_to_u32 : F32 -> U32

Round an F32 to the nearest U32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_u32(7.2) == 7
round_to_u64 : F32 -> U64

Round an F32 to the nearest U64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_u64(7.2) == 7
round_to_u128 : F32 -> U128

Round an F32 to the nearest U128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.round_to_u128(7.2) == 7
floor_to_i8 : F32 -> I8

Round an F32 down to an I8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_i8(-3.2) == -4
floor_to_i16 : F32 -> I16

Round an F32 down to an I16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_i16(-3.2) == -4
floor_to_i32 : F32 -> I32

Round an F32 down to an I32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_i32(3.8) == 3
floor_to_i64 : F32 -> I64

Round an F32 down to an I64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_i64(3.8) == 3
floor_to_i128 : F32 -> I128

Round an F32 down to an I128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_i128(3.8) == 3
floor_to_u8 : F32 -> U8

Round an F32 down to a U8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_u8(3.8) == 3
floor_to_u16 : F32 -> U16

Round an F32 down to a U16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_u16(3.8) == 3
floor_to_u32 : F32 -> U32

Round an F32 down to a U32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_u32(3.8) == 3
floor_to_u64 : F32 -> U64

Round an F32 down to a U64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_u64(3.8) == 3
floor_to_u128 : F32 -> U128

Round an F32 down to a U128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.floor_to_u128(3.8) == 3
ceiling_to_i8 : F32 -> I8

Round an F32 up to an I8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_i8(-3.2) == -3
ceiling_to_i16 : F32 -> I16

Round an F32 up to an I16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_i16(-3.2) == -3
ceiling_to_i32 : F32 -> I32

Round an F32 up to an I32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_i32(3.2) == 4
ceiling_to_i64 : F32 -> I64

Round an F32 up to an I64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_i64(3.2) == 4
ceiling_to_i128 : F32 -> I128

Round an F32 up to an I128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_i128(3.2) == 4
ceiling_to_u8 : F32 -> U8

Round an F32 up to a U8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_u8(3.2) == 4
ceiling_to_u16 : F32 -> U16

Round an F32 up to a U16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_u16(3.2) == 4
ceiling_to_u32 : F32 -> U32

Round an F32 up to a U32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_u32(3.2) == 4
ceiling_to_u64 : F32 -> U64

Round an F32 up to a U64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_u64(3.2) == 4
ceiling_to_u128 : F32 -> U128

Round an F32 up to a U128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F32.ceiling_to_u128(3.2) == 4
from_int_digits : List(U8) -> Try(F32, [OutOfRange])

Build an F32 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an F32, or if any element is not a valid digit. The result is always non-negative; to build a negative value, F32.negate the result.

expect F32.to_str(F32.from_int_digits([1, 2, 3]).ok_or(0.0)) == "123"
from_dec_digits : (List(U8), List(U8)) -> Try(F32, [OutOfRange])

Build an F32 from a tuple of (integer digits, fractional digits), each as a list of base-10 digits most significant first. Each element of both lists must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an F32, or if any element is not a valid digit. The result is always non-negative; to build a negative value, F32.negate the result.

expect F32.to_str(F32.from_dec_digits(([1, 2], [5])).ok_or(0.0)) == "12.5"
from_numeral : Numeral -> Try(F32, [InvalidNumeral(Str)])

Convert a numeric literal into an F32. This is the hook the compiler uses when a literal is given type F32; most code should parse user text with F32.from_str instead.

from_str : Str -> Try(F32, [BadNumStr, ..])

Parse an F32 from a Str. Returns Err(BadNumStr) if the string is not a valid decimal number, or if the parsed value does not fit in an F32.

expect F32.to_str(F32.from_str("42.5").ok_or(0.0)) == "42.5"

expect F32.to_str(F32.from_str("-1.25").ok_or(0.0)) == "-1.25"

expect Try.is_err(F32.from_str("not a number"))
to_i8_wrap : F32 -> I8

Convert an F32 to an I8. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement. The result for NaN, inf, or -inf is implementation-defined.

expect F32.to_i8_wrap(42.7) == 42
to_i8_try : F32 -> Try(I8, [OutOfRange])

Convert an F32 to an I8, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero. Integer-part values from -128 to 127 succeed; other values return Err(OutOfRange).

expect F32.to_i8_try(42.7) == Ok(42)

expect F32.to_i8_try(200.0) == Err(OutOfRange)
to_i16_wrap : F32 -> I16

Convert an F32 to an I16. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -32768 to 32767 are preserved; other values wrap by truncating to the low 16 bits and reinterpreting them in two's complement. The result for NaN, inf, or -inf is implementation-defined.

expect F32.to_i16_wrap(42.5) == 42
to_i16_try : F32 -> Try(I16, [OutOfRange])

Convert an F32 to an I16, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero. Integer-part values from -32768 to 32767 succeed; other values return Err(OutOfRange).

expect F32.to_i16_try(42.5) == Ok(42)

expect F32.to_i16_try(40000.0) == Err(OutOfRange)
to_i32_wrap : F32 -> I32

Convert an F32 to an I32. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for NaN, inf, or -inf is implementation-defined.

expect F32.to_i32_wrap(42.5) == 42
to_i32_try : F32 -> Try(I32, [OutOfRange])

Convert an F32 to an I32, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_i32_try(42.5) == Ok(42)
to_i64_wrap : F32 -> I64

Convert an F32 to an I64. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for NaN, inf, or -inf is implementation-defined.

expect F32.to_i64_wrap(42.5) == 42
to_i64_try : F32 -> Try(I64, [OutOfRange])

Convert an F32 to an I64, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_i64_try(42.5) == Ok(42)
to_i128_wrap : F32 -> I128

Convert an F32 to an I128. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for NaN, inf, or -inf is implementation-defined.

expect F32.to_i128_wrap(42.5) == 42
to_i128_try : F32 -> Try(I128, [OutOfRange])

Convert an F32 to an I128, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_i128_try(42.5) == Ok(42)
to_u8_wrap : F32 -> U8

Convert an F32 to a U8. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F32.to_u8_wrap(42.7) == 42
to_u8_try : F32 -> Try(U8, [OutOfRange])

Convert an F32 to a U8, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_u8_try(42.7) == Ok(42)

expect F32.to_u8_try(-1.0) == Err(OutOfRange)
to_u16_wrap : F32 -> U16

Convert an F32 to a U16. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F32.to_u16_wrap(42.5) == 42
to_u16_try : F32 -> Try(U16, [OutOfRange])

Convert an F32 to a U16, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_u16_try(42.5) == Ok(42)
to_u32_wrap : F32 -> U32

Convert an F32 to a U32. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F32.to_u32_wrap(42.5) == 42
to_u32_try : F32 -> Try(U32, [OutOfRange])

Convert an F32 to a U32, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_u32_try(42.5) == Ok(42)
to_u64_wrap : F32 -> U64

Convert an F32 to a U64. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F32.to_u64_wrap(42.5) == 42
to_u64_try : F32 -> Try(U64, [OutOfRange])

Convert an F32 to a U64, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_u64_try(42.5) == Ok(42)
to_u128_wrap : F32 -> U128

Convert an F32 to a U128. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F32.to_u128_wrap(42.5) == 42
to_u128_try : F32 -> Try(U128, [OutOfRange])

Convert an F32 to a U128, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F32.to_u128_try(42.5) == Ok(42)
to_f64 : F32 -> F64

Convert an F32 to an F64. This is a safe widening conversion: every F32 value is exactly representable as an F64, including NaN, inf, and -inf.

expect F64.to_str(F32.to_f64(1.5)) == "1.5"
encode : F32, fmt -> Try(encoded, err) where { fmt.encode_f32 : fmt, F32 -> Try(encoded, err) }

Encode an F32 using a format that provides encode_f32

decode : src, fmt -> (Try(F32, err), src) where { fmt.decode_f32 : fmt, src -> (Try(F32, err), src) }

Decode an F32 using a format that provides decode_f32

F64

default : -> F64

Returns the default F64 value, which is 0.0. Functions like List.sum use this as the starting value when adding up a list of numbers.

expect F64.is_zero(F64.default())
highest : F64

The highest finite value representable by an F64, which is 1.7976931348623157e308.

expect F64.to_bits(F64.highest) == 9218868437227405311
lowest : F64

The lowest finite value representable by an F64, which is -1.7976931348623157e308.

expect F64.to_bits(F64.lowest) == 18442240474082181119
nan : F64

A quiet NaN F64 value.

expect F64.is_nan(F64.nan)
infinity : F64

Positive infinity as an F64.

expect F64.is_infinite(F64.infinity)

expect F64.infinity > F64.highest
e : F64

Euler's number as an F64.

expect F64.to_bits(F64.e) == 4613303445314885481
pi : F64

The circle constant pi as an F64.

expect F64.to_bits(F64.pi) == 4614256656552045848
tau : F64

The circle constant tau as an F64.

expect F64.to_bits(F64.tau) == 4618760256179416344
to_str : F64 -> Str

Convert an F64 to its decimal string representation.

expect F64.to_str(42.5) == "42.5"

expect F64.to_str(-42.5) == "-42.5"
to_bits : F64 -> U64

Return the raw IEEE 754 bit pattern of an F64.

expect F64.to_bits(F64.from_bits(4609434218613702656)) == 4609434218613702656

expect F64.from_bits(F64.to_bits(1.5)).to_str() == "1.5"
from_bits : U64 -> F64

Build an F64 from a raw IEEE 754 bit pattern.

expect F64.from_bits(F64.to_bits(-0.0)).to_bits() == F64.to_bits(-0.0)

expect F64.from_bits(0).to_bits() == 0
is_nan : F64 -> Bool

Returns Bool.True if the value is NaN.

expect F64.is_nan(F64.nan)

expect !F64.is_nan(1.0)
is_infinite : F64 -> Bool

Returns Bool.True if the value is positive or negative infinity.

expect F64.is_infinite(F64.infinity)

expect F64.is_infinite(F64.negate(F64.infinity))

expect !F64.is_infinite(1.0)
is_finite : F64 -> Bool

Returns Bool.True if the value is neither NaN nor infinity.

expect F64.is_finite(1.0)

expect !F64.is_finite(F64.infinity)

expect !F64.is_finite(F64.nan)
is_zero : F64 -> Bool

Returns Bool.True if the value is 0.0. Both positive and negative zero return Bool.True.

expect F64.is_zero(0.0)

expect !F64.is_zero(0.5)
is_float_eq : F64, F64 -> Bool

Returns Bool.True if two F64 values compare equal using the IEEE 754 == operation. NaN does not compare equal to itself.

expect F64.is_float_eq(1.5, 1.5)

expect !F64.is_float_eq(F64.nan, F64.nan)
is_negative : F64 -> Bool

Returns Bool.True if the value is less than 0.0.

expect F64.is_negative(-0.5)

expect !F64.is_negative(0.0)
is_positive : F64 -> Bool

Returns Bool.True if the value is greater than 0.0.

expect F64.is_positive(0.5)

expect !F64.is_positive(0.0)
is_gt : F64, F64 -> Bool

Returns Bool.True if the first value is greater than the second. Comparisons involving NaN always return Bool.False.

expect F64.is_gt(5.0, 3.0)

expect !F64.is_gt(3.0, 3.0)
is_gte : F64, F64 -> Bool

Returns Bool.True if the first value is greater than or equal to the second. Comparisons involving NaN always return Bool.False.

expect F64.is_gte(3.0, 3.0)

expect !F64.is_gte(2.0, 3.0)
is_lt : F64, F64 -> Bool

Returns Bool.True if the first value is less than the second. Comparisons involving NaN always return Bool.False.

expect F64.is_lt(3.0, 5.0)

expect !F64.is_lt(3.0, 3.0)
is_lte : F64, F64 -> Bool

Returns Bool.True if the first value is less than or equal to the second. Comparisons involving NaN always return Bool.False.

expect F64.is_lte(3.0, 3.0)

expect !F64.is_lte(5.0, 3.0)
max : F64, F64 -> F64

Returns the greater of two F64 values.

expect F64.is_float_eq(F64.max(5, 3), 5)

expect F64.is_float_eq(F64.max(-3, -1), -1)
min : F64, F64 -> F64

Returns the smaller of two F64 values.

expect F64.is_float_eq(F64.min(5, 3), 3)

expect F64.is_float_eq(F64.min(-3, -1), -3)
negate : F64 -> F64

Negate an F64. Flips the sign bit, so negating 0.0 produces -0.0 and negating NaN produces NaN.

expect F64.negate(3.5).to_str() == "-3.5"

expect F64.negate(-3.5).to_str() == "3.5"
abs : F64 -> F64

Return the absolute value of an F64. The result of abs(NaN) is NaN.

expect F64.abs(3.5).to_str() == "3.5"

expect F64.abs(-3.5).to_str() == "3.5"
sqrt : F64 -> F64

Return the square root of an F64. Crashes if the input is negative. NaN and positive infinity follow IEEE 754 behavior: NaN returns NaN, and positive infinity returns positive infinity.

expect F64.to_str(F64.sqrt(9.0)) == "3"

expect F64.to_str(F64.sqrt(2.25)) == "1.5"
sqrt_try : F64 -> Try(F64, [SqrtOfNegative, ..])

Return the square root of an F64, or Err(SqrtOfNegative) if the input is negative. NaN and positive infinity return Ok with the IEEE 754 result.

expect F64.is_float_eq(F64.sqrt_try(9.0).ok_or(0.0), 3.0)

expect F64.sqrt_try(-1.0) == Err(SqrtOfNegative)
pow : F64, F64 -> F64

Raise an F64 to an F64 power. The result follows IEEE 754 behavior and may be inf, -inf, or NaN, such as when a negative base has a non-integer exponent.

expect F64.pow(2.0, 3.0).to_str() == "8"

expect F64.pow(9.0, 0.5).to_str() == "3"
sin : F64 -> F64

Return the sine of an F64 angle in radians. NaN and infinite inputs follow IEEE 754 behavior and return NaN.

expect F64.sin(0.0).to_str() == "0"
cos : F64 -> F64

Return the cosine of an F64 angle in radians. NaN and infinite inputs follow IEEE 754 behavior and return NaN.

expect F64.cos(0.0).to_str() == "1"
tan : F64 -> F64

Return the tangent of an F64 angle in radians. The result follows IEEE 754 behavior and may be inf, -inf, or NaN; NaN and infinite inputs return NaN.

expect F64.tan(0.0).to_str() == "0"
asin : F64 -> F64

Return the arcsine of an F64 value in radians. Inputs outside -1.0 through 1.0, NaN, and infinities return NaN.

expect F64.asin(0.0).to_str() == "0"
acos : F64 -> F64

Return the arccosine of an F64 value in radians. Inputs outside -1.0 through 1.0, NaN, and infinities return NaN.

expect F64.acos(1.0).to_str() == "0"
atan : F64 -> F64

Return the arctangent of an F64 value in radians. NaN returns NaN; infinities follow IEEE 754 behavior.

expect F64.atan(0.0).to_str() == "0"
plus : F64, F64 -> F64

Add two F64 values. Addition is subject to IEEE 754 rounding; the result may be inf, -inf, or NaN.

expect F64.plus(1.5, 2.5).to_str() == "4"
minus : F64, F64 -> F64

Subtract the second F64 from the first. Subtraction is subject to IEEE 754 rounding; the result may be inf, -inf, or NaN.

expect F64.minus(5.0, 3.5).to_str() == "1.5"
times : F64, F64 -> F64

Multiply two F64 values. Multiplication is subject to IEEE 754 rounding; the result may be inf, -inf, or NaN.

expect F64.times(2.5, 4.0).to_str() == "10"
div_by : F64, F64 -> F64

Divide the first F64 by the second. Unlike integer division, division by zero does not crash: it produces inf, -inf, or NaN as specified by IEEE 754.

expect F64.div_by(10.0, 4.0).to_str() == "2.5"
div_trunc_by : F64, F64 -> F64

Divide the first F64 by the second, truncating toward zero to produce a whole-number F64 result.

expect F64.div_trunc_by(7.5, 2.0).to_str() == "3"

expect F64.div_trunc_by(-7.5, 2.0).to_str() == "-3"
rem_by : F64, F64 -> F64

Return the remainder of dividing the first F64 by the second. The sign of the result matches the sign of the dividend.

expect F64.rem_by(7.5, 2.0).to_str() == "1.5"

expect F64.rem_by(-7.5, 2.0).to_str() == "-1.5"
abs_diff : F64, F64 -> F64

Return the absolute difference between two F64 values.

expect F64.abs_diff(2.5, 5.0).to_str() == "2.5"

expect F64.abs_diff(-1.5, 5.0).to_str() == "6.5"
round_to_i8 : F64 -> I8

Round an F64 to the nearest I8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_i8(3.4) == 3
round_to_i16 : F64 -> I16

Round an F64 to the nearest I16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_i16(3.4) == 3
round_to_i32 : F64 -> I32

Round an F64 to the nearest I32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_i32(-3.6) == -4
round_to_i64 : F64 -> I64

Round an F64 to the nearest I64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_i64(7.2) == 7
round_to_i128 : F64 -> I128

Round an F64 to the nearest I128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_i128(7.2) == 7
round_to_u8 : F64 -> U8

Round an F64 to the nearest U8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_u8(3.4) == 3
round_to_u16 : F64 -> U16

Round an F64 to the nearest U16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_u16(3.4) == 3
round_to_u32 : F64 -> U32

Round an F64 to the nearest U32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_u32(7.2) == 7
round_to_u64 : F64 -> U64

Round an F64 to the nearest U64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_u64(7.2) == 7
round_to_u128 : F64 -> U128

Round an F64 to the nearest U128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.round_to_u128(7.2) == 7
floor_to_i8 : F64 -> I8

Round an F64 down to an I8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_i8(-3.2) == -4
floor_to_i16 : F64 -> I16

Round an F64 down to an I16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_i16(-3.2) == -4
floor_to_i32 : F64 -> I32

Round an F64 down to an I32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_i32(3.8) == 3
floor_to_i64 : F64 -> I64

Round an F64 down to an I64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_i64(3.8) == 3
floor_to_i128 : F64 -> I128

Round an F64 down to an I128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_i128(3.8) == 3
floor_to_u8 : F64 -> U8

Round an F64 down to a U8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_u8(3.8) == 3
floor_to_u16 : F64 -> U16

Round an F64 down to a U16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_u16(3.8) == 3
floor_to_u32 : F64 -> U32

Round an F64 down to a U32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_u32(3.8) == 3
floor_to_u64 : F64 -> U64

Round an F64 down to a U64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_u64(3.8) == 3
floor_to_u128 : F64 -> U128

Round an F64 down to a U128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.floor_to_u128(3.8) == 3
ceiling_to_i8 : F64 -> I8

Round an F64 up to an I8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_i8(-3.2) == -3
ceiling_to_i16 : F64 -> I16

Round an F64 up to an I16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_i16(-3.2) == -3
ceiling_to_i32 : F64 -> I32

Round an F64 up to an I32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_i32(3.2) == 4
ceiling_to_i64 : F64 -> I64

Round an F64 up to an I64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_i64(3.2) == 4
ceiling_to_i128 : F64 -> I128

Round an F64 up to an I128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_i128(3.2) == 4
ceiling_to_u8 : F64 -> U8

Round an F64 up to a U8. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_u8(3.2) == 4
ceiling_to_u16 : F64 -> U16

Round an F64 up to a U16. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_u16(3.2) == 4
ceiling_to_u32 : F64 -> U32

Round an F64 up to a U32. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_u32(3.2) == 4
ceiling_to_u64 : F64 -> U64

Round an F64 up to a U64. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_u64(3.2) == 4
ceiling_to_u128 : F64 -> U128

Round an F64 up to a U128. Crashes if the rounded value is out of range, NaN, or infinite.

expect F64.ceiling_to_u128(3.2) == 4
from_int_digits : List(U8) -> Try(F64, [OutOfRange])

Build an F64 from a list of base-10 digits, most significant first. Each element of the list must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an F64, or if any element is not a valid digit. The result is always non-negative; to build a negative value, F64.negate the result.

expect F64.to_str(F64.from_int_digits([1, 2, 3]).ok_or(0.0)) == "123"
from_dec_digits : (List(U8), List(U8)) -> Try(F64, [OutOfRange])

Build an F64 from a tuple of (integer digits, fractional digits), each as a list of base-10 digits most significant first. Each element of both lists must be a digit in the range 0 to 9. Returns Err(OutOfRange) if the resulting value does not fit in an F64, or if any element is not a valid digit. The result is always non-negative; to build a negative value, F64.negate the result.

expect F64.to_str(F64.from_dec_digits(([1, 2], [5])).ok_or(0.0)) == "12.5"
from_numeral : Numeral -> Try(F64, [InvalidNumeral(Str)])

Convert a numeric literal into an F64. This is the hook the compiler uses when a literal is given type F64; most code should parse user text with F64.from_str instead.

from_str : Str -> Try(F64, [BadNumStr, ..])

Parse an F64 from a Str. Returns Err(BadNumStr) if the string is not a valid decimal number, or if the parsed value does not fit in an F64.

expect F64.to_str(F64.from_str("42.5").ok_or(0.0)) == "42.5"

expect F64.to_str(F64.from_str("-1.25").ok_or(0.0)) == "-1.25"

expect Try.is_err(F64.from_str("not a number"))
to_i8_wrap : F64 -> I8

Convert an F64 to an I8. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -128 to 127 are preserved; other values wrap by truncating to the low 8 bits and reinterpreting them in two's complement. The result for NaN, inf, or -inf is implementation-defined.

expect F64.to_i8_wrap(42.7) == 42
to_i8_try : F64 -> Try(I8, [OutOfRange])

Convert an F64 to an I8, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero. Integer-part values from -128 to 127 succeed; other values return Err(OutOfRange).

expect F64.to_i8_try(42.7) == Ok(42)

expect F64.to_i8_try(200.0) == Err(OutOfRange)
to_i16_wrap : F64 -> I16

Convert an F64 to an I16. The fractional part is truncated toward zero; the integer part wraps on overflow. Integer-part values from -32768 to 32767 are preserved; other values wrap by truncating to the low 16 bits and reinterpreting them in two's complement. The result for NaN, inf, or -inf is implementation-defined.

expect F64.to_i16_wrap(42.5) == 42
to_i16_try : F64 -> Try(I16, [OutOfRange])

Convert an F64 to an I16, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero. Integer-part values from -32768 to 32767 succeed; other values return Err(OutOfRange).

expect F64.to_i16_try(42.5) == Ok(42)

expect F64.to_i16_try(40000.0) == Err(OutOfRange)
to_i32_wrap : F64 -> I32

Convert an F64 to an I32. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for NaN, inf, or -inf is implementation-defined.

expect F64.to_i32_wrap(42.5) == 42
to_i32_try : F64 -> Try(I32, [OutOfRange])

Convert an F64 to an I32, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_i32_try(42.5) == Ok(42)
to_i64_wrap : F64 -> I64

Convert an F64 to an I64. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for NaN, inf, or -inf is implementation-defined.

expect F64.to_i64_wrap(42.5) == 42
to_i64_try : F64 -> Try(I64, [OutOfRange])

Convert an F64 to an I64, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_i64_try(42.5) == Ok(42)
to_i128_wrap : F64 -> I128

Convert an F64 to an I128. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for NaN, inf, or -inf is implementation-defined.

expect F64.to_i128_wrap(42.5) == 42
to_i128_try : F64 -> Try(I128, [OutOfRange])

Convert an F64 to an I128, returning Err(OutOfRange) if the integer part does not fit, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_i128_try(42.5) == Ok(42)
to_u8_wrap : F64 -> U8

Convert an F64 to a U8. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F64.to_u8_wrap(42.7) == 42
to_u8_try : F64 -> Try(U8, [OutOfRange])

Convert an F64 to a U8, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_u8_try(42.7) == Ok(42)

expect F64.to_u8_try(-1.0) == Err(OutOfRange)
to_u16_wrap : F64 -> U16

Convert an F64 to a U16. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F64.to_u16_wrap(42.5) == 42
to_u16_try : F64 -> Try(U16, [OutOfRange])

Convert an F64 to a U16, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_u16_try(42.5) == Ok(42)
to_u32_wrap : F64 -> U32

Convert an F64 to a U32. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F64.to_u32_wrap(42.5) == 42
to_u32_try : F64 -> Try(U32, [OutOfRange])

Convert an F64 to a U32, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_u32_try(42.5) == Ok(42)
to_u64_wrap : F64 -> U64

Convert an F64 to a U64. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F64.to_u64_wrap(42.5) == 42
to_u64_try : F64 -> Try(U64, [OutOfRange])

Convert an F64 to a U64, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_u64_try(42.5) == Ok(42)
to_u128_wrap : F64 -> U128

Convert an F64 to a U128. The fractional part is truncated toward zero; the integer part wraps on overflow. The result for negative values, NaN, inf, or -inf is implementation-defined.

expect F64.to_u128_wrap(42.5) == 42
to_u128_try : F64 -> Try(U128, [OutOfRange])

Convert an F64 to a U128, returning Err(OutOfRange) if the integer part does not fit, if the value is negative, or if the value is NaN, inf, or -inf. The fractional part is truncated toward zero.

expect F64.to_u128_try(42.5) == Ok(42)
to_f32_wrap : F64 -> F32

Convert an F64 to an F32, narrowing the value. F64 has more precision and a wider range than F32, so this conversion may lose precision, and values that exceed the F32 range overflow to inf or -inf. NaN, inf, and -inf are preserved.

expect F32.to_str(F64.to_f32_wrap(1.5)) == "1.5"
to_f32_try : F64 -> Try(F32, [OutOfRange])

Convert an F64 to an F32, returning Err(OutOfRange) if the value's magnitude exceeds the F32 range (which would otherwise overflow to inf or -inf), or if the value is NaN. Values that fit in an F32 succeed, though precision may still be lost due to F32's smaller mantissa.

expect F32.to_str(F64.to_f32_try(1.5).ok_or(0.0)) == "1.5"
encode : F64, fmt -> Try(encoded, err) where { fmt.encode_f64 : fmt, F64 -> Try(encoded, err) }

Encode an F64 using a format that provides encode_f64

decode : src, fmt -> (Try(F64, err), src) where { fmt.decode_f64 : fmt, src -> (Try(F64, err), src) }

Decode an F64 using a format that provides decode_f64