type w64 = Wrapping<u64>;
Aliased Type§
struct w64(pub u64);
Fields§
§0: u64
Implementations
Source§impl Wrapping<u64>
impl Wrapping<u64>
Sourcepub const fn leading_zeros(self) -> u32
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn leading_zeros(self) -> u32
wrapping_int_impl
)Returns the number of leading zeros in the binary representation of self
.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(u64::MAX) >> 2;
assert_eq!(n.leading_zeros(), 2);
Sourcepub fn is_power_of_two(self) -> bool
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub fn is_power_of_two(self) -> bool
wrapping_int_impl
)Returns true
if and only if self == 2^k
for some k
.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert!(Wrapping(16u64).is_power_of_two());
assert!(!Wrapping(10u64).is_power_of_two());
Sourcepub fn next_power_of_two(self) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_next_power_of_two
)
pub fn next_power_of_two(self) -> Wrapping<u64>
wrapping_next_power_of_two
)Returns the smallest power of two greater than or equal to self
.
When return value overflows (i.e., self > (1 << (N-1))
for type
uN
), overflows to 2^N = 0
.
§Examples
Basic usage:
#![feature(wrapping_next_power_of_two)]
use std::num::Wrapping;
assert_eq!(Wrapping(2u64).next_power_of_two(), Wrapping(2));
assert_eq!(Wrapping(3u64).next_power_of_two(), Wrapping(4));
assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
Source§impl Wrapping<u64>
impl Wrapping<u64>
Sourcepub const MIN: Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const MIN: Wrapping<u64>
wrapping_int_impl
)Returns the smallest value that can be represented by this integer type.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<u64>>::MIN, Wrapping(u64::MIN));
Sourcepub const MAX: Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const MAX: Wrapping<u64>
wrapping_int_impl
)Returns the largest value that can be represented by this integer type.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<u64>>::MAX, Wrapping(u64::MAX));
Sourcepub const BITS: u32 = 64u32
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const BITS: u32 = 64u32
wrapping_int_impl
)Returns the size of this integer type in bits.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(<Wrapping<u64>>::BITS, u64::BITS);
Sourcepub const fn count_ones(self) -> u32
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn count_ones(self) -> u32
wrapping_int_impl
)Returns the number of ones in the binary representation of self
.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0b01001100u64);
assert_eq!(n.count_ones(), 3);
Sourcepub const fn count_zeros(self) -> u32
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn count_zeros(self) -> u32
wrapping_int_impl
)Returns the number of zeros in the binary representation of self
.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(!0u64).count_zeros(), 0);
Sourcepub const fn trailing_zeros(self) -> u32
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn trailing_zeros(self) -> u32
wrapping_int_impl
)Returns the number of trailing zeros in the binary representation of self
.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0b0101000u64);
assert_eq!(n.trailing_zeros(), 3);
Sourcepub const fn rotate_left(self, n: u32) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn rotate_left(self, n: u32) -> Wrapping<u64>
wrapping_int_impl
)Shifts the bits to the left by a specified amount, n
,
wrapping the truncated bits to the end of the resulting
integer.
Please note this isn’t the same operation as the <<
shifting
operator!
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
assert_eq!(n.rotate_left(32), m);
Sourcepub const fn rotate_right(self, n: u32) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn rotate_right(self, n: u32) -> Wrapping<u64>
wrapping_int_impl
)Shifts the bits to the right by a specified amount, n
,
wrapping the truncated bits to the beginning of the resulting
integer.
Please note this isn’t the same operation as the >>
shifting
operator!
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
assert_eq!(n.rotate_right(4), m);
Sourcepub const fn swap_bytes(self) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn swap_bytes(self) -> Wrapping<u64>
wrapping_int_impl
)Reverses the byte order of the integer.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
assert_eq!(n, Wrapping(85));
let m = n.swap_bytes();
assert_eq!(m, Wrapping(0b01010101_00000000));
assert_eq!(m, Wrapping(21760));
1.37.0 (const: 1.37.0) · Sourcepub const fn reverse_bits(self) -> Wrapping<u64>
pub const fn reverse_bits(self) -> Wrapping<u64>
Reverses the bit pattern of the integer.
§Examples
Please note that this example is shared between integer types.
Which explains why i16
is used here.
Basic usage:
use std::num::Wrapping;
let n = Wrapping(0b0000000_01010101i16);
assert_eq!(n, Wrapping(85));
let m = n.reverse_bits();
assert_eq!(m.0 as u16, 0b10101010_00000000);
assert_eq!(m, Wrapping(-22016));
Sourcepub const fn from_be(x: Wrapping<u64>) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn from_be(x: Wrapping<u64>) -> Wrapping<u64>
wrapping_int_impl
)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.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "big") {
assert_eq!(<Wrapping<u64>>::from_be(n), n)
} else {
assert_eq!(<Wrapping<u64>>::from_be(n), n.swap_bytes())
}
Sourcepub const fn from_le(x: Wrapping<u64>) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn from_le(x: Wrapping<u64>) -> Wrapping<u64>
wrapping_int_impl
)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.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "little") {
assert_eq!(<Wrapping<u64>>::from_le(n), n)
} else {
assert_eq!(<Wrapping<u64>>::from_le(n), n.swap_bytes())
}
Sourcepub const fn to_be(self) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn to_be(self) -> Wrapping<u64>
wrapping_int_impl
)Converts self
to big endian from the target’s endianness.
On big endian this is a no-op. On little endian the bytes are swapped.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "big") {
assert_eq!(n.to_be(), n)
} else {
assert_eq!(n.to_be(), n.swap_bytes())
}
Sourcepub const fn to_le(self) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub const fn to_le(self) -> Wrapping<u64>
wrapping_int_impl
)Converts self
to little endian from the target’s endianness.
On little endian this is a no-op. On big endian the bytes are swapped.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
let n = Wrapping(0x1Au64);
if cfg!(target_endian = "little") {
assert_eq!(n.to_le(), n)
} else {
assert_eq!(n.to_le(), n.swap_bytes())
}
Sourcepub fn pow(self, exp: u32) -> Wrapping<u64>
🔬This is a nightly-only experimental API. (wrapping_int_impl
)
pub fn pow(self, exp: u32) -> Wrapping<u64>
wrapping_int_impl
)Raises self to the power of exp
, using exponentiation by squaring.
§Examples
Basic usage:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3u64).pow(4), Wrapping(81));
Results that are too large are wrapped:
#![feature(wrapping_int_impl)]
use std::num::Wrapping;
assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
Trait Implementations
1.22.0 · Source§impl AddAssign<&u64> for Wrapping<u64>
impl AddAssign<&u64> for Wrapping<u64>
Source§fn add_assign(&mut self, other: &u64)
fn add_assign(&mut self, other: &u64)
+=
operation. Read more1.60.0 · Source§impl AddAssign<u64> for Wrapping<u64>
impl AddAssign<u64> for Wrapping<u64>
Source§fn add_assign(&mut self, other: u64)
fn add_assign(&mut self, other: u64)
+=
operation. Read more1.22.0 · Source§impl BitAndAssign<&u64> for Wrapping<u64>
impl BitAndAssign<&u64> for Wrapping<u64>
Source§fn bitand_assign(&mut self, other: &u64)
fn bitand_assign(&mut self, other: &u64)
&=
operation. Read more1.60.0 · Source§impl BitAndAssign<u64> for Wrapping<u64>
impl BitAndAssign<u64> for Wrapping<u64>
Source§fn bitand_assign(&mut self, other: u64)
fn bitand_assign(&mut self, other: u64)
&=
operation. Read more1.8.0 · Source§impl BitAndAssign for Wrapping<u64>
impl BitAndAssign for Wrapping<u64>
1.22.0 · Source§impl BitOrAssign<&u64> for Wrapping<u64>
impl BitOrAssign<&u64> for Wrapping<u64>
Source§fn bitor_assign(&mut self, other: &u64)
fn bitor_assign(&mut self, other: &u64)
|=
operation. Read more1.60.0 · Source§impl BitOrAssign<u64> for Wrapping<u64>
impl BitOrAssign<u64> for Wrapping<u64>
Source§fn bitor_assign(&mut self, other: u64)
fn bitor_assign(&mut self, other: u64)
|=
operation. Read more1.8.0 · Source§impl BitOrAssign for Wrapping<u64>
impl BitOrAssign for Wrapping<u64>
1.22.0 · Source§impl BitXorAssign<&u64> for Wrapping<u64>
impl BitXorAssign<&u64> for Wrapping<u64>
Source§fn bitxor_assign(&mut self, other: &u64)
fn bitxor_assign(&mut self, other: &u64)
^=
operation. Read more1.60.0 · Source§impl BitXorAssign<u64> for Wrapping<u64>
impl BitXorAssign<u64> for Wrapping<u64>
Source§fn bitxor_assign(&mut self, other: u64)
fn bitxor_assign(&mut self, other: u64)
^=
operation. Read more1.8.0 · Source§impl BitXorAssign for Wrapping<u64>
impl BitXorAssign for Wrapping<u64>
1.22.0 · Source§impl DivAssign<&u64> for Wrapping<u64>
impl DivAssign<&u64> for Wrapping<u64>
Source§fn div_assign(&mut self, other: &u64)
fn div_assign(&mut self, other: &u64)
/=
operation. Read more1.60.0 · Source§impl DivAssign<u64> for Wrapping<u64>
impl DivAssign<u64> for Wrapping<u64>
Source§fn div_assign(&mut self, other: u64)
fn div_assign(&mut self, other: u64)
/=
operation. Read more1.22.0 · Source§impl MulAssign<&u64> for Wrapping<u64>
impl MulAssign<&u64> for Wrapping<u64>
Source§fn mul_assign(&mut self, other: &u64)
fn mul_assign(&mut self, other: &u64)
*=
operation. Read more1.60.0 · Source§impl MulAssign<u64> for Wrapping<u64>
impl MulAssign<u64> for Wrapping<u64>
Source§fn mul_assign(&mut self, other: u64)
fn mul_assign(&mut self, other: u64)
*=
operation. Read more1.0.0 · Source§impl<T> Ord for Wrapping<T>where
T: Ord,
impl<T> Ord for Wrapping<T>where
T: Ord,
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.0.0 · Source§impl<T> PartialOrd for Wrapping<T>where
T: PartialOrd,
impl<T> PartialOrd for Wrapping<T>where
T: PartialOrd,
1.22.0 · Source§impl RemAssign<&u64> for Wrapping<u64>
impl RemAssign<&u64> for Wrapping<u64>
Source§fn rem_assign(&mut self, other: &u64)
fn rem_assign(&mut self, other: &u64)
%=
operation. Read more1.60.0 · Source§impl RemAssign<u64> for Wrapping<u64>
impl RemAssign<u64> for Wrapping<u64>
Source§fn rem_assign(&mut self, other: u64)
fn rem_assign(&mut self, other: u64)
%=
operation. Read more1.22.0 · Source§impl ShlAssign<&usize> for Wrapping<u64>
impl ShlAssign<&usize> for Wrapping<u64>
Source§fn shl_assign(&mut self, other: &usize)
fn shl_assign(&mut self, other: &usize)
<<=
operation. Read more1.8.0 · Source§impl ShlAssign<usize> for Wrapping<u64>
impl ShlAssign<usize> for Wrapping<u64>
Source§fn shl_assign(&mut self, other: usize)
fn shl_assign(&mut self, other: usize)
<<=
operation. Read more1.22.0 · Source§impl ShrAssign<&usize> for Wrapping<u64>
impl ShrAssign<&usize> for Wrapping<u64>
Source§fn shr_assign(&mut self, other: &usize)
fn shr_assign(&mut self, other: &usize)
>>=
operation. Read more1.8.0 · Source§impl ShrAssign<usize> for Wrapping<u64>
impl ShrAssign<usize> for Wrapping<u64>
Source§fn shr_assign(&mut self, other: usize)
fn shr_assign(&mut self, other: usize)
>>=
operation. Read more1.22.0 · Source§impl SubAssign<&u64> for Wrapping<u64>
impl SubAssign<&u64> for Wrapping<u64>
Source§fn sub_assign(&mut self, other: &u64)
fn sub_assign(&mut self, other: &u64)
-=
operation. Read more1.60.0 · Source§impl SubAssign<u64> for Wrapping<u64>
impl SubAssign<u64> for Wrapping<u64>
Source§fn sub_assign(&mut self, other: u64)
fn sub_assign(&mut self, other: u64)
-=
operation. Read more