Numeral
is_negative : Numeral -> Bool
digits_before_pt : Numeral -> List(U8)
digits_after_pt : Numeral -> List(U8)
digits_after_pt_count : Numeral -> U64
is_negative : Numeral -> Bool
digits_before_pt : Numeral -> List(U8)
digits_after_pt : Numeral -> List(U8)
digits_after_pt_count : Numeral -> U64
The highest value representable by a U8, which is 255.
expect U8.highest == 255
The lowest value representable by a U8, which is 0.
expect U8.lowest == 0
Convert a U8 to its decimal string representation.
expect U8.to_str(42) == "42"
Returns Bool.True if the value is 0.
expect U8.is_zero(0)
expect !U8.is_zero(7)
Returns Bool.True if the two values are equal.
expect U8.is_eq(3, 3)
expect !U8.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect U8.is_gt(5, 3)
expect !U8.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect U8.is_lt(3, 5)
expect !U8.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect U8.is_even(4)
expect !U8.is_even(5)
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)
Returns the greater of two U8 values.
expect U8.max(5, 3) == 5
Returns the smaller of two U8 values.
expect U8.min(5, 3) == 3
Add two U8 values.
expect U8.plus(2, 3) == 5
steps_between : U8, U8 -> [Known(U64), Unknown]
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
Subtract the second U8 from the first.
expect U8.minus(5, 3) == 2
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
Multiply two U8 values.
expect U8.times(4, 3) == 12
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
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)
Divide the first U8 by the second, returning Err(DivByZero)
instead of crashing if the divisor is zero.
div_ceil_by : U8, U8 -> U8
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
Return the remainder of dividing the first U8 by the second.
expect U8.rem_by(7, 3) == 1
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])
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.
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)) == []
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
Encode a U8 using a format that provides encode_u8
Decode a U8 using a format that provides decode_u8
The highest value representable by an I8, which is 127.
expect I8.highest == 127
The lowest value representable by an I8, which is -128.
expect I8.lowest == -128
Convert an I8 to its decimal string representation.
expect I8.to_str(42) == "42"
expect I8.to_str(-42) == "-42"
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)
Returns Bool.True if the two values are equal.
expect I8.is_eq(3, 3)
expect !I8.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect I8.is_gt(5, 3)
expect !I8.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect I8.is_lt(3, 5)
expect !I8.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect I8.is_even(4)
expect !I8.is_even(5)
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)
Returns the greater of two I8 values.
expect I8.max(5, 3) == 5
expect I8.max(-3, -1) == -1
Returns the smaller of two I8 values.
expect I8.min(5, 3) == 3
expect I8.min(-3, -1) == -3
Add two I8 values.
expect I8.plus(2, 3) == 5
steps_between : I8, I8 -> [Known(U64), Unknown]
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
Subtract the second I8 from the first.
expect I8.minus(5, 3) == 2
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
Multiply two I8 values.
expect I8.times(4, 3) == 12
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
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)
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
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
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
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
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
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)) == []
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.
to_u8_wrap : I8 -> U8
to_u16_wrap : I8 -> U16
to_u16_try : I8 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : I8 -> U32
to_u32_try : I8 -> Try(U32, [OutOfRange, ..])
to_u64_wrap : I8 -> U64
to_u64_try : I8 -> Try(U64, [OutOfRange, ..])
to_u128_wrap : I8 -> U128
to_u128_try : I8 -> Try(U128, [OutOfRange, ..])
Encode an I8 using a format that provides encode_i8
Decode an I8 using a format that provides decode_i8
The highest value representable by a U16, which is 65535.
expect U16.highest == 65535
The lowest value representable by a U16, which is 0.
expect U16.lowest == 0
Convert a U16 to its decimal string representation.
expect U16.to_str(42) == "42"
Returns Bool.True if the value is 0.
expect U16.is_zero(0)
expect !U16.is_zero(7)
Returns Bool.True if the two values are equal.
expect U16.is_eq(3, 3)
expect !U16.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect U16.is_gt(5, 3)
expect !U16.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect U16.is_lt(3, 5)
expect !U16.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect U16.is_even(4)
expect !U16.is_even(5)
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)
Returns the greater of two U16 values.
expect U16.max(5, 3) == 5
Returns the smaller of two U16 values.
expect U16.min(5, 3) == 3
Add two U16 values.
expect U16.plus(2, 3) == 5
steps_between : U16, U16 -> [Known(U64), Unknown]
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
Subtract the second U16 from the first.
expect U16.minus(5, 3) == 2
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
Multiply two U16 values.
expect U16.times(4, 3) == 12
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
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)
Divide the first U16 by the second, returning Err(DivByZero)
instead of crashing if the divisor is zero.
div_ceil_by : U16, U16 -> U16
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
Return the remainder of dividing the first U16 by the second.
expect U16.rem_by(7, 3) == 1
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
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 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
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)) == []
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.
to_i8_wrap : U16 -> I8
to_i16_wrap : U16 -> I16
to_i16_try : U16 -> Try(I16, [OutOfRange, ..])
to_u8_wrap : U16 -> U8
The highest value representable by an I16, which is 32767.
expect I16.highest == 32767
The lowest value representable by an I16, which is -32768.
expect I16.lowest == -32768
Convert an I16 to its decimal string representation.
expect I16.to_str(42) == "42"
expect I16.to_str(-42) == "-42"
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)
Returns Bool.True if the two values are equal.
expect I16.is_eq(3, 3)
expect !I16.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect I16.is_gt(5, 3)
expect !I16.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect I16.is_lt(3, 5)
expect !I16.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect I16.is_even(4)
expect !I16.is_even(5)
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)
Returns the greater of two I16 values.
expect I16.max(5, 3) == 5
expect I16.max(-3, -1) == -1
Returns the smaller of two I16 values.
expect I16.min(5, 3) == 3
expect I16.min(-3, -1) == -3
Add two I16 values.
expect I16.plus(2, 3) == 5
steps_between : I16, I16 -> [Known(U64), Unknown]
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
Subtract the second I16 from the first.
expect I16.minus(5, 3) == 2
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
Multiply two I16 values.
expect I16.times(4, 3) == 12
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
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)
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
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
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
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
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 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
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)) == []
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.
to_i8_wrap : I16 -> I8
to_u8_wrap : I16 -> U8
to_u16_wrap : I16 -> U16
to_u16_try : I16 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : I16 -> U32
to_u32_try : I16 -> Try(U32, [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, ..])
to_u128_wrap : I16 -> U128
to_u128_try : I16 -> Try(U128, [OutOfRange, ..])
The highest value representable by a U32, which is 4294967295.
expect U32.highest == 4294967295
The lowest value representable by a U32, which is 0.
expect U32.lowest == 0
Convert a U32 to its decimal string representation.
expect U32.to_str(42) == "42"
Returns Bool.True if the value is 0.
expect U32.is_zero(0)
expect !U32.is_zero(7)
Returns Bool.True if the two values are equal.
expect U32.is_eq(3, 3)
expect !U32.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect U32.is_gt(5, 3)
expect !U32.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect U32.is_lt(3, 5)
expect !U32.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect U32.is_even(4)
expect !U32.is_even(5)
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)
Returns the greater of two U32 values.
expect U32.max(5, 3) == 5
Returns the smaller of two U32 values.
expect U32.min(5, 3) == 3
Add two U32 values.
expect U32.plus(2, 3) == 5
steps_between : U32, U32 -> [Known(U64), Unknown]
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
Subtract the second U32 from the first.
expect U32.minus(5, 3) == 2
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
Multiply two U32 values.
expect U32.times(4, 3) == 12
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
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)
Divide the first U32 by the second, returning Err(DivByZero)
instead of crashing if the divisor is zero.
div_ceil_by : U32, U32 -> U32
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
Return the remainder of dividing the first U32 by the second.
expect U32.rem_by(7, 3) == 1
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
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 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
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)) == []
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.
to_i8_wrap : U32 -> I8
to_i16_wrap : U32 -> I16
to_i16_try : U32 -> Try(I16, [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, ..])
to_u8_wrap : U32 -> U8
to_u16_wrap : U32 -> U16
to_u16_try : U32 -> Try(U16, [OutOfRange, ..])
The highest value representable by an I32, which is 2147483647.
expect I32.highest == 2147483647
The lowest value representable by an I32, which is -2147483648.
expect I32.lowest == -2147483648
Convert an I32 to its decimal string representation.
expect I32.to_str(42) == "42"
expect I32.to_str(-42) == "-42"
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)
Returns Bool.True if the two values are equal.
expect I32.is_eq(3, 3)
expect !I32.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect I32.is_gt(5, 3)
expect !I32.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect I32.is_lt(3, 5)
expect !I32.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect I32.is_even(4)
expect !I32.is_even(5)
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)
Returns the greater of two I32 values.
expect I32.max(5, 3) == 5
expect I32.max(-3, -1) == -1
Returns the smaller of two I32 values.
expect I32.min(5, 3) == 3
expect I32.min(-3, -1) == -3
Add two I32 values.
expect I32.plus(2, 3) == 5
steps_between : I32, I32 -> [Known(U64), Unknown]
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
Subtract the second I32 from the first.
expect I32.minus(5, 3) == 2
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
Multiply two I32 values.
expect I32.times(4, 3) == 12
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
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)
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
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
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
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
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 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
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)) == []
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.
to_i8_wrap : I32 -> I8
to_i16_wrap : I32 -> I16
to_i16_try : I32 -> Try(I16, [OutOfRange, ..])
to_u8_wrap : I32 -> U8
to_u16_wrap : I32 -> U16
to_u16_try : I32 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : I32 -> U32
to_u32_try : I32 -> Try(U32, [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, ..])
to_u128_wrap : I32 -> U128
to_u128_try : I32 -> Try(U128, [OutOfRange, ..])
The highest value representable by a U64, which is
18446744073709551615.
expect U64.highest == 18446744073709551615
The lowest value representable by a U64, which is 0.
expect U64.lowest == 0
Convert a U64 to its decimal string representation.
expect U64.to_str(42) == "42"
Returns Bool.True if the value is 0.
expect U64.is_zero(0)
expect !U64.is_zero(7)
Returns Bool.True if the two values are equal.
expect U64.is_eq(3, 3)
expect !U64.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect U64.is_gt(5, 3)
expect !U64.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect U64.is_lt(3, 5)
expect !U64.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect U64.is_even(4)
expect !U64.is_even(5)
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)
Returns the greater of two U64 values.
expect U64.max(5, 3) == 5
Returns the smaller of two U64 values.
expect U64.min(5, 3) == 3
Add two U64 values.
expect U64.plus(2, 3) == 5
steps_between : U64, U64 -> [Known(U64), Unknown]
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
Subtract the second U64 from the first.
expect U64.minus(5, 3) == 2
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
Multiply two U64 values.
expect U64.times(4, 3) == 12
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
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)
Divide the first U64 by the second, returning Err(DivByZero)
instead of crashing if the divisor is zero.
div_ceil_by : U64, U64 -> U64
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
Return the remainder of dividing the first U64 by the second.
expect U64.rem_by(7, 3) == 1
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
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 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
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)) == []
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.
to_i8_wrap : U64 -> I8
to_i16_wrap : U64 -> I16
to_i16_try : U64 -> Try(I16, [OutOfRange, ..])
to_i32_wrap : U64 -> I32
to_i32_try : U64 -> Try(I32, [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, ..])
to_u8_wrap : U64 -> U8
to_u16_wrap : U64 -> U16
to_u16_try : U64 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : U64 -> U32
to_u32_try : U64 -> Try(U32, [OutOfRange, ..])
The highest value representable by an I64, which is
9223372036854775807.
expect I64.highest == 9223372036854775807
The lowest value representable by an I64, which is
-9223372036854775808.
expect I64.lowest == -9223372036854775808
Convert an I64 to its decimal string representation.
expect I64.to_str(42) == "42"
expect I64.to_str(-42) == "-42"
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)
Returns Bool.True if the two values are equal.
expect I64.is_eq(3, 3)
expect !I64.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect I64.is_gt(5, 3)
expect !I64.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect I64.is_lt(3, 5)
expect !I64.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect I64.is_even(4)
expect !I64.is_even(5)
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)
Returns the greater of two I64 values.
expect I64.max(5, 3) == 5
expect I64.max(-3, -1) == -1
Returns the smaller of two I64 values.
expect I64.min(5, 3) == 3
expect I64.min(-3, -1) == -3
Add two I64 values.
expect I64.plus(2, 3) == 5
steps_between : I64, I64 -> [Known(U64), Unknown]
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
Subtract the second I64 from the first.
expect I64.minus(5, 3) == 2
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
Multiply two I64 values.
expect I64.times(4, 3) == 12
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
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)
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
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
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
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
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 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
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)) == []
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.
to_i8_wrap : I64 -> I8
to_i16_wrap : I64 -> I16
to_i16_try : I64 -> Try(I16, [OutOfRange, ..])
to_i32_wrap : I64 -> I32
to_i32_try : I64 -> Try(I32, [OutOfRange, ..])
to_u8_wrap : I64 -> U8
to_u16_wrap : I64 -> U16
to_u16_try : I64 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : I64 -> U32
to_u32_try : I64 -> Try(U32, [OutOfRange, ..])
to_u64_wrap : I64 -> U64
to_u64_try : I64 -> Try(U64, [OutOfRange, ..])
to_u128_wrap : I64 -> U128
to_u128_try : I64 -> Try(U128, [OutOfRange, ..])
The highest value representable by a U128, which is
340282366920938463463374607431768211455.
expect U128.highest == 340282366920938463463374607431768211455
The lowest value representable by a U128, which is 0.
expect U128.lowest == 0
Convert a U128 to its decimal string representation.
expect U128.to_str(42) == "42"
Returns Bool.True if the value is 0.
expect U128.is_zero(0)
expect !U128.is_zero(7)
Returns Bool.True if the two values are equal.
expect U128.is_eq(3, 3)
expect !U128.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect U128.is_gt(5, 3)
expect !U128.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect U128.is_lt(3, 5)
expect !U128.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect U128.is_even(4)
expect !U128.is_even(5)
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)
Returns the greater of two U128 values.
expect U128.max(5, 3) == 5
Returns the smaller of two U128 values.
expect U128.min(5, 3) == 3
Add two U128 values.
expect U128.plus(2, 3) == 5
steps_between : U128, U128 -> [Known(U64), Unknown]
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
Subtract the second U128 from the first.
expect U128.minus(5, 3) == 2
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
Multiply two U128 values.
expect U128.times(4, 3) == 12
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
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)
Divide the first U128 by the second, returning Err(DivByZero)
instead of crashing if the divisor is zero.
div_ceil_by : U128, U128 -> U128
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
Return the remainder of dividing the first U128 by the second.
expect U128.rem_by(7, 3) == 1
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
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 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 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
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)) == []
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.
to_i8_wrap : U128 -> I8
to_i16_wrap : U128 -> I16
to_i16_try : U128 -> Try(I16, [OutOfRange, ..])
to_i32_wrap : U128 -> I32
to_i32_try : U128 -> Try(I32, [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, ..])
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
to_u16_wrap : U128 -> U16
to_u16_try : U128 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : U128 -> U32
to_u32_try : U128 -> Try(U32, [OutOfRange, ..])
to_u64_wrap : U128 -> U64
to_u64_try : U128 -> Try(U64, [OutOfRange, ..])
to_dec_try : U128 -> Try(Dec, [OutOfRange])
The highest value representable by an I128, which is
170141183460469231731687303715884105727.
expect I128.highest == 170141183460469231731687303715884105727
The lowest value representable by an I128, which is
-170141183460469231731687303715884105728.
expect I128.lowest == -170141183460469231731687303715884105728
Convert an I128 to its decimal string representation.
expect I128.to_str(42) == "42"
expect I128.to_str(-42) == "-42"
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)
Returns Bool.True if the two values are equal.
expect I128.is_eq(3, 3)
expect !I128.is_eq(3, 4)
Returns Bool.True if the first value is greater than the second.
expect I128.is_gt(5, 3)
expect !I128.is_gt(3, 3)
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)
Returns Bool.True if the first value is less than the second.
expect I128.is_lt(3, 5)
expect !I128.is_lt(3, 3)
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 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
Returns Bool.True if the value is evenly divisible by 2.
expect I128.is_even(4)
expect !I128.is_even(5)
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)
Returns the greater of two I128 values.
expect I128.max(5, 3) == 5
expect I128.max(-3, -1) == -1
Returns the smaller of two I128 values.
expect I128.min(5, 3) == 3
expect I128.min(-3, -1) == -3
Add two I128 values.
expect I128.plus(2, 3) == 5
steps_between : I128, I128 -> [Known(U64), Unknown]
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
Subtract the second I128 from the first.
expect I128.minus(5, 3) == 2
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
Multiply two I128 values.
expect I128.times(4, 3) == 12
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
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)
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
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
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
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
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 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 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
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)) == []
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.
to_i8_wrap : I128 -> I8
to_i16_wrap : I128 -> I16
to_i16_try : I128 -> Try(I16, [OutOfRange, ..])
to_i32_wrap : I128 -> I32
to_i32_try : I128 -> Try(I32, [OutOfRange, ..])
to_i64_wrap : I128 -> I64
to_i64_try : I128 -> Try(I64, [OutOfRange, ..])
to_u8_wrap : I128 -> U8
to_u16_wrap : I128 -> U16
to_u16_try : I128 -> Try(U16, [OutOfRange, ..])
to_u32_wrap : I128 -> U32
to_u32_try : I128 -> Try(U32, [OutOfRange, ..])
to_u64_wrap : I128 -> U64
to_u64_try : I128 -> Try(U64, [OutOfRange, ..])
to_u128_wrap : I128 -> U128
to_u128_try : I128 -> Try(U128, [OutOfRange, ..])
to_dec_try : I128 -> Try(Dec, [OutOfRange])
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
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
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
Euler's number as a Dec, truncated to 18 fractional decimal places.
The circle constant pi as a Dec, truncated to 18 fractional decimal places.
The circle constant tau as a Dec, truncated to 18 fractional decimal places.
Convert a Dec to its decimal string representation.
expect Dec.to_str(42.5) == "42.5"
expect Dec.to_str(-42.5) == "-42.5"
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)
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)
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)
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)
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)
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 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
Returns the greater of two Dec values.
expect Dec.max(5, 3) == 5
expect Dec.max(-3, -1) == -1
Returns the smaller of two Dec values.
expect Dec.min(5, 3) == 3
expect Dec.min(-3, -1) == -3
Negate a Dec.
expect Dec.negate(3.5) == -3.5
expect Dec.negate(-3.5) == 3.5
Return the absolute value of a Dec.
expect Dec.abs(3.5) == 3.5
expect Dec.abs(-3.5) == 3.5
Add two Dec values.
expect Dec.plus(1.5, 2.5) == 4.0
Add two Dec values, returning Err(Overflow) instead of wrapping
if the result is outside Dec.lowest through Dec.highest.
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
Subtract the second Dec from the first.
expect Dec.minus(5.0, 3.5) == 1.5
Subtract the second Dec from the first, returning
Err(Overflow) instead of wrapping if the result is outside
Dec.lowest through Dec.highest.
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_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
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.
Return the sine of a Dec angle in radians. This is a fixed-point approximation limited to 18 fractional decimal places.
Return the cosine of a Dec angle in radians. This is a fixed-point approximation limited to 18 fractional decimal places.
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.
Return the arcsine of a Dec value in radians. Crashes if the
input is outside -1.0 through 1.0.
Return the arccosine of a Dec value in radians. Crashes if the
input is outside -1.0 through 1.0.
Return the arctangent of a Dec value in radians. This is a fixed-point approximation limited to 18 fractional decimal places.
div_trunc_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
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_to_i16 : Dec -> I16
round_to_i32 : Dec -> I32
round_to_i64 : Dec -> I64
round_to_i128 : Dec -> I128
round_to_u8 : Dec -> U8
round_to_u16 : Dec -> U16
round_to_u32 : Dec -> U32
round_to_u64 : Dec -> U64
round_to_u128 : Dec -> U128
floor_to_i8 : Dec -> I8
floor_to_i16 : Dec -> I16
floor_to_i32 : Dec -> I32
floor_to_i64 : Dec -> I64
floor_to_i128 : Dec -> I128
floor_to_u8 : Dec -> U8
floor_to_u16 : Dec -> U16
floor_to_u32 : Dec -> U32
floor_to_u64 : Dec -> U64
floor_to_u128 : Dec -> U128
ceiling_to_i8 : Dec -> I8
ceiling_to_i16 : Dec -> I16
ceiling_to_i32 : Dec -> I32
ceiling_to_i64 : Dec -> I64
ceiling_to_i128 : Dec -> I128
ceiling_to_u8 : Dec -> U8
ceiling_to_u16 : Dec -> U16
ceiling_to_u32 : Dec -> U32
ceiling_to_u64 : Dec -> U64
ceiling_to_u128 : Dec -> U128
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)
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.
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_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])
to_i128_wrap : Dec -> I128
to_i128_try : Dec -> Try(I128, [OutOfRange])
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_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])
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])
to_u128_wrap : Dec -> U128
to_u128_try : Dec -> Try(U128, [OutOfRange])
to_f32_wrap : Dec -> F32
to_f32_try : Dec -> Try(F32, [OutOfRange])
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)) == []
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 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
The highest finite value representable by an F32, which is
3.40282347e38.
expect F32.to_bits(F32.highest) == 2139095039
The lowest finite value representable by an F32, which is
-3.40282347e38.
expect F32.to_bits(F32.lowest) == 4286578687
A quiet NaN F32 value.
expect F32.is_nan(F32.nan)
Positive infinity as an F32.
expect F32.is_infinite(F32.infinity)
expect F32.infinity > F32.highest
Euler's number as an F32.
expect F32.to_bits(F32.e) == 1076754516
The circle constant pi as an F32.
expect F32.to_bits(F32.pi) == 1078530011
The circle constant tau as an F32.
expect F32.to_bits(F32.tau) == 1086918619
Convert an F32 to its decimal string representation.
expect F32.to_str(42.5) == "42.5"
expect F32.to_str(-42.5) == "-42.5"
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"
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
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)
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)
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)
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)
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)
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)
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)
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)
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 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"
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"
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"
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)
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"
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"
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"
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"
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"
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"
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"
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"
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"
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
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"
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_to_i16 : F32 -> I16
round_to_i32 : F32 -> I32
round_to_i64 : F32 -> I64
round_to_i128 : F32 -> I128
round_to_u8 : F32 -> U8
round_to_u16 : F32 -> U16
round_to_u32 : F32 -> U32
round_to_u64 : F32 -> U64
round_to_u128 : F32 -> U128
floor_to_i8 : F32 -> I8
floor_to_i16 : F32 -> I16
floor_to_i32 : F32 -> I32
floor_to_i64 : F32 -> I64
floor_to_i128 : F32 -> I128
floor_to_u8 : F32 -> U8
floor_to_u16 : F32 -> U16
floor_to_u32 : F32 -> U32
floor_to_u64 : F32 -> U64
floor_to_u128 : F32 -> U128
ceiling_to_i8 : F32 -> I8
ceiling_to_i16 : F32 -> I16
ceiling_to_i32 : F32 -> I32
ceiling_to_i64 : F32 -> I64
ceiling_to_i128 : F32 -> I128
ceiling_to_u8 : F32 -> U8
ceiling_to_u16 : F32 -> U16
ceiling_to_u32 : F32 -> U32
ceiling_to_u64 : F32 -> U64
ceiling_to_u128 : F32 -> U128
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"
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.
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
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
to_i32_try : F32 -> Try(I32, [OutOfRange])
to_i64_wrap : F32 -> I64
to_i64_try : F32 -> Try(I64, [OutOfRange])
to_i128_wrap : F32 -> I128
to_i128_try : F32 -> Try(I128, [OutOfRange])
to_u8_wrap : F32 -> U8
to_u16_wrap : F32 -> U16
to_u16_try : F32 -> Try(U16, [OutOfRange])
to_u32_wrap : F32 -> U32
to_u32_try : F32 -> Try(U32, [OutOfRange])
to_u64_wrap : F32 -> U64
to_u64_try : F32 -> Try(U64, [OutOfRange])
to_u128_wrap : F32 -> U128
to_u128_try : F32 -> Try(U128, [OutOfRange])
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
The highest finite value representable by an F64, which is
1.7976931348623157e308.
expect F64.to_bits(F64.highest) == 9218868437227405311
The lowest finite value representable by an F64, which is
-1.7976931348623157e308.
expect F64.to_bits(F64.lowest) == 18442240474082181119
A quiet NaN F64 value.
expect F64.is_nan(F64.nan)
Positive infinity as an F64.
expect F64.is_infinite(F64.infinity)
expect F64.infinity > F64.highest
Euler's number as an F64.
expect F64.to_bits(F64.e) == 4613303445314885481
The circle constant pi as an F64.
expect F64.to_bits(F64.pi) == 4614256656552045848
The circle constant tau as an F64.
expect F64.to_bits(F64.tau) == 4618760256179416344
Convert an F64 to its decimal string representation.
expect F64.to_str(42.5) == "42.5"
expect F64.to_str(-42.5) == "-42.5"
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"
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
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)
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)
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)
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)
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)
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)
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)
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)
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 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"
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"
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"
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)
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"
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"
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"
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"
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"
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"
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"
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"
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"
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
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"
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_to_i16 : F64 -> I16
round_to_i32 : F64 -> I32
round_to_i64 : F64 -> I64
round_to_i128 : F64 -> I128
round_to_u8 : F64 -> U8
round_to_u16 : F64 -> U16
round_to_u32 : F64 -> U32
round_to_u64 : F64 -> U64
round_to_u128 : F64 -> U128
floor_to_i8 : F64 -> I8
floor_to_i16 : F64 -> I16
floor_to_i32 : F64 -> I32
floor_to_i64 : F64 -> I64
floor_to_i128 : F64 -> I128
floor_to_u8 : F64 -> U8
floor_to_u16 : F64 -> U16
floor_to_u32 : F64 -> U32
floor_to_u64 : F64 -> U64
floor_to_u128 : F64 -> U128
ceiling_to_i8 : F64 -> I8
ceiling_to_i16 : F64 -> I16
ceiling_to_i32 : F64 -> I32
ceiling_to_i64 : F64 -> I64
ceiling_to_i128 : F64 -> I128
ceiling_to_u8 : F64 -> U8
ceiling_to_u16 : F64 -> U16
ceiling_to_u32 : F64 -> U32
ceiling_to_u64 : F64 -> U64
ceiling_to_u128 : F64 -> U128
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"
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.
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
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
to_i32_try : F64 -> Try(I32, [OutOfRange])
to_i64_wrap : F64 -> I64
to_i64_try : F64 -> Try(I64, [OutOfRange])
to_i128_wrap : F64 -> I128
to_i128_try : F64 -> Try(I128, [OutOfRange])
to_u8_wrap : F64 -> U8
to_u16_wrap : F64 -> U16
to_u16_try : F64 -> Try(U16, [OutOfRange])
to_u32_wrap : F64 -> U32
to_u32_try : F64 -> Try(U32, [OutOfRange])
to_u64_wrap : F64 -> U64
to_u64_try : F64 -> Try(U64, [OutOfRange])
to_u128_wrap : F64 -> U128
to_u128_try : F64 -> Try(U128, [OutOfRange])
to_f32_wrap : F64 -> F32
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 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