README

marianoguerra/temporal/int128 does not have a README file

#
ParseInt128Error

pub suberror ParseInt128Error {
InvalidDigit
OutOfRange
} derive(Eq,
Debug
)

Parse failure for [of_string].

#
Int128

pub struct Int128 {
hi : Int64
lo : UInt64
} derive(Default, Eq, Hash)

A signed 128-bit integer, stored as a high signed 64-bit word and a low unsigned 64-bit word in two's complement form.

Temporal needs 128-bit arithmetic: epoch nanoseconds span ±8.64e21, and normalized time durations reach ±9.007199254740991999999999e24, both well beyond Int64.

Arithmetic wraps on overflow, matching the machine-integer semantics of the Rust i128 this port mirrors. Use the checked_* variants where overflow must be detected.
impl Compare for Int128
impl Show for Int128
impl Debug for Int128

#
Int128::abs

fn Int128::abs(self : Int128) -> Int128

Absolute value. min_value maps to itself, mirroring i128::wrapping_abs.

#
Int128::add

fn Int128::add(self : Int128, other : Int128) -> Int128

Wrapping addition.

#
Int128::bit_length

fn Int128::bit_length(self : Int128) -> Int

Returns the number of significant bits in the magnitude, or 0 for zero.

test {
inspect(@int128.of_int(0).bit_length(), content="0")
inspect(@int128.of_int(1).bit_length(), content="1")
inspect(@int128.of_int(-255).bit_length(), content="8")
}

#
Int128::checked_add

fn Int128::checked_add(self : Int128, other : Int128) -> Int128?

Addition that reports overflow instead of wrapping.

#
Int128::checked_mul

fn Int128::checked_mul(self : Int128, other : Int128) -> Int128?

Multiplication that reports overflow instead of wrapping.

#
Int128::checked_sub

fn Int128::checked_sub(self : Int128, other : Int128) -> Int128?

Subtraction that reports overflow instead of wrapping.

#
Int128::clamp

fn Int128::clamp(self : Int128, low : Int128, high : Int128) -> Int128

Clamps the value into low ..= high.

#
Int128::div

fn Int128::div(self : Int128, other : Int128) -> Int128

Truncating division.

#
Int128::div_euclid

fn Int128::div_euclid(self : Int128, other : Int128) -> Int128

Euclidean division: rounds toward negative infinity for a positive divisor.

#
Int128::div_rem

fn Int128::div_rem(self : Int128, other : Int128) -> (Int128, Int128)

Truncating division and remainder, as Rust's / and % on i128.

The remainder takes the sign of the dividend.

Panics

Panics when other is zero.

#
Int128::div_rem_euclid

fn Int128::div_rem_euclid(self : Int128, other : Int128) -> (Int128, Int128)

Euclidean division and remainder, as Rust's div_euclid / rem_euclid.

The remainder is always non-negative. Temporal's spec text is written in terms of floor and modulo, so this is the variant most of the port uses.

#
Int128::from_words

fn Int128::from_words(hi : Int64, lo : UInt64) -> Int128

Builds an Int128 from its raw high and low words.

#
Int128::high

fn Int128::high(self : Int128) -> Int64

Returns the high (most significant, signed) 64-bit word.

#
Int128::is_negative

fn Int128::is_negative(self : Int128) -> Bool

Returns whether the value is strictly negative.

#
Int128::is_zero

fn Int128::is_zero(self : Int128) -> Bool

Returns whether the value is zero.

#
Int128::land

fn Int128::land(self : Int128, other : Int128) -> Int128

Bitwise and.

#
Int128::lnot

fn Int128::lnot(self : Int128) -> Int128

Bitwise complement.

#
Int128::lor

fn Int128::lor(self : Int128, other : Int128) -> Int128

Bitwise or.

#
Int128::low

fn Int128::low(self : Int128) -> UInt64

Returns the low (least significant, unsigned) 64-bit word.

#
Int128::max

fn Int128::max(self : Int128, other : Int128) -> Int128

Returns the larger of two values.

#
Int128::min

fn Int128::min(self : Int128, other : Int128) -> Int128

Returns the smaller of two values.

#
Int128::mul

fn Int128::mul(self : Int128, other : Int128) -> Int128

Wrapping multiplication.

#
Int128::neg

fn Int128::neg(self : Int128) -> Int128

Two's-complement negation. min_value negates to itself.

#
Int128::rem

fn Int128::rem(self : Int128, other : Int128) -> Int128

Remainder of truncating division; takes the sign of the dividend.

#
Int128::rem_euclid

fn Int128::rem_euclid(self : Int128, other : Int128) -> Int128

Euclidean remainder; always in 0 ..< other.abs().

#
Int128::shl

fn Int128::shl(self : Int128, n : Int) -> Int128

Logical left shift by n bits, where n is taken modulo 128.

#
Int128::shr

fn Int128::shr(self : Int128, n : Int) -> Int128

Arithmetic (sign-propagating) right shift by n bits, n taken modulo 128.

#
Int128::signum

fn Int128::signum(self : Int128) -> Int

Returns -1, 0, or 1 according to the sign of the value.

#
Int128::sub

fn Int128::sub(self : Int128, other : Int128) -> Int128

Wrapping subtraction.

#
Int128::to_double

fn Int128::to_double(self : Int128) -> Double

Converts to the nearest Double, rounding to nearest with ties to even.

Values beyond 2^53 cannot be represented exactly; the result is the correctly rounded neighbour, matching Rust's i128 as f64.

#
Int128::to_int

fn Int128::to_int(self : Int128) -> Int?

Converts to Int, returning None when the value does not fit.

#
Int128::to_int64

fn Int128::to_int64(self : Int128) -> Int64?

Converts to Int64, returning None when the value does not fit.

#
Int128::to_int64_saturating

fn Int128::to_int64_saturating(self : Int128) -> Int64

Converts to Int64, saturating at the Int64 bounds.

#
max_value

let max_value : Int128

The largest representable value, 2^127 - 1.

#
min_value

let min_value : Int128

The smallest representable value, -2^127.

#
of_double

fn of_double(value : Double) -> Int128?

Converts a Double to Int128 by truncating toward zero.

Returns None for values that are not finite or whose truncation falls outside the 128-bit range.

#
of_int

fn of_int(v : Int) -> Int128

Sign-extends an Int.

#
of_int64

fn of_int64(v : Int64) -> Int128

Sign-extends an Int64.

test {
inspect(@int128.of_int64(-5L), content="-5")
}

#
of_string

fn of_string(s : String) -> Int128 raise ParseInt128Error

Parses a decimal integer, with an optional leading + or -.

test {
inspect(
@int128.of_string("-170141183460469231731687303715884105728"),
content="-170141183460469231731687303715884105728",
)
}

#
of_uint64

fn of_uint64(v : UInt64) -> Int128

Zero-extends a UInt64.

#
one

let one : Int128

The value 1.

#
zero

let zero : Int128

The value 0.

Source Files