```
"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
}
", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 1);", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn count_zeros(self) -> u32 {
(!self).count_ones()
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn leading_zeros(self) -> u32 {
(self as $UnsignedT).leading_zeros()
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn trailing_zeros(self) -> u32 {
(self as $UnsignedT).trailing_zeros()
assert_eq!(n.rotate_left(", $rot, "), m);
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))]
#[inline]
pub const fn rotate_left(self, n: u32) -> Self {
(self as $UnsignedT).rotate_left(n) as Self
assert_eq!(n.rotate_right(", $rot, "), m);
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))]
#[inline]
pub const fn rotate_right(self, n: u32) -> Self {
(self as $UnsignedT).rotate_right(n) as Self
assert_eq!(m, ", $swapped, ");
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn swap_bytes(self) -> Self {
(self as $UnsignedT).swap_bytes() as Self
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn from_be(x: Self) -> Self {
#[cfg(target_endian = "big")]
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn from_le(x: Self) -> Self {
#[cfg(target_endian = "little")]
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn to_be(self) -> Self { // or not to be?
#[cfg(target_endian = "big")]
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn to_le(self) -> Self {
#[cfg(target_endian = "little")]
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_add(self, rhs: Self) -> Self {
- #[cfg(stage0)]
- unsafe {
- intrinsics::overflowing_add(self, rhs)
- }
- #[cfg(not(stage0))]
intrinsics::overflowing_add(self, rhs)
}
}
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
- #[cfg(stage0)]
- unsafe {
- intrinsics::overflowing_sub(self, rhs)
- }
- #[cfg(not(stage0))]
intrinsics::overflowing_sub(self, rhs)
}
}
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
- #[cfg(stage0)]
- unsafe {
- intrinsics::overflowing_mul(self, rhs)
- }
- #[cfg(not(stage0))]
intrinsics::overflowing_mul(self, rhs)
}
}
$EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
$EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
"::MIN, true));", $EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) {
- #[cfg(stage0)]
- let (a, b) = unsafe {
- intrinsics::add_with_overflow(self as $ActualT, rhs as $ActualT)
- };
- #[cfg(not(stage0))]
let (a, b) = intrinsics::add_with_overflow(self as $ActualT, rhs as $ActualT);
(a as Self, b)
}
"::MAX, true));", $EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
- #[cfg(stage0)]
- let (a, b) = unsafe {
- intrinsics::sub_with_overflow(self as $ActualT, rhs as $ActualT)
- };
- #[cfg(not(stage0))]
let (a, b) = intrinsics::sub_with_overflow(self as $ActualT, rhs as $ActualT);
(a as Self, b)
}
$EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
- #[cfg(stage0)]
- let (a, b) = unsafe {
- intrinsics::mul_with_overflow(self as $ActualT, rhs as $ActualT)
- };
- #[cfg(not(stage0))]
let (a, b) = intrinsics::mul_with_overflow(self as $ActualT, rhs as $ActualT);
(a as Self, b)
}
$EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
$EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shr(rhs), (rhs > ($BITS - 1)))
assert_eq!(n.count_ones(), 3);", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn count_ones(self) -> u32 {
- #[cfg(stage0)]
- unsafe { intrinsics::ctpop(self as $ActualT) as u32 }
- #[cfg(not(stage0))]
- { intrinsics::ctpop(self as $ActualT) as u32 }
+ intrinsics::ctpop(self as $ActualT) as u32
}
}
", $Feature, "assert_eq!(", stringify!($SelfT), "::max_value().count_zeros(), 0);", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn count_zeros(self) -> u32 {
(!self).count_ones()
assert_eq!(n.leading_zeros(), 2);", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn leading_zeros(self) -> u32 {
- #[cfg(stage0)]
- unsafe { intrinsics::ctlz(self as $ActualT) as u32 }
- #[cfg(not(stage0))]
- { intrinsics::ctlz(self as $ActualT) as u32 }
+ intrinsics::ctlz(self as $ActualT) as u32
}
}
assert_eq!(n.trailing_zeros(), 3);", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn trailing_zeros(self) -> u32 {
- #[cfg(stage0)]
- unsafe { intrinsics::cttz(self) as u32 }
- #[cfg(not(stage0))]
- { intrinsics::cttz(self) as u32 }
+ intrinsics::cttz(self) as u32
}
}
assert_eq!(n.rotate_left(", $rot, "), m);
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))]
#[inline]
pub const fn rotate_left(self, n: u32) -> Self {
- #[cfg(stage0)]
- unsafe { intrinsics::rotate_left(self, n as $SelfT) }
- #[cfg(not(stage0))]
intrinsics::rotate_left(self, n as $SelfT)
}
}
assert_eq!(n.rotate_right(", $rot, "), m);
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_rotate"))]
#[inline]
pub const fn rotate_right(self, n: u32) -> Self {
- #[cfg(stage0)]
- unsafe { intrinsics::rotate_right(self, n as $SelfT) }
- #[cfg(not(stage0))]
intrinsics::rotate_right(self, n as $SelfT)
}
}
assert_eq!(m, ", $swapped, ");
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn swap_bytes(self) -> Self {
- #[cfg(stage0)]
- unsafe { intrinsics::bswap(self as $ActualT) as Self }
- #[cfg(not(stage0))]
- { intrinsics::bswap(self as $ActualT) as Self }
+ intrinsics::bswap(self as $ActualT) as Self
}
}
assert_eq!(m, ", $reversed, ");
```"),
#[unstable(feature = "reverse_bits", issue = "48763")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_conversion"))]
#[inline]
pub const fn reverse_bits(self) -> Self {
- #[cfg(stage0)]
- unsafe { intrinsics::bitreverse(self as $ActualT) as Self }
- #[cfg(not(stage0))]
- { intrinsics::bitreverse(self as $ActualT) as Self }
+ intrinsics::bitreverse(self as $ActualT) as Self
}
}
}", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn from_be(x: Self) -> Self {
#[cfg(target_endian = "big")]
}", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn from_le(x: Self) -> Self {
#[cfg(target_endian = "little")]
}", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn to_be(self) -> Self { // or not to be?
#[cfg(target_endian = "big")]
}", $EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_ops"))]
#[inline]
pub const fn to_le(self) -> Self {
#[cfg(target_endian = "little")]
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_add(self, rhs: Self) -> Self {
- #[cfg(stage0)]
- unsafe {
- intrinsics::overflowing_add(self, rhs)
- }
- #[cfg(not(stage0))]
intrinsics::overflowing_add(self, rhs)
}
}
$EndFeature, "
```"),
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_sub(self, rhs: Self) -> Self {
- #[cfg(stage0)]
- unsafe {
- intrinsics::overflowing_sub(self, rhs)
- }
- #[cfg(not(stage0))]
intrinsics::overflowing_sub(self, rhs)
}
}
/// assert_eq!(25u8.wrapping_mul(12), 44);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_mul(self, rhs: Self) -> Self {
- #[cfg(stage0)]
- unsafe {
- intrinsics::overflowing_mul(self, rhs)
- }
- #[cfg(not(stage0))]
intrinsics::overflowing_mul(self, rhs)
}
assert_eq!(1", stringify!($SelfT), ".wrapping_shl(128), 1);", $EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
assert_eq!(128", stringify!($SelfT), ".wrapping_shr(128), 128);", $EndFeature, "
```"),
#[stable(feature = "num_wrapping", since = "1.2.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_wrapping"))]
#[inline]
pub const fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (0, true));", $EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) {
- #[cfg(stage0)]
- let (a, b) = unsafe {
- intrinsics::add_with_overflow(self as $ActualT, rhs as $ActualT)
- };
- #[cfg(not(stage0))]
let (a, b) = intrinsics::add_with_overflow(self as $ActualT, rhs as $ActualT);
(a as Self, b)
}
$EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
- #[cfg(stage0)]
- let (a, b) = unsafe {
- intrinsics::sub_with_overflow(self as $ActualT, rhs as $ActualT)
- };
- #[cfg(not(stage0))]
let (a, b) = intrinsics::sub_with_overflow(self as $ActualT, rhs as $ActualT);
(a as Self, b)
}
/// assert_eq!(1_000_000_000u32.overflowing_mul(10), (1410065408, true));
/// ```
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
- #[cfg(stage0)]
- let (a, b) = unsafe {
- intrinsics::mul_with_overflow(self as $ActualT, rhs as $ActualT)
- };
- #[cfg(not(stage0))]
let (a, b) = intrinsics::mul_with_overflow(self as $ActualT, rhs as $ActualT);
(a as Self, b)
}
assert_eq!(0x1", stringify!($SelfT), ".overflowing_shl(132), (0x10, true));", $EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(132), (0x1, true));", $EndFeature, "
```"),
#[stable(feature = "wrapping", since = "1.7.0")]
- #[cfg_attr(stage0, rustc_const_unstable(feature = "const_int_overflowing"))]
#[inline]
pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shr(rhs), (rhs > ($BITS - 1)))