Primitive Type i128
Expand description
The 128-bit signed integer type.
§ABI compatibility
Rust’s i128 is expected to be ABI-compatible with C’s __int128 on platforms where the type
is available, which includes most 64-bit architectures. If any platforms that do not specify
__int128 are updated to introduce it, the Rust i128 ABI on relevant targets will be changed
to match.
It is important to note that in C, __int128 is not the same as _BitInt(128), and the two
types are allowed to have different ABIs. In particular, on x86, __int128 and _BitInt(128)
do not use the same alignment. i128 is intended to always match __int128 and does not
attempt to match _BitInt(128) on platforms without __int128.
Implementations§
Source§impl i128
impl i128
1.43.0 · Sourcepub const MIN: i128
pub const MIN: i128
The smallest value that can be represented by this integer type (−2127).
§Examples
1.43.0 · Sourcepub const MAX: i128
pub const MAX: i128
The largest value that can be represented by this integer type (2127 − 1).
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn count_ones(self) -> u32
pub const fn count_ones(self) -> u32
Returns the number of ones in the binary representation of self.
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn count_zeros(self) -> u32
pub const fn count_zeros(self) -> u32
Returns the number of zeros in the binary representation of self.
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn leading_zeros(self) -> u32
pub const fn leading_zeros(self) -> u32
1.0.0 (const: 1.32.0) · Sourcepub const fn trailing_zeros(self) -> u32
pub const fn trailing_zeros(self) -> u32
Returns the number of trailing zeros in the binary representation of self.
§Examples
1.46.0 (const: 1.46.0) · Sourcepub const fn leading_ones(self) -> u32
pub const fn leading_ones(self) -> u32
Returns the number of leading ones in the binary representation of self.
§Examples
1.46.0 (const: 1.46.0) · Sourcepub const fn trailing_ones(self) -> u32
pub const fn trailing_ones(self) -> u32
Returns the number of trailing ones in the binary representation of self.
§Examples
1.97.0 (const: 1.97.0) · Sourcepub const fn isolate_highest_one(self) -> i128
pub const fn isolate_highest_one(self) -> i128
Returns self with only the most significant bit set, or 0 if
the input is 0.
§Examples
1.97.0 (const: 1.97.0) · Sourcepub const fn isolate_lowest_one(self) -> i128
pub const fn isolate_lowest_one(self) -> i128
Returns self with only the least significant bit set, or 0 if
the input is 0.
§Examples
1.97.0 (const: 1.97.0) · Sourcepub const fn highest_one(self) -> Option<u32>
pub const fn highest_one(self) -> Option<u32>
Returns the index of the highest bit set to one in self, or None
if self is 0.
§Examples
1.97.0 (const: 1.97.0) · Sourcepub const fn lowest_one(self) -> Option<u32>
pub const fn lowest_one(self) -> Option<u32>
Returns the index of the lowest bit set to one in self, or None
if self is 0.
§Examples
1.87.0 (const: 1.87.0) · Sourcepub const fn cast_unsigned(self) -> u128
pub const fn cast_unsigned(self) -> u128
Returns the bit pattern of self reinterpreted as an unsigned integer of the same size.
This produces the same result as an as cast, but ensures that the bit-width remains
the same.
§Examples
Sourcepub const fn saturating_cast_unsigned(self) -> u128
🔬This is a nightly-only experimental API. (integer_cast_extras #154650)
pub const fn saturating_cast_unsigned(self) -> u128
integer_cast_extras #154650)Saturating conversion of self to an unsigned integer of the same size.
Negative values are clamped to 0.
For other kinds of unsigned integer casts, see
cast_unsigned,
checked_cast_unsigned,
or strict_cast_unsigned.
§Examples
Sourcepub const fn checked_cast_unsigned(self) -> Option<u128>
🔬This is a nightly-only experimental API. (integer_cast_extras #154650)
pub const fn checked_cast_unsigned(self) -> Option<u128>
integer_cast_extras #154650)Checked conversion of self to an unsigned integer of the same size,
returning None if self is negative.
For other kinds of unsigned integer casts, see
cast_unsigned,
saturating_cast_unsigned,
or strict_cast_unsigned.
§Examples
Sourcepub const fn strict_cast_unsigned(self) -> u128
🔬This is a nightly-only experimental API. (integer_cast_extras #154650)
pub const fn strict_cast_unsigned(self) -> u128
integer_cast_extras #154650)Strict conversion of self to an unsigned integer of the same size,
which panics if self is negative.
For other kinds of unsigned integer casts, see
cast_unsigned,
checked_cast_unsigned,
or saturating_cast_unsigned.
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn rotate_left(self, n: u32) -> i128
pub const fn rotate_left(self, n: u32) -> i128
Shifts the bits to the left by a specified amount, n,
wrapping the truncated bits to the end of the resulting integer.
rotate_left(n) is equivalent to applying rotate_left(1) a total of n times. In
particular, a rotation by the number of bits in self returns the input value
unchanged.
Please note this isn’t the same operation as the << shifting operator!
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn rotate_right(self, n: u32) -> i128
pub const fn rotate_right(self, n: u32) -> i128
Shifts the bits to the right by a specified amount, n,
wrapping the truncated bits to the beginning of the resulting
integer.
rotate_right(n) is equivalent to applying rotate_right(1) a total of n times. In
particular, a rotation by the number of bits in self returns the input value
unchanged.
Please note this isn’t the same operation as the >> shifting operator!
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn swap_bytes(self) -> i128
pub const fn swap_bytes(self) -> i128
Reverses the byte order of the integer.
§Examples
1.37.0 (const: 1.37.0) · Sourcepub const fn reverse_bits(self) -> i128
pub const fn reverse_bits(self) -> i128
Reverses the order of bits in the integer. The least significant bit becomes the most significant bit, second least-significant bit becomes second most-significant bit, etc.
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn from_be(x: i128) -> i128
pub const fn from_be(x: i128) -> i128
Converts an integer from big endian to the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
See also from_be_bytes().
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn from_le(x: i128) -> i128
pub const fn from_le(x: i128) -> i128
Converts an integer from little endian to the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
See also from_le_bytes().
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn to_be(self) -> i128
pub const fn to_be(self) -> i128
Swaps bytes of self on little endian targets.
On big endian this is a no-op.
The returned value has the same type as self, and will be interpreted
as (a potentially different) value of a native-endian
i128.
See to_be_bytes() for a type-safe alternative.
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn to_le(self) -> i128
pub const fn to_le(self) -> i128
Swaps bytes of self on big endian targets.
On little endian this is a no-op.
The returned value has the same type as self, and will be interpreted
as (a potentially different) value of a native-endian
i128.
See to_le_bytes() for a type-safe alternative.
§Examples
1.0.0 (const: 1.47.0) · Sourcepub const fn checked_add(self, rhs: i128) -> Option<i128>
pub const fn checked_add(self, rhs: i128) -> Option<i128>
Checked integer addition. Computes self + rhs, returning None
if overflow occurred.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_add(self, rhs: i128) -> i128
pub const fn strict_add(self, rhs: i128) -> i128
1.79.0 (const: 1.79.0) · Sourcepub const unsafe fn unchecked_add(self, rhs: i128) -> i128
pub const unsafe fn unchecked_add(self, rhs: i128) -> i128
Unchecked integer addition. Computes self + rhs, assuming overflow
cannot occur.
Calling x.unchecked_add(y) is semantically equivalent to calling
x.checked_add(y).unwrap_unchecked().
If you’re just trying to avoid the panic in debug mode, then do not
use this. Instead, you’re looking for wrapping_add.
§Safety
This results in undefined behavior when
self + rhs > i128::MAX or self + rhs < i128::MIN,
i.e. when checked_add would return None.
1.66.0 (const: 1.66.0) · Sourcepub const fn checked_add_unsigned(self, rhs: u128) -> Option<i128>
pub const fn checked_add_unsigned(self, rhs: u128) -> Option<i128>
Checked addition with an unsigned integer. Computes self + rhs,
returning None if overflow occurred.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_add_unsigned(self, rhs: u128) -> i128
pub const fn strict_add_unsigned(self, rhs: u128) -> i128
1.0.0 (const: 1.47.0) · Sourcepub const fn checked_sub(self, rhs: i128) -> Option<i128>
pub const fn checked_sub(self, rhs: i128) -> Option<i128>
Checked integer subtraction. Computes self - rhs, returning None if
overflow occurred.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_sub(self, rhs: i128) -> i128
pub const fn strict_sub(self, rhs: i128) -> i128
1.79.0 (const: 1.79.0) · Sourcepub const unsafe fn unchecked_sub(self, rhs: i128) -> i128
pub const unsafe fn unchecked_sub(self, rhs: i128) -> i128
Unchecked integer subtraction. Computes self - rhs, assuming overflow
cannot occur.
Calling x.unchecked_sub(y) is semantically equivalent to calling
x.checked_sub(y).unwrap_unchecked().
If you’re just trying to avoid the panic in debug mode, then do not
use this. Instead, you’re looking for wrapping_sub.
§Safety
This results in undefined behavior when
self - rhs > i128::MAX or self - rhs < i128::MIN,
i.e. when checked_sub would return None.
1.66.0 (const: 1.66.0) · Sourcepub const fn checked_sub_unsigned(self, rhs: u128) -> Option<i128>
pub const fn checked_sub_unsigned(self, rhs: u128) -> Option<i128>
Checked subtraction with an unsigned integer. Computes self - rhs,
returning None if overflow occurred.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_sub_unsigned(self, rhs: u128) -> i128
pub const fn strict_sub_unsigned(self, rhs: u128) -> i128
1.0.0 (const: 1.47.0) · Sourcepub const fn checked_mul(self, rhs: i128) -> Option<i128>
pub const fn checked_mul(self, rhs: i128) -> Option<i128>
Checked integer multiplication. Computes self * rhs, returning None if
overflow occurred.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_mul(self, rhs: i128) -> i128
pub const fn strict_mul(self, rhs: i128) -> i128
1.79.0 (const: 1.79.0) · Sourcepub const unsafe fn unchecked_mul(self, rhs: i128) -> i128
pub const unsafe fn unchecked_mul(self, rhs: i128) -> i128
Unchecked integer multiplication. Computes self * rhs, assuming overflow
cannot occur.
Calling x.unchecked_mul(y) is semantically equivalent to calling
x.checked_mul(y).unwrap_unchecked().
If you’re just trying to avoid the panic in debug mode, then do not
use this. Instead, you’re looking for wrapping_mul.
§Safety
This results in undefined behavior when
self * rhs > i128::MAX or self * rhs < i128::MIN,
i.e. when checked_mul would return None.
1.0.0 (const: 1.52.0) · Sourcepub const fn checked_div(self, rhs: i128) -> Option<i128>
pub const fn checked_div(self, rhs: i128) -> Option<i128>
Checked integer division. Computes self / rhs, returning None if rhs == 0
or the division results in overflow.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_div(self, rhs: i128) -> i128
pub const fn strict_div(self, rhs: i128) -> i128
Strict integer division. Computes self / rhs, panicking
if overflow occurred.
§Panics
This function will panic if rhs is zero.
§Overflow behavior
This function will always panic on overflow, regardless of whether overflow checks are enabled.
The only case where such an overflow can occur is when one divides MIN / -1 on a signed type (where
MIN is the negative minimal value for the type); this is equivalent to -MIN, a positive value
that is too large to represent in the type.
§Examples
The following panics because of overflow:
The following panics because of division by zero:
1.38.0 (const: 1.52.0) · Sourcepub const fn checked_div_euclid(self, rhs: i128) -> Option<i128>
pub const fn checked_div_euclid(self, rhs: i128) -> Option<i128>
Checked Euclidean division. Computes self.div_euclid(rhs),
returning None if rhs == 0 or the division results in overflow.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_div_euclid(self, rhs: i128) -> i128
pub const fn strict_div_euclid(self, rhs: i128) -> i128
Strict Euclidean division. Computes self.div_euclid(rhs), panicking
if overflow occurred.
§Panics
This function will panic if rhs is zero.
§Overflow behavior
This function will always panic on overflow, regardless of whether overflow checks are enabled.
The only case where such an overflow can occur is when one divides MIN / -1 on a signed type (where
MIN is the negative minimal value for the type); this is equivalent to -MIN, a positive value
that is too large to represent in the type.
§Examples
The following panics because of overflow:
The following panics because of division by zero:
Sourcepub const fn checked_div_exact(self, rhs: i128) -> Option<i128>
🔬This is a nightly-only experimental API. (exact_div #139911)
pub const fn checked_div_exact(self, rhs: i128) -> Option<i128>
exact_div #139911)Checked integer division without remainder. Computes self / rhs,
returning None if rhs == 0, the division results in overflow,
or self % rhs != 0.
§Examples
Sourcepub const fn div_exact(self, rhs: i128) -> Option<i128>
🔬This is a nightly-only experimental API. (exact_div #139911)
pub const fn div_exact(self, rhs: i128) -> Option<i128>
exact_div #139911)Integer division without remainder. Computes self / rhs, returning None if self % rhs != 0.
§Panics
This function will panic if rhs == 0.
§Overflow behavior
On overflow, this function will panic if overflow checks are enabled (default in debug mode) and wrap if overflow checks are disabled (default in release mode).
§Examples
Sourcepub const unsafe fn unchecked_div_exact(self, rhs: i128) -> i128
🔬This is a nightly-only experimental API. (exact_div #139911)
pub const unsafe fn unchecked_div_exact(self, rhs: i128) -> i128
exact_div #139911)Unchecked integer division without remainder. Computes self / rhs.
§Safety
This results in undefined behavior when rhs == 0, self % rhs != 0, or
self == i128::MIN && rhs == -1,
i.e. when checked_div_exact would return None.
1.7.0 (const: 1.52.0) · Sourcepub const fn checked_rem(self, rhs: i128) -> Option<i128>
pub const fn checked_rem(self, rhs: i128) -> Option<i128>
Checked integer remainder. Computes self % rhs, returning None if
rhs == 0 or the division results in overflow.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_rem(self, rhs: i128) -> i128
pub const fn strict_rem(self, rhs: i128) -> i128
Strict integer remainder. Computes self % rhs, panicking if
the division results in overflow.
§Panics
This function will panic if rhs is zero.
§Overflow behavior
This function will always panic on overflow, regardless of whether overflow checks are enabled.
The only case where such an overflow can occur is x % y for MIN / -1 on a
signed type (where MIN is the negative minimal value), which is invalid due to implementation artifacts.
§Examples
The following panics because of division by zero:
The following panics because of overflow:
1.38.0 (const: 1.52.0) · Sourcepub const fn checked_rem_euclid(self, rhs: i128) -> Option<i128>
pub const fn checked_rem_euclid(self, rhs: i128) -> Option<i128>
Checked Euclidean remainder. Computes self.rem_euclid(rhs), returning None
if rhs == 0 or the division results in overflow.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_rem_euclid(self, rhs: i128) -> i128
pub const fn strict_rem_euclid(self, rhs: i128) -> i128
Strict Euclidean remainder. Computes self.rem_euclid(rhs), panicking if
the division results in overflow.
§Panics
This function will panic if rhs is zero.
§Overflow behavior
This function will always panic on overflow, regardless of whether overflow checks are enabled.
The only case where such an overflow can occur is x % y for MIN / -1 on a
signed type (where MIN is the negative minimal value), which is invalid due to implementation artifacts.
§Examples
The following panics because of division by zero:
The following panics because of overflow:
1.7.0 (const: 1.47.0) · Sourcepub const fn checked_neg(self) -> Option<i128>
pub const fn checked_neg(self) -> Option<i128>
Checked negation. Computes -self, returning None if self == MIN.
§Examples
1.93.0 (const: 1.93.0) · Sourcepub const unsafe fn unchecked_neg(self) -> i128
pub const unsafe fn unchecked_neg(self) -> i128
Unchecked negation. Computes -self, assuming overflow cannot occur.
§Safety
This results in undefined behavior when
self == i128::MIN,
i.e. when checked_neg would return None.
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_neg(self) -> i128
pub const fn strict_neg(self) -> i128
1.7.0 (const: 1.47.0) · Sourcepub const fn checked_shl(self, rhs: u32) -> Option<i128>
pub const fn checked_shl(self, rhs: u32) -> Option<i128>
Checked shift left. Computes self << rhs, returning None if rhs is larger
than or equal to the number of bits in self.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_shl(self, rhs: u32) -> i128
pub const fn strict_shl(self, rhs: u32) -> i128
1.93.0 (const: 1.93.0) · Sourcepub const unsafe fn unchecked_shl(self, rhs: u32) -> i128
pub const unsafe fn unchecked_shl(self, rhs: u32) -> i128
Unchecked shift left. Computes self << rhs, assuming that
rhs is less than the number of bits in self.
§Safety
This results in undefined behavior if rhs is larger than
or equal to the number of bits in self,
i.e. when checked_shl would return None.
1.87.0 (const: 1.87.0) · Sourcepub const fn unbounded_shl(self, rhs: u32) -> i128
pub const fn unbounded_shl(self, rhs: u32) -> i128
Unbounded shift left. Computes self << rhs, without bounding the value of rhs.
If rhs is larger or equal to the number of bits in self,
the entire value is shifted out, and 0 is returned.
§Examples
assert_eq!(0x1_i128.unbounded_shl(4), 0x10);
assert_eq!(0x1_i128.unbounded_shl(129), 0);
assert_eq!(0b101_i128.unbounded_shl(0), 0b101);
assert_eq!(0b101_i128.unbounded_shl(1), 0b1010);
assert_eq!(0b101_i128.unbounded_shl(2), 0b10100);
assert_eq!(42_i128.unbounded_shl(128), 0);
assert_eq!(42_i128.unbounded_shl(1).unbounded_shl(127), 0);
assert_eq!((-13_i128).unbounded_shl(128), 0);
assert_eq!((-13_i128).unbounded_shl(1).unbounded_shl(127), 0);Sourcepub const fn shl_exact(self, rhs: u32) -> Option<i128>
🔬This is a nightly-only experimental API. (exact_bitshifts #144336)
pub const fn shl_exact(self, rhs: u32) -> Option<i128>
exact_bitshifts #144336)Exact shift left. Computes self << rhs as long as it can be reversed losslessly.
Returns None if any bits that would be shifted out differ from the resulting sign bit
or if rhs >=
i128::BITS.
Otherwise, returns Some(self << rhs).
§Examples
#![feature(exact_bitshifts)]
assert_eq!(0x1i128.shl_exact(4), Some(0x10));
assert_eq!(0x1i128.shl_exact(i128::BITS - 2), Some(1 << i128::BITS - 2));
assert_eq!(0x1i128.shl_exact(i128::BITS - 1), None);
assert_eq!((-0x2i128).shl_exact(i128::BITS - 2), Some(-0x2 << i128::BITS - 2));
assert_eq!((-0x2i128).shl_exact(i128::BITS - 1), None);Sourcepub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> i128
🔬This is a nightly-only experimental API. (exact_bitshifts #144336)
pub const unsafe fn unchecked_shl_exact(self, rhs: u32) -> i128
exact_bitshifts #144336)Unchecked exact shift left. Computes self << rhs, assuming the operation can be
losslessly reversed and rhs cannot be larger than
i128::BITS.
§Safety
This results in undefined behavior when rhs >= self.leading_zeros() && rhs >= self.leading_ones() i.e. when
i128::shl_exact
would return None.
1.7.0 (const: 1.47.0) · Sourcepub const fn checked_shr(self, rhs: u32) -> Option<i128>
pub const fn checked_shr(self, rhs: u32) -> Option<i128>
Checked shift right. Computes self >> rhs, returning None if rhs is
larger than or equal to the number of bits in self.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_shr(self, rhs: u32) -> i128
pub const fn strict_shr(self, rhs: u32) -> i128
1.93.0 (const: 1.93.0) · Sourcepub const unsafe fn unchecked_shr(self, rhs: u32) -> i128
pub const unsafe fn unchecked_shr(self, rhs: u32) -> i128
Unchecked shift right. Computes self >> rhs, assuming that
rhs is less than the number of bits in self.
§Safety
This results in undefined behavior if rhs is larger than
or equal to the number of bits in self,
i.e. when checked_shr would return None.
1.87.0 (const: 1.87.0) · Sourcepub const fn unbounded_shr(self, rhs: u32) -> i128
pub const fn unbounded_shr(self, rhs: u32) -> i128
Unbounded shift right. Computes self >> rhs, without bounding the value of rhs.
If rhs is larger or equal to the number of bits in self,
the entire value is shifted out, which yields 0 for a positive number,
and -1 for a negative number.
§Examples
assert_eq!(0x10_i128.unbounded_shr(4), 0x1);
assert_eq!(0x10_i128.unbounded_shr(129), 0);
assert_eq!(i128::MIN.unbounded_shr(129), -1);
assert_eq!(0b1010_i128.unbounded_shr(0), 0b1010);
assert_eq!(0b1010_i128.unbounded_shr(1), 0b101);
assert_eq!(0b1010_i128.unbounded_shr(2), 0b10);
assert_eq!(42_i128.unbounded_shr(128), 0);
assert_eq!(42_i128.unbounded_shr(1).unbounded_shr(127), 0);
assert_eq!((-13_i128).unbounded_shr(128), -1);
assert_eq!((-13_i128).unbounded_shr(1).unbounded_shr(127), -1);Sourcepub const fn shr_exact(self, rhs: u32) -> Option<i128>
🔬This is a nightly-only experimental API. (exact_bitshifts #144336)
pub const fn shr_exact(self, rhs: u32) -> Option<i128>
exact_bitshifts #144336)Exact shift right. Computes self >> rhs as long as it can be reversed losslessly.
Returns None if any non-zero bits would be shifted out or if rhs >=
i128::BITS.
Otherwise, returns Some(self >> rhs).
§Examples
Sourcepub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> i128
🔬This is a nightly-only experimental API. (exact_bitshifts #144336)
pub const unsafe fn unchecked_shr_exact(self, rhs: u32) -> i128
exact_bitshifts #144336)Unchecked exact shift right. Computes self >> rhs, assuming the operation can be
losslessly reversed and rhs cannot be larger than
i128::BITS.
§Safety
This results in undefined behavior when rhs > self.trailing_zeros() || rhs >= i128::BITS
i.e. when
i128::shr_exact
would return None.
1.13.0 (const: 1.47.0) · Sourcepub const fn checked_abs(self) -> Option<i128>
pub const fn checked_abs(self) -> Option<i128>
Checked absolute value. Computes self.abs(), returning None if
self == MIN.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_abs(self) -> i128
pub const fn strict_abs(self) -> i128
1.34.0 (const: 1.50.0) · Sourcepub const fn checked_pow(self, exp: u32) -> Option<i128>
pub const fn checked_pow(self, exp: u32) -> Option<i128>
Checked exponentiation. Computes self.pow(exp), returning None if
overflow occurred.
§Examples
1.91.0 (const: 1.91.0) · Sourcepub const fn strict_pow(self, exp: u32) -> i128
pub const fn strict_pow(self, exp: u32) -> i128
1.84.0 (const: 1.84.0) · Sourcepub const fn checked_isqrt(self) -> Option<i128>
pub const fn checked_isqrt(self) -> Option<i128>
Returns the integer square root of the number, rounded down.
This function returns the principal (non-negative) square root.
For a given number n, although both x and -x satisfy x2 = n,
this function always returns the non-negative value.
Returns None if self is negative.
§Examples
1.0.0 (const: 1.47.0) · Sourcepub const fn saturating_add(self, rhs: i128) -> i128
pub const fn saturating_add(self, rhs: i128) -> i128
Saturating integer addition. Computes self + rhs, saturating at the numeric
bounds instead of overflowing.
§Examples
1.66.0 (const: 1.66.0) · Sourcepub const fn saturating_add_unsigned(self, rhs: u128) -> i128
pub const fn saturating_add_unsigned(self, rhs: u128) -> i128
Saturating addition with an unsigned integer. Computes self + rhs,
saturating at the numeric bounds instead of overflowing.
§Examples
1.0.0 (const: 1.47.0) · Sourcepub const fn saturating_sub(self, rhs: i128) -> i128
pub const fn saturating_sub(self, rhs: i128) -> i128
Saturating integer subtraction. Computes self - rhs, saturating at the
numeric bounds instead of overflowing.
§Examples
1.66.0 (const: 1.66.0) · Sourcepub const fn saturating_sub_unsigned(self, rhs: u128) -> i128
pub const fn saturating_sub_unsigned(self, rhs: u128) -> i128
Saturating subtraction with an unsigned integer. Computes self - rhs,
saturating at the numeric bounds instead of overflowing.
§Examples
assert_eq!(100i128.saturating_sub_unsigned(