Primitive Type i64
Expand description
The 64-bit signed integer type.
Implementations§
Source§impl i64
impl i64
1.43.0 · Sourcepub const MIN: i64
pub const MIN: i64
The smallest value that can be represented by this integer type (−263).
§Examples
1.43.0 · Sourcepub const MAX: i64
pub const MAX: i64
The largest value that can be represented by this integer type (263 − 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) -> i64
pub const fn isolate_highest_one(self) -> i64
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) -> i64
pub const fn isolate_lowest_one(self) -> i64
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) -> u64
pub const fn cast_unsigned(self) -> u64
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) -> u64
🔬This is a nightly-only experimental API. (integer_cast_extras #154650)
pub const fn saturating_cast_unsigned(self) -> u64
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<u64>
🔬This is a nightly-only experimental API. (integer_cast_extras #154650)
pub const fn checked_cast_unsigned(self) -> Option<u64>
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) -> u64
🔬This is a nightly-only experimental API. (integer_cast_extras #154650)
pub const fn strict_cast_unsigned(self) -> u64
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) -> i64
pub const fn rotate_left(self, n: u32) -> i64
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) -> i64
pub const fn rotate_right(self, n: u32) -> i64
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) -> i64
pub const fn swap_bytes(self) -> i64
Reverses the byte order of the integer.
§Examples
1.37.0 (const: 1.37.0) · Sourcepub const fn reverse_bits(self) -> i64
pub const fn reverse_bits(self) -> i64
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: i64) -> i64
pub const fn from_be(x: i64) -> i64
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: i64) -> i64
pub const fn from_le(x: i64) -> i64
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) -> i64
pub const fn to_be(self) -> i64
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
i64.
See to_be_bytes() for a type-safe alternative.
§Examples
1.0.0 (const: 1.32.0) · Sourcepub const fn to_le(self) -> i64
pub const fn to_le(self) -> i64
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
i64.
See to_le_bytes() for a type-safe alternative.
§Examples
1.0.0 (const: 1.47.0) · Sourcepub const fn checked_add(self, rhs: i64) -> Option<i64>
pub const fn checked_add(self, rhs: i64) -> Option<i64>
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: i64) -> i64
pub const fn strict_add(self, rhs: i64) -> i64
1.79.0 (const: 1.79.0) · Sourcepub const unsafe fn unchecked_add(self, rhs: i64) -> i64
pub const unsafe fn unchecked_add(self, rhs: i64) -> i64
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 > i64::MAX or self + rhs < i64::MIN,
i.e. when checked_add would return None.
1.66.0 (const: 1.66.0) · Sourcepub const fn checked_add_unsigned(self, rhs: u64) -> Option<i64>
pub const fn checked_add_unsigned(self, rhs: u64) -> Option<i64>
Checked addition with an unsigned integer. Computes self + rhs,
returning None if overflow occurred.