5 #[allow(unused_macros)]
6 macro_rules
! sh_impl_signed
{
7 ($t
:ident
, $f
:ident
) => {
8 #[stable(feature = "rust1", since = "1.0.0")]
9 impl Shl
<$f
> for Wrapping
<$t
> {
10 type Output
= Wrapping
<$t
>;
13 fn shl(self, other
: $f
) -> Wrapping
<$t
> {
15 Wrapping(self.0.wrapping_shr((-other
& self::shift_max
::$t
as $f
) as u32))
17 Wrapping(self.0.wrapping_shl((other
& self::shift_max
::$t
as $f
) as u32))
21 forward_ref_binop
! { impl Shl
, shl
for Wrapping
<$t
>, $f
,
22 #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
24 #[stable(feature = "op_assign_traits", since = "1.8.0")]
25 impl ShlAssign
<$f
> for Wrapping
<$t
> {
27 fn shl_assign(&mut self, other
: $f
) {
28 *self = *self << other
;
31 forward_ref_op_assign
! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
33 #[stable(feature = "rust1", since = "1.0.0")]
34 impl Shr
<$f
> for Wrapping
<$t
> {
35 type Output
= Wrapping
<$t
>;
38 fn shr(self, other
: $f
) -> Wrapping
<$t
> {
40 Wrapping(self.0.wrapping_shl((-other
& self::shift_max
::$t
as $f
) as u32))
42 Wrapping(self.0.wrapping_shr((other
& self::shift_max
::$t
as $f
) as u32))
46 forward_ref_binop
! { impl Shr
, shr
for Wrapping
<$t
>, $f
,
47 #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
49 #[stable(feature = "op_assign_traits", since = "1.8.0")]
50 impl ShrAssign
<$f
> for Wrapping
<$t
> {
52 fn shr_assign(&mut self, other
: $f
) {
53 *self = *self >> other
;
56 forward_ref_op_assign
! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
60 macro_rules
! sh_impl_unsigned
{
61 ($t
:ident
, $f
:ident
) => {
62 #[stable(feature = "rust1", since = "1.0.0")]
63 impl Shl
<$f
> for Wrapping
<$t
> {
64 type Output
= Wrapping
<$t
>;
67 fn shl(self, other
: $f
) -> Wrapping
<$t
> {
68 Wrapping(self.0.wrapping_shl((other
& self::shift_max
::$t
as $f
) as u32))
71 forward_ref_binop
! { impl Shl
, shl
for Wrapping
<$t
>, $f
,
72 #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
74 #[stable(feature = "op_assign_traits", since = "1.8.0")]
75 impl ShlAssign
<$f
> for Wrapping
<$t
> {
77 fn shl_assign(&mut self, other
: $f
) {
78 *self = *self << other
;
81 forward_ref_op_assign
! { impl ShlAssign, shl_assign for Wrapping<$t>, $f }
83 #[stable(feature = "rust1", since = "1.0.0")]
84 impl Shr
<$f
> for Wrapping
<$t
> {
85 type Output
= Wrapping
<$t
>;
88 fn shr(self, other
: $f
) -> Wrapping
<$t
> {
89 Wrapping(self.0.wrapping_shr((other
& self::shift_max
::$t
as $f
) as u32))
92 forward_ref_binop
! { impl Shr
, shr
for Wrapping
<$t
>, $f
,
93 #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
95 #[stable(feature = "op_assign_traits", since = "1.8.0")]
96 impl ShrAssign
<$f
> for Wrapping
<$t
> {
98 fn shr_assign(&mut self, other
: $f
) {
99 *self = *self >> other
;
102 forward_ref_op_assign
! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
106 // FIXME (#23545): uncomment the remaining impls
107 macro_rules
! sh_impl_all
{
108 ($
($t
:ident
)*) => ($
(
109 //sh_impl_unsigned! { $t, u8 }
110 //sh_impl_unsigned! { $t, u16 }
111 //sh_impl_unsigned! { $t, u32 }
112 //sh_impl_unsigned! { $t, u64 }
113 //sh_impl_unsigned! { $t, u128 }
114 sh_impl_unsigned
! { $t, usize }
116 //sh_impl_signed! { $t, i8 }
117 //sh_impl_signed! { $t, i16 }
118 //sh_impl_signed! { $t, i32 }
119 //sh_impl_signed! { $t, i64 }
120 //sh_impl_signed! { $t, i128 }
121 //sh_impl_signed! { $t, isize }
125 sh_impl_all
! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize }
127 // FIXME(30524): impl Op<T> for Wrapping<T>, impl OpAssign<T> for Wrapping<T>
128 macro_rules
! wrapping_impl
{
130 #[stable(feature = "rust1", since = "1.0.0")]
131 impl Add
for Wrapping
<$t
> {
132 type Output
= Wrapping
<$t
>;
135 fn add(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
136 Wrapping(self.0.wrapping_add(other
.0))
139 forward_ref_binop
! { impl Add
, add
for Wrapping
<$t
>, Wrapping
<$t
>,
140 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
142 #[stable(feature = "op_assign_traits", since = "1.8.0")]
143 impl AddAssign
for Wrapping
<$t
> {
145 fn add_assign(&mut self, other
: Wrapping
<$t
>) {
146 *self = *self + other
;
149 forward_ref_op_assign
! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> }
151 #[stable(feature = "rust1", since = "1.0.0")]
152 impl Sub
for Wrapping
<$t
> {
153 type Output
= Wrapping
<$t
>;
156 fn sub(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
157 Wrapping(self.0.wrapping_sub(other
.0))
160 forward_ref_binop
! { impl Sub
, sub
for Wrapping
<$t
>, Wrapping
<$t
>,
161 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
163 #[stable(feature = "op_assign_traits", since = "1.8.0")]
164 impl SubAssign
for Wrapping
<$t
> {
166 fn sub_assign(&mut self, other
: Wrapping
<$t
>) {
167 *self = *self - other
;
170 forward_ref_op_assign
! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> }
172 #[stable(feature = "rust1", since = "1.0.0")]
173 impl Mul
for Wrapping
<$t
> {
174 type Output
= Wrapping
<$t
>;
177 fn mul(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
178 Wrapping(self.0.wrapping_mul(other
.0))
181 forward_ref_binop
! { impl Mul
, mul
for Wrapping
<$t
>, Wrapping
<$t
>,
182 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
184 #[stable(feature = "op_assign_traits", since = "1.8.0")]
185 impl MulAssign
for Wrapping
<$t
> {
187 fn mul_assign(&mut self, other
: Wrapping
<$t
>) {
188 *self = *self * other
;
191 forward_ref_op_assign
! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> }
193 #[stable(feature = "wrapping_div", since = "1.3.0")]
194 impl Div
for Wrapping
<$t
> {
195 type Output
= Wrapping
<$t
>;
198 fn div(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
199 Wrapping(self.0.wrapping_div(other
.0))
202 forward_ref_binop
! { impl Div
, div
for Wrapping
<$t
>, Wrapping
<$t
>,
203 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
205 #[stable(feature = "op_assign_traits", since = "1.8.0")]
206 impl DivAssign
for Wrapping
<$t
> {
208 fn div_assign(&mut self, other
: Wrapping
<$t
>) {
209 *self = *self / other
;
212 forward_ref_op_assign
! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> }
214 #[stable(feature = "wrapping_impls", since = "1.7.0")]
215 impl Rem
for Wrapping
<$t
> {
216 type Output
= Wrapping
<$t
>;
219 fn rem(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
220 Wrapping(self.0.wrapping_rem(other
.0))
223 forward_ref_binop
! { impl Rem
, rem
for Wrapping
<$t
>, Wrapping
<$t
>,
224 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
226 #[stable(feature = "op_assign_traits", since = "1.8.0")]
227 impl RemAssign
for Wrapping
<$t
> {
229 fn rem_assign(&mut self, other
: Wrapping
<$t
>) {
230 *self = *self % other
;
233 forward_ref_op_assign
! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> }
235 #[stable(feature = "rust1", since = "1.0.0")]
236 impl Not
for Wrapping
<$t
> {
237 type Output
= Wrapping
<$t
>;
240 fn not(self) -> Wrapping
<$t
> {
244 forward_ref_unop
! { impl Not
, not
for Wrapping
<$t
>,
245 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
247 #[stable(feature = "rust1", since = "1.0.0")]
248 impl BitXor
for Wrapping
<$t
> {
249 type Output
= Wrapping
<$t
>;
252 fn bitxor(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
253 Wrapping(self.0 ^ other
.0)
256 forward_ref_binop
! { impl BitXor
, bitxor
for Wrapping
<$t
>, Wrapping
<$t
>,
257 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
259 #[stable(feature = "op_assign_traits", since = "1.8.0")]
260 impl BitXorAssign
for Wrapping
<$t
> {
262 fn bitxor_assign(&mut self, other
: Wrapping
<$t
>) {
263 *self = *self ^ other
;
266 forward_ref_op_assign
! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> }
268 #[stable(feature = "rust1", since = "1.0.0")]
269 impl BitOr
for Wrapping
<$t
> {
270 type Output
= Wrapping
<$t
>;
273 fn bitor(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
274 Wrapping(self.0 | other
.0)
277 forward_ref_binop
! { impl BitOr
, bitor
for Wrapping
<$t
>, Wrapping
<$t
>,
278 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
280 #[stable(feature = "op_assign_traits", since = "1.8.0")]
281 impl BitOrAssign
for Wrapping
<$t
> {
283 fn bitor_assign(&mut self, other
: Wrapping
<$t
>) {
284 *self = *self | other
;
287 forward_ref_op_assign
! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> }
289 #[stable(feature = "rust1", since = "1.0.0")]
290 impl BitAnd
for Wrapping
<$t
> {
291 type Output
= Wrapping
<$t
>;
294 fn bitand(self, other
: Wrapping
<$t
>) -> Wrapping
<$t
> {
295 Wrapping(self.0 & other
.0)
298 forward_ref_binop
! { impl BitAnd
, bitand
for Wrapping
<$t
>, Wrapping
<$t
>,
299 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
301 #[stable(feature = "op_assign_traits", since = "1.8.0")]
302 impl BitAndAssign
for Wrapping
<$t
> {
304 fn bitand_assign(&mut self, other
: Wrapping
<$t
>) {
305 *self = *self & other
;
308 forward_ref_op_assign
! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> }
310 #[stable(feature = "wrapping_neg", since = "1.10.0")]
311 impl Neg
for Wrapping
<$t
> {
314 fn neg(self) -> Self {
318 forward_ref_unop
! { impl Neg
, neg
for Wrapping
<$t
>,
319 #[stable(feature = "wrapping_ref", since = "1.14.0")] }
324 wrapping_impl
! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
326 macro_rules
! wrapping_int_impl
{
330 concat
!("Returns the smallest value that can be represented by this integer type.
337 #![feature(wrapping_int_impl)]
338 use std::num::Wrapping;
340 assert_eq!(<Wrapping<", stringify
!($t
), ">>::MIN, Wrapping(", stringify
!($t
), "::MIN));
342 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
343 pub const MIN
: Self = Self(<$t
>::MIN
);
347 concat
!("Returns the largest value that can be represented by this integer type.
354 #![feature(wrapping_int_impl)]
355 use std::num::Wrapping;
357 assert_eq!(<Wrapping<", stringify
!($t
), ">>::MAX, Wrapping(", stringify
!($t
), "::MAX));
359 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
360 pub const MAX
: Self = Self(<$t
>::MAX
);
364 concat
!("Returns the number of ones in the binary representation of `self`.
371 #![feature(wrapping_int_impl)]
372 use std::num::Wrapping;
374 let n = Wrapping(0b01001100", stringify
!($t
), ");
376 assert_eq!(n.count_ones(), 3);
379 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
380 pub const fn count_ones(self) -> u32 {
386 concat
!("Returns the number of zeros in the binary representation of `self`.
393 #![feature(wrapping_int_impl)]
394 use std::num::Wrapping;
396 assert_eq!(Wrapping(!0", stringify
!($t
), ").count_zeros(), 0);
399 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
400 pub const fn count_zeros(self) -> u32 {
406 concat
!("Returns the number of trailing zeros in the binary representation
414 #![feature(wrapping_int_impl)]
415 use std::num::Wrapping;
417 let n = Wrapping(0b0101000", stringify
!($t
), ");
419 assert_eq!(n.trailing_zeros(), 3);
422 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
423 pub const fn trailing_zeros(self) -> u32 {
424 self.0.trailing_zeros()
428 /// Shifts the bits to the left by a specified amount, `n`,
429 /// wrapping the truncated bits to the end of the resulting
432 /// Please note this isn't the same operation as the `<<` shifting
440 /// #![feature(wrapping_int_impl)]
441 /// use std::num::Wrapping;
443 /// let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
444 /// let m: Wrapping<i64> = Wrapping(-0x76543210FEDCBA99);
446 /// assert_eq!(n.rotate_left(32), m);
449 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
450 pub const fn rotate_left(self, n
: u32) -> Self {
451 Wrapping(self.0.rotate_left(n
))
454 /// Shifts the bits to the right by a specified amount, `n`,
455 /// wrapping the truncated bits to the beginning of the resulting
458 /// Please note this isn't the same operation as the `>>` shifting
466 /// #![feature(wrapping_int_impl)]
467 /// use std::num::Wrapping;
469 /// let n: Wrapping<i64> = Wrapping(0x0123456789ABCDEF);
470 /// let m: Wrapping<i64> = Wrapping(-0xFEDCBA987654322);
472 /// assert_eq!(n.rotate_right(4), m);
475 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
476 pub const fn rotate_right(self, n
: u32) -> Self {
477 Wrapping(self.0.rotate_right(n
))
480 /// Reverses the byte order of the integer.
487 /// #![feature(wrapping_int_impl)]
488 /// use std::num::Wrapping;
490 /// let n: Wrapping<i16> = Wrapping(0b0000000_01010101);
491 /// assert_eq!(n, Wrapping(85));
493 /// let m = n.swap_bytes();
495 /// assert_eq!(m, Wrapping(0b01010101_00000000));
496 /// assert_eq!(m, Wrapping(21760));
499 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
500 pub const fn swap_bytes(self) -> Self {
501 Wrapping(self.0.swap_bytes())
504 /// Reverses the bit pattern of the integer.
508 /// Please note that this example is shared between integer types.
509 /// Which explains why `i16` is used here.
514 /// use std::num::Wrapping;
516 /// let n = Wrapping(0b0000000_01010101i16);
517 /// assert_eq!(n, Wrapping(85));
519 /// let m = n.reverse_bits();
521 /// assert_eq!(m.0 as u16, 0b10101010_00000000);
522 /// assert_eq!(m, Wrapping(-22016));
524 #[stable(feature = "reverse_bits", since = "1.37.0")]
525 #[rustc_const_stable(feature = "const_reverse_bits", since = "1.37.0")]
528 pub const fn reverse_bits(self) -> Self {
529 Wrapping(self.0.reverse_bits())
533 concat
!("Converts an integer from big endian to the target's endianness.
535 On big endian this is a no-op. On little endian the bytes are
543 #![feature(wrapping_int_impl)]
544 use std::num::Wrapping;
546 let n = Wrapping(0x1A", stringify
!($t
), ");
548 if cfg!(target_endian = \"big\") {
549 assert_eq!(<Wrapping<", stringify
!($t
), ">>::from_be(n), n)
551 assert_eq!(<Wrapping<", stringify
!($t
), ">>::from_be(n), n.swap_bytes())
555 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
556 pub const fn from_be(x
: Self) -> Self {
557 Wrapping(<$t
>::from_be(x
.0))
562 concat
!("Converts an integer from little endian to the target's endianness.
564 On little endian this is a no-op. On big endian the bytes are
572 #![feature(wrapping_int_impl)]
573 use std::num::Wrapping;
575 let n = Wrapping(0x1A", stringify
!($t
), ");
577 if cfg!(target_endian = \"little\") {
578 assert_eq!(<Wrapping<", stringify
!($t
), ">>::from_le(n), n)
580 assert_eq!(<Wrapping<", stringify
!($t
), ">>::from_le(n), n.swap_bytes())
584 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
585 pub const fn from_le(x
: Self) -> Self {
586 Wrapping(<$t
>::from_le(x
.0))
591 concat
!("Converts `self` to big endian from the target's endianness.
593 On big endian this is a no-op. On little endian the bytes are
601 #![feature(wrapping_int_impl)]
602 use std::num::Wrapping;
604 let n = Wrapping(0x1A", stringify
!($t
), ");
606 if cfg!(target_endian = \"big\") {
607 assert_eq!(n.to_be(), n)
609 assert_eq!(n.to_be(), n.swap_bytes())
613 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
614 pub const fn to_be(self) -> Self {
615 Wrapping(self.0.to_be())
620 concat
!("Converts `self` to little endian from the target's endianness.
622 On little endian this is a no-op. On big endian the bytes are
630 #![feature(wrapping_int_impl)]
631 use std::num::Wrapping;
633 let n = Wrapping(0x1A", stringify
!($t
), ");
635 if cfg!(target_endian = \"little\") {
636 assert_eq!(n.to_le(), n)
638 assert_eq!(n.to_le(), n.swap_bytes())
642 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
643 pub const fn to_le(self) -> Self {
644 Wrapping(self.0.to_le())
649 concat
!("Raises self to the power of `exp`, using exponentiation by squaring.
656 #![feature(wrapping_int_impl)]
657 use std::num::Wrapping;
659 assert_eq!(Wrapping(3", stringify
!($t
), ").pow(4), Wrapping(81));
662 Results that are too large are wrapped:
665 #![feature(wrapping_int_impl)]
666 use std::num::Wrapping;
668 assert_eq!(Wrapping(3i8).pow(5), Wrapping(-13));
669 assert_eq!(Wrapping(3i8).pow(6), Wrapping(-39));
672 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
673 pub fn pow(self, exp
: u32) -> Self {
674 Wrapping(self.0.wrapping_pow(exp
))
681 wrapping_int_impl
! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
683 macro_rules
! wrapping_int_impl_signed
{
687 concat
!("Returns the number of leading zeros in the binary representation of `self`.
694 #![feature(wrapping_int_impl)]
695 use std::num::Wrapping;
697 let n = Wrapping(", stringify
!($t
), "::max_value()) >> 2;
699 assert_eq!(n.leading_zeros(), 3);
702 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
703 pub const fn leading_zeros(self) -> u32 {
704 self.0.leading_zeros()
709 concat
!("Computes the absolute value of `self`, wrapping around at
710 the boundary of the type.
712 The only case where such wrapping can occur is when one takes the absolute value of the negative
713 minimal value for the type this is a positive value that is too large to represent in the type. In
714 such a case, this function returns `MIN` itself.
721 #![feature(wrapping_int_impl)]
722 use std::num::Wrapping;
724 assert_eq!(Wrapping(100", stringify
!($t
), ").abs(), Wrapping(100));
725 assert_eq!(Wrapping(-100", stringify
!($t
), ").abs(), Wrapping(100));
726 assert_eq!(Wrapping(", stringify
!($t
), "::min_value()).abs(), Wrapping(", stringify
!($t
),
728 assert_eq!(Wrapping(-128i8).abs().0 as u8, 128u8);
731 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
732 pub fn abs(self) -> Wrapping
<$t
> {
733 Wrapping(self.0.wrapping_abs())
738 concat
!("Returns a number representing sign of `self`.
740 - `0` if the number is zero
741 - `1` if the number is positive
742 - `-1` if the number is negative
749 #![feature(wrapping_int_impl)]
750 use std::num::Wrapping;
752 assert_eq!(Wrapping(10", stringify
!($t
), ").signum(), Wrapping(1));
753 assert_eq!(Wrapping(0", stringify
!($t
), ").signum(), Wrapping(0));
754 assert_eq!(Wrapping(-10", stringify
!($t
), ").signum(), Wrapping(-1));
757 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
758 pub fn signum(self) -> Wrapping
<$t
> {
759 Wrapping(self.0.signum())
764 concat
!("Returns `true` if `self` is positive and `false` if the number is zero or
772 #![feature(wrapping_int_impl)]
773 use std::num::Wrapping;
775 assert!(Wrapping(10", stringify
!($t
), ").is_positive());
776 assert!(!Wrapping(-10", stringify
!($t
), ").is_positive());
779 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
780 pub const fn is_positive(self) -> bool
{
786 concat
!("Returns `true` if `self` is negative and `false` if the number is zero or
794 #![feature(wrapping_int_impl)]
795 use std::num::Wrapping;
797 assert!(Wrapping(-10", stringify
!($t
), ").is_negative());
798 assert!(!Wrapping(10", stringify
!($t
), ").is_negative());
801 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
802 pub const fn is_negative(self) -> bool
{
810 wrapping_int_impl_signed
! { isize i8 i16 i32 i64 i128 }
812 macro_rules
! wrapping_int_impl_unsigned
{
816 concat
!("Returns the number of leading zeros in the binary representation of `self`.
823 #![feature(wrapping_int_impl)]
824 use std::num::Wrapping;
826 let n = Wrapping(", stringify
!($t
), "::max_value()) >> 2;
828 assert_eq!(n.leading_zeros(), 2);
831 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
832 pub const fn leading_zeros(self) -> u32 {
833 self.0.leading_zeros()
838 concat
!("Returns `true` if and only if `self == 2^k` for some `k`.
845 #![feature(wrapping_int_impl)]
846 use std::num::Wrapping;
848 assert!(Wrapping(16", stringify
!($t
), ").is_power_of_two());
849 assert!(!Wrapping(10", stringify
!($t
), ").is_power_of_two());
852 #[unstable(feature = "wrapping_int_impl", issue = "32463")]
853 pub fn is_power_of_two(self) -> bool
{
854 self.0.is_power_of_two
()
859 concat
!("Returns the smallest power of two greater than or equal to `self`.
861 When return value overflows (i.e., `self > (1 << (N-1))` for type
862 `uN`), overflows to `2^N = 0`.
869 #![feature(wrapping_next_power_of_two)]
870 use std::num::Wrapping;
872 assert_eq!(Wrapping(2", stringify
!($t
), ").next_power_of_two(), Wrapping(2));
873 assert_eq!(Wrapping(3", stringify
!($t
), ").next_power_of_two(), Wrapping(4));
874 assert_eq!(Wrapping(200_u8).next_power_of_two(), Wrapping(0));
877 #[unstable(feature = "wrapping_next_power_of_two", issue = "32463",
878 reason
= "needs decision on wrapping behaviour")]
879 pub fn next_power_of_two(self) -> Self {
880 Wrapping(self.0.wrapping_next_power_of_two())
887 wrapping_int_impl_unsigned
! { usize u8 u16 u32 u64 u128 }
890 #![allow(non_upper_case_globals)]
892 #[cfg(target_pointer_width = "16")]
894 pub const usize: u32 = super::u16;
895 pub const isize: u32 = super::i16;
898 #[cfg(target_pointer_width = "32")]
900 pub const usize: u32 = super::u32;
901 pub const isize: u32 = super::i32;
904 #[cfg(target_pointer_width = "64")]
906 pub const usize: u32 = super::u64;
907 pub const isize: u32 = super::i64;
910 pub const i8: u32 = (1 << 3) - 1;
911 pub const i16: u32 = (1 << 4) - 1;
912 pub const i32: u32 = (1 << 5) - 1;
913 pub const i64: u32 = (1 << 6) - 1;
914 pub const i128
: u32 = (1 << 7) - 1;
915 pub use self::platform
::isize;
917 pub const u8: u32 = i8;
918 pub const u16: u32 = i16;
919 pub const u32: u32 = i32;
920 pub const u64: u32 = i64;
921 pub const u128
: u32 = i128
;
922 pub use self::platform
::usize;