1macro_rules! int_impl {
2    (
3        Self = $SelfT:ty,
4        ActualT = $ActualT:ident,
5        UnsignedT = $UnsignedT:ty,
6
7        BITS = $BITS:literal,
12        BITS_MINUS_ONE = $BITS_MINUS_ONE:literal,
13        Min = $Min:literal,
14        Max = $Max:literal,
15        rot = $rot:literal,
16        rot_op = $rot_op:literal,
17        rot_result = $rot_result:literal,
18        swap_op = $swap_op:literal,
19        swapped = $swapped:literal,
20        reversed = $reversed:literal,
21        le_bytes = $le_bytes:literal,
22        be_bytes = $be_bytes:literal,
23        to_xe_bytes_doc = $to_xe_bytes_doc:expr,
24        from_xe_bytes_doc = $from_xe_bytes_doc:expr,
25        bound_condition = $bound_condition:literal,
26    ) => {
27        #[doc = concat!("(−2<sup>", $BITS_MINUS_ONE, "</sup>", $bound_condition, ").")]
29        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN, ", stringify!($Min), ");")]
34        #[stable(feature = "assoc_int_consts", since = "1.43.0")]
36        pub const MIN: Self = !Self::MAX;
37
38        #[doc = concat!("(2<sup>", $BITS_MINUS_ONE, "</sup> − 1", $bound_condition, ").")]
40        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX, ", stringify!($Max), ");")]
45        #[stable(feature = "assoc_int_consts", since = "1.43.0")]
47        pub const MAX: Self = (<$UnsignedT>::MAX >> 1) as Self;
48
49        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::BITS, ", stringify!($BITS), ");")]
55        #[stable(feature = "int_bits_const", since = "1.53.0")]
57        #[cfg(not(feature = "ferrocene_certified"))]
58        pub const BITS: u32 = <$UnsignedT>::BITS;
59
60        #[doc = concat!("let n = 0b100_0000", stringify!($SelfT), ";")]
66        #[stable(feature = "rust1", since = "1.0.0")]
71        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
72        #[doc(alias = "popcount")]
73        #[doc(alias = "popcnt")]
74        #[must_use = "this returns the result of the operation, \
75                      without modifying the original"]
76        #[inline(always)]
77        #[cfg(not(feature = "ferrocene_certified"))]
78        pub const fn count_ones(self) -> u32 { (self as $UnsignedT).count_ones() }
79
80        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.count_zeros(), 1);")]
86        #[stable(feature = "rust1", since = "1.0.0")]
88        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
89        #[must_use = "this returns the result of the operation, \
90                      without modifying the original"]
91        #[inline(always)]
92        #[cfg(not(feature = "ferrocene_certified"))]
93        pub const fn count_zeros(self) -> u32 {
94            (!self).count_ones()
95        }
96
97        #[doc = concat!("let n = -1", stringify!($SelfT), ";")]
106        #[doc = concat!("[`ilog2`]: ", stringify!($SelfT), "::ilog2")]
110        #[stable(feature = "rust1", since = "1.0.0")]
111        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
112        #[must_use = "this returns the result of the operation, \
113                      without modifying the original"]
114        #[inline(always)]
115        #[cfg(not(feature = "ferrocene_certified"))]
116        pub const fn leading_zeros(self) -> u32 {
117            (self as $UnsignedT).leading_zeros()
118        }
119
120        #[doc = concat!("let n = -4", stringify!($SelfT), ";")]
126        #[stable(feature = "rust1", since = "1.0.0")]
130        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
131        #[must_use = "this returns the result of the operation, \
132                      without modifying the original"]
133        #[inline(always)]
134        #[cfg(not(feature = "ferrocene_certified"))]
135        pub const fn trailing_zeros(self) -> u32 {
136            (self as $UnsignedT).trailing_zeros()
137        }
138
139        #[doc = concat!("let n = -1", stringify!($SelfT), ";")]
145        #[doc = concat!("assert_eq!(n.leading_ones(), ", stringify!($BITS), ");")]
147        #[stable(feature = "leading_trailing_ones", since = "1.46.0")]
149        #[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")]
150        #[must_use = "this returns the result of the operation, \
151                      without modifying the original"]
152        #[inline(always)]
153        #[cfg(not(feature = "ferrocene_certified"))]
154        pub const fn leading_ones(self) -> u32 {
155            (self as $UnsignedT).leading_ones()
156        }
157
158        #[doc = concat!("let n = 3", stringify!($SelfT), ";")]
164        #[stable(feature = "leading_trailing_ones", since = "1.46.0")]
168        #[rustc_const_stable(feature = "leading_trailing_ones", since = "1.46.0")]
169        #[must_use = "this returns the result of the operation, \
170                      without modifying the original"]
171        #[inline(always)]
172        #[cfg(not(feature = "ferrocene_certified"))]
173        pub const fn trailing_ones(self) -> u32 {
174            (self as $UnsignedT).trailing_ones()
175        }
176
177        #[doc = concat!("let n: ", stringify!($SelfT), " = 0b_01100100;")]
186        #[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".isolate_highest_one(), 0);")]
189        #[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
191        #[must_use = "this returns the result of the operation, \
192                      without modifying the original"]
193        #[inline(always)]
194        #[cfg(not(feature = "ferrocene_certified"))]
195        pub const fn isolate_highest_one(self) -> Self {
196            self & (((1 as $SelfT) << (<$SelfT>::BITS - 1)).wrapping_shr(self.leading_zeros()))
197        }
198
199        #[doc = concat!("let n: ", stringify!($SelfT), " = 0b_01100100;")]
208        #[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".isolate_lowest_one(), 0);")]
211        #[unstable(feature = "isolate_most_least_significant_one", issue = "136909")]
213        #[must_use = "this returns the result of the operation, \
214                      without modifying the original"]
215        #[inline(always)]
216        #[cfg(not(feature = "ferrocene_certified"))]
217        pub const fn isolate_lowest_one(self) -> Self {
218            self & self.wrapping_neg()
219        }
220
221        #[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".highest_one(), None);")]
230        #[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".highest_one(), Some(0));")]
231        #[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".highest_one(), Some(4));")]
232        #[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".highest_one(), Some(4));")]
233        #[unstable(feature = "int_lowest_highest_one", issue = "145203")]
235        #[must_use = "this returns the result of the operation, \
236                      without modifying the original"]
237        #[inline(always)]
238        #[cfg(not(feature = "ferrocene_certified"))]
239        pub const fn highest_one(self) -> Option<u32> {
240            (self as $UnsignedT).highest_one()
241        }
242
243        #[doc = concat!("assert_eq!(0x0_", stringify!($SelfT), ".lowest_one(), None);")]
252        #[doc = concat!("assert_eq!(0x1_", stringify!($SelfT), ".lowest_one(), Some(0));")]
253        #[doc = concat!("assert_eq!(0x10_", stringify!($SelfT), ".lowest_one(), Some(4));")]
254        #[doc = concat!("assert_eq!(0x1f_", stringify!($SelfT), ".lowest_one(), Some(0));")]
255        #[unstable(feature = "int_lowest_highest_one", issue = "145203")]
257        #[must_use = "this returns the result of the operation, \
258                      without modifying the original"]
259        #[inline(always)]
260        #[cfg(not(feature = "ferrocene_certified"))]
261        pub const fn lowest_one(self) -> Option<u32> {
262            (self as $UnsignedT).lowest_one()
263        }
264
265        #[doc = concat!("let n = -1", stringify!($SelfT), ";")]
274        #[doc = concat!("assert_eq!(n.cast_unsigned(), ", stringify!($UnsignedT), "::MAX);")]
276        #[stable(feature = "integer_sign_cast", since = "1.87.0")]
278        #[rustc_const_stable(feature = "integer_sign_cast", since = "1.87.0")]
279        #[must_use = "this returns the result of the operation, \
280                      without modifying the original"]
281        #[inline(always)]
282        #[cfg(not(feature = "ferrocene_certified"))]
283        pub const fn cast_unsigned(self) -> $UnsignedT {
284            self as $UnsignedT
285        }
286
287        #[doc = concat!("let n = ", $rot_op, stringify!($SelfT), ";")]
296        #[doc = concat!("let m = ", $rot_result, ";")]
297        #[doc = concat!("assert_eq!(n.rotate_left(", $rot, "), m);")]
299        #[stable(feature = "rust1", since = "1.0.0")]
301        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
302        #[must_use = "this returns the result of the operation, \
303                      without modifying the original"]
304        #[inline(always)]
305        #[cfg(not(feature = "ferrocene_certified"))]
306        pub const fn rotate_left(self, n: u32) -> Self {
307            (self as $UnsignedT).rotate_left(n) as Self
308        }
309
310        #[doc = concat!("let n = ", $rot_result, stringify!($SelfT), ";")]
320        #[doc = concat!("let m = ", $rot_op, ";")]
321        #[doc = concat!("assert_eq!(n.rotate_right(", $rot, "), m);")]
323        #[stable(feature = "rust1", since = "1.0.0")]
325        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
326        #[must_use = "this returns the result of the operation, \
327                      without modifying the original"]
328        #[inline(always)]
329        #[cfg(not(feature = "ferrocene_certified"))]
330        pub const fn rotate_right(self, n: u32) -> Self {
331            (self as $UnsignedT).rotate_right(n) as Self
332        }
333
334        #[doc = concat!("let n = ", $swap_op, stringify!($SelfT), ";")]
340        #[doc = concat!("assert_eq!(m, ", $swapped, ");")]
344        #[stable(feature = "rust1", since = "1.0.0")]
346        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
347        #[must_use = "this returns the result of the operation, \
348                      without modifying the original"]
349        #[inline(always)]
350        #[cfg(not(feature = "ferrocene_certified"))]
351        pub const fn swap_bytes(self) -> Self {
352            (self as $UnsignedT).swap_bytes() as Self
353        }
354
355        #[doc = concat!("let n = ", $swap_op, stringify!($SelfT), ";")]
362        #[doc = concat!("assert_eq!(m, ", $reversed, ");")]
365        #[doc = concat!("assert_eq!(0, 0", stringify!($SelfT), ".reverse_bits());")]
366        #[stable(feature = "reverse_bits", since = "1.37.0")]
368        #[rustc_const_stable(feature = "reverse_bits", since = "1.37.0")]
369        #[must_use = "this returns the result of the operation, \
370                      without modifying the original"]
371        #[inline(always)]
372        #[cfg(not(feature = "ferrocene_certified"))]
373        pub const fn reverse_bits(self) -> Self {
374            (self as $UnsignedT).reverse_bits() as Self
375        }
376
377        #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
385        #[doc = concat!("    assert_eq!(", stringify!($SelfT), "::from_be(n), n)")]
388        #[doc = concat!("    assert_eq!(", stringify!($SelfT), "::from_be(n), n.swap_bytes())")]
390        #[stable(feature = "rust1", since = "1.0.0")]
393        #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
394        #[must_use]
395        #[inline]
396        #[cfg(not(feature = "ferrocene_certified"))]
397        pub const fn from_be(x: Self) -> Self {
398            #[cfg(target_endian = "big")]
399            {
400                x
401            }
402            #[cfg(not(target_endian = "big"))]
403            {
404                x.swap_bytes()
405            }
406        }
407
408        #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
416        #[doc = concat!("    assert_eq!(", stringify!($SelfT), "::from_le(n), n)")]
419        #[doc = concat!("    assert_eq!(", stringify!($SelfT), "::from_le(n), n.swap_bytes())")]
421        #[stable(feature = "rust1", since = "1.0.0")]
424        #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
425        #[must_use]
426        #[inline]
427        pub const fn from_le(x: Self) -> Self {
428            #[cfg(target_endian = "little")]
429            {
430                x
431            }
432            #[cfg(not(target_endian = "little"))]
433            {
434                x.swap_bytes()
435            }
436        }
437
438        #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
446        #[stable(feature = "rust1", since = "1.0.0")]
454        #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
455        #[must_use = "this returns the result of the operation, \
456                      without modifying the original"]
457        #[inline]
458        #[cfg(not(feature = "ferrocene_certified"))]
459        pub const fn to_be(self) -> Self { #[cfg(target_endian = "big")]
461            {
462                self
463            }
464            #[cfg(not(target_endian = "big"))]
465            {
466                self.swap_bytes()
467            }
468        }
469
470        #[doc = concat!("let n = 0x1A", stringify!($SelfT), ";")]
478        #[stable(feature = "rust1", since = "1.0.0")]
486        #[rustc_const_stable(feature = "const_int_conversions", since = "1.32.0")]
487        #[must_use = "this returns the result of the operation, \
488                      without modifying the original"]
489        #[inline]
490        pub const fn to_le(self) -> Self {
491            #[cfg(target_endian = "little")]
492            {
493                self
494            }
495            #[cfg(not(target_endian = "little"))]
496            {
497                self.swap_bytes()
498            }
499        }
500
501        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(1), Some(", stringify!($SelfT), "::MAX - 1));")]
508        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);")]
509        #[stable(feature = "rust1", since = "1.0.0")]
511        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
512        #[must_use = "this returns the result of the operation, \
513                      without modifying the original"]
514        #[inline]
515        #[cfg(not(feature = "ferrocene_certified"))]
516        pub const fn checked_add(self, rhs: Self) -> Option<Self> {
517            let (a, b) = self.overflowing_add(rhs);
518            if intrinsics::unlikely(b) { None } else { Some(a) }
519        }
520
521        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).strict_add(1), ", stringify!($SelfT), "::MAX - 1);")]
534        #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add(3);")]
540        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
542        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
543        #[must_use = "this returns the result of the operation, \
544                      without modifying the original"]
545        #[inline]
546        #[track_caller]
547        #[cfg(not(feature = "ferrocene_certified"))]
548        pub const fn strict_add(self, rhs: Self) -> Self {
549            let (a, b) = self.overflowing_add(rhs);
550            if b { overflow_panic::add() } else { a }
551        }
552
553        #[doc = concat!("`self + rhs > ", stringify!($SelfT), "::MAX` or `self + rhs < ", stringify!($SelfT), "::MIN`,")]
566        #[doc = concat!("[`checked_add`]: ", stringify!($SelfT), "::checked_add")]
570        #[doc = concat!("[`wrapping_add`]: ", stringify!($SelfT), "::wrapping_add")]
571        #[stable(feature = "unchecked_math", since = "1.79.0")]
572        #[rustc_const_stable(feature = "unchecked_math", since = "1.79.0")]
573        #[must_use = "this returns the result of the operation, \
574                      without modifying the original"]
575        #[inline(always)]
576        #[track_caller]
577        #[cfg(not(feature = "ferrocene_certified"))]
578        pub const unsafe fn unchecked_add(self, rhs: Self) -> Self {
579            assert_unsafe_precondition!(
580                check_language_ub,
581                concat!(stringify!($SelfT), "::unchecked_add cannot overflow"),
582                (
583                    lhs: $SelfT = self,
584                    rhs: $SelfT = rhs,
585                ) => !lhs.overflowing_add(rhs).1,
586            );
587
588            unsafe {
590                intrinsics::unchecked_add(self, rhs)
591            }
592        }
593
594        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_unsigned(2), Some(3));")]
601        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add_unsigned(3), None);")]
602        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
604        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
605        #[must_use = "this returns the result of the operation, \
606                      without modifying the original"]
607        #[inline]
608        #[cfg(not(feature = "ferrocene_certified"))]
609        pub const fn checked_add_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
610            let (a, b) = self.overflowing_add_unsigned(rhs);
611            if intrinsics::unlikely(b) { None } else { Some(a) }
612        }
613
614        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_add_unsigned(2), 3);")]
627        #[doc = concat!("let _ = (", stringify!($SelfT), "::MAX - 2).strict_add_unsigned(3);")]
633        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
635        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
636        #[must_use = "this returns the result of the operation, \
637                      without modifying the original"]
638        #[inline]
639        #[track_caller]
640        #[cfg(not(feature = "ferrocene_certified"))]
641        pub const fn strict_add_unsigned(self, rhs: $UnsignedT) -> Self {
642            let (a, b) = self.overflowing_add_unsigned(rhs);
643            if b { overflow_panic::add() } else { a }
644        }
645
646        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(1), Some(", stringify!($SelfT), "::MIN + 1));")]
653        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub(3), None);")]
654        #[stable(feature = "rust1", since = "1.0.0")]
656        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
657        #[must_use = "this returns the result of the operation, \
658                      without modifying the original"]
659        #[inline]
660        #[cfg(not(feature = "ferrocene_certified"))]
661        pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
662            let (a, b) = self.overflowing_sub(rhs);
663            if intrinsics::unlikely(b) { None } else { Some(a) }
664        }
665
666        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).strict_sub(1), ", stringify!($SelfT), "::MIN + 1);")]
679        #[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub(3);")]
685        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
687        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
688        #[must_use = "this returns the result of the operation, \
689                      without modifying the original"]
690        #[inline]
691        #[track_caller]
692        #[cfg(not(feature = "ferrocene_certified"))]
693        pub const fn strict_sub(self, rhs: Self) -> Self {
694            let (a, b) = self.overflowing_sub(rhs);
695            if b { overflow_panic::sub() } else { a }
696        }
697
698        #[doc = concat!("`self - rhs > ", stringify!($SelfT), "::MAX` or `self - rhs < ", stringify!($SelfT), "::MIN`,")]
711        #[doc = concat!("[`checked_sub`]: ", stringify!($SelfT), "::checked_sub")]
715        #[doc = concat!("[`wrapping_sub`]: ", stringify!($SelfT), "::wrapping_sub")]
716        #[stable(feature = "unchecked_math", since = "1.79.0")]
717        #[rustc_const_stable(feature = "unchecked_math", since = "1.79.0")]
718        #[must_use = "this returns the result of the operation, \
719                      without modifying the original"]
720        #[inline(always)]
721        #[track_caller]
722        #[cfg(not(feature = "ferrocene_certified"))]
723        pub const unsafe fn unchecked_sub(self, rhs: Self) -> Self {
724            assert_unsafe_precondition!(
725                check_language_ub,
726                concat!(stringify!($SelfT), "::unchecked_sub cannot overflow"),
727                (
728                    lhs: $SelfT = self,
729                    rhs: $SelfT = rhs,
730                ) => !lhs.overflowing_sub(rhs).1,
731            );
732
733            unsafe {
735                intrinsics::unchecked_sub(self, rhs)
736            }
737        }
738
739        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_sub_unsigned(2), Some(-1));")]
746        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub_unsigned(3), None);")]
747        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
749        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
750        #[must_use = "this returns the result of the operation, \
751                      without modifying the original"]
752        #[inline]
753        #[cfg(not(feature = "ferrocene_certified"))]
754        pub const fn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option<Self> {
755            let (a, b) = self.overflowing_sub_unsigned(rhs);
756            if intrinsics::unlikely(b) { None } else { Some(a) }
757        }
758
759        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".strict_sub_unsigned(2), -1);")]
772        #[doc = concat!("let _ = (", stringify!($SelfT), "::MIN + 2).strict_sub_unsigned(3);")]
778        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
780        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
781        #[must_use = "this returns the result of the operation, \
782                      without modifying the original"]
783        #[inline]
784        #[track_caller]
785        #[cfg(not(feature = "ferrocene_certified"))]
786        pub const fn strict_sub_unsigned(self, rhs: $UnsignedT) -> Self {
787            let (a, b) = self.overflowing_sub_unsigned(rhs);
788            if b { overflow_panic::sub() } else { a }
789        }
790
791        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(1), Some(", stringify!($SelfT), "::MAX));")]
798        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_mul(2), None);")]
799        #[stable(feature = "rust1", since = "1.0.0")]
801        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
802        #[must_use = "this returns the result of the operation, \
803                      without modifying the original"]
804        #[inline]
805        #[cfg(not(feature = "ferrocene_certified"))]
806        pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
807            let (a, b) = self.overflowing_mul(rhs);
808            if intrinsics::unlikely(b) { None } else { Some(a) }
809        }
810
811        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.strict_mul(1), ", stringify!($SelfT), "::MAX);")]
824        #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_mul(2);")]
830        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
832        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
833        #[must_use = "this returns the result of the operation, \
834                      without modifying the original"]
835        #[inline]
836        #[track_caller]
837        #[cfg(not(feature = "ferrocene_certified"))]
838        pub const fn strict_mul(self, rhs: Self) -> Self {
839            let (a, b) = self.overflowing_mul(rhs);
840            if b { overflow_panic::mul() } else { a }
841        }
842
843        #[doc = concat!("`self * rhs > ", stringify!($SelfT), "::MAX` or `self * rhs < ", stringify!($SelfT), "::MIN`,")]
856        #[doc = concat!("[`checked_mul`]: ", stringify!($SelfT), "::checked_mul")]
860        #[doc = concat!("[`wrapping_mul`]: ", stringify!($SelfT), "::wrapping_mul")]
861        #[stable(feature = "unchecked_math", since = "1.79.0")]
862        #[rustc_const_stable(feature = "unchecked_math", since = "1.79.0")]
863        #[must_use = "this returns the result of the operation, \
864                      without modifying the original"]
865        #[inline(always)]
866        #[track_caller]
867        #[cfg(not(feature = "ferrocene_certified"))]
868        pub const unsafe fn unchecked_mul(self, rhs: Self) -> Self {
869            assert_unsafe_precondition!(
870                check_language_ub,
871                concat!(stringify!($SelfT), "::unchecked_mul cannot overflow"),
872                (
873                    lhs: $SelfT = self,
874                    rhs: $SelfT = rhs,
875                ) => !lhs.overflowing_mul(rhs).1,
876            );
877
878            unsafe {
880                intrinsics::unchecked_mul(self, rhs)
881            }
882        }
883
884        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div(-1), Some(", stringify!($Max), "));")]
891        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div(-1), None);")]
892        #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div(0), None);")]
893        #[stable(feature = "rust1", since = "1.0.0")]
895        #[rustc_const_stable(feature = "const_checked_int_div", since = "1.52.0")]
896        #[must_use = "this returns the result of the operation, \
897                      without modifying the original"]
898        #[inline]
899        #[cfg(not(feature = "ferrocene_certified"))]
900        pub const fn checked_div(self, rhs: Self) -> Option<Self> {
901            if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
902                None
903            } else {
904                Some(unsafe { intrinsics::unchecked_div(self, rhs) })
906            }
907        }
908
909        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).strict_div(-1), ", stringify!($Max), ");")]
928        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_div(-1);")]
934        #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div(0);")]
940        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
942        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
943        #[must_use = "this returns the result of the operation, \
944                      without modifying the original"]
945        #[inline]
946        #[track_caller]
947        #[cfg(not(feature = "ferrocene_certified"))]
948        pub const fn strict_div(self, rhs: Self) -> Self {
949            let (a, b) = self.overflowing_div(rhs);
950            if b { overflow_panic::div() } else { a }
951        }
952
953        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_div_euclid(-1), Some(", stringify!($Max), "));")]
960        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_div_euclid(-1), None);")]
961        #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_div_euclid(0), None);")]
962        #[stable(feature = "euclidean_division", since = "1.38.0")]
964        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
965        #[must_use = "this returns the result of the operation, \
966                      without modifying the original"]
967        #[inline]
968        #[cfg(not(feature = "ferrocene_certified"))]
969        pub const fn checked_div_euclid(self, rhs: Self) -> Option<Self> {
970            if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
972                None
973            } else {
974                Some(self.div_euclid(rhs))
975            }
976        }
977
978        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).strict_div_euclid(-1), ", stringify!($Max), ");")]
997        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_div_euclid(-1);")]
1003        #[doc = concat!("let _ = (1", stringify!($SelfT), ").strict_div_euclid(0);")]
1009        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1011        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1012        #[must_use = "this returns the result of the operation, \
1013                      without modifying the original"]
1014        #[inline]
1015        #[track_caller]
1016        #[cfg(not(feature = "ferrocene_certified"))]
1017        pub const fn strict_div_euclid(self, rhs: Self) -> Self {
1018            let (a, b) = self.overflowing_div_euclid(rhs);
1019            if b { overflow_panic::div() } else { a }
1020        }
1021
1022        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).checked_exact_div(-1), Some(", stringify!($Max), "));")]
1031        #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_exact_div(2), None);")]
1032        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_exact_div(-1), None);")]
1033        #[doc = concat!("assert_eq!((1", stringify!($SelfT), ").checked_exact_div(0), None);")]
1034        #[unstable(
1036            feature = "exact_div",
1037            issue = "139911",
1038        )]
1039        #[must_use = "this returns the result of the operation, \
1040                      without modifying the original"]
1041        #[inline]
1042        #[cfg(not(feature = "ferrocene_certified"))]
1043        pub const fn checked_exact_div(self, rhs: Self) -> Option<Self> {
1044            if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
1045                None
1046            } else {
1047                unsafe {
1049                    if intrinsics::unlikely(intrinsics::unchecked_rem(self, rhs) != 0) {
1050                        None
1051                    } else {
1052                        Some(intrinsics::exact_div(self, rhs))
1053                    }
1054                }
1055            }
1056        }
1057
1058        #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(2), 32);")]
1070        #[doc = concat!("assert_eq!(64", stringify!($SelfT), ".exact_div(32), 2);")]
1071        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).exact_div(-1), ", stringify!($Max), ");")]
1072        #[doc = concat!("let _ = 65", stringify!($SelfT), ".exact_div(2);")]
1077        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.exact_div(-1);")]
1081        #[unstable(
1083            feature = "exact_div",
1084            issue = "139911",
1085        )]
1086        #[must_use = "this returns the result of the operation, \
1087                      without modifying the original"]
1088        #[inline]
1089        #[cfg(not(feature = "ferrocene_certified"))]
1090        pub const fn exact_div(self, rhs: Self) -> Self {
1091            match self.checked_exact_div(rhs) {
1092                Some(x) => x,
1093                None => panic!("Failed to divide without remainder"),
1094            }
1095        }
1096
1097        #[doc = concat!("`self == ", stringify!($SelfT), "::MIN && rhs == -1`,")]
1103        #[unstable(
1105            feature = "exact_div",
1106            issue = "139911",
1107        )]
1108        #[must_use = "this returns the result of the operation, \
1109                      without modifying the original"]
1110        #[inline]
1111        #[cfg(not(feature = "ferrocene_certified"))]
1112        pub const unsafe fn unchecked_exact_div(self, rhs: Self) -> Self {
1113            assert_unsafe_precondition!(
1114                check_language_ub,
1115                concat!(stringify!($SelfT), "::unchecked_exact_div cannot overflow, divide by zero, or leave a remainder"),
1116                (
1117                    lhs: $SelfT = self,
1118                    rhs: $SelfT = rhs,
1119                ) => rhs > 0 && lhs % rhs == 0 && (lhs != <$SelfT>::MIN || rhs != -1),
1120            );
1121            unsafe { intrinsics::exact_div(self, rhs) }
1123        }
1124
1125        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(2), Some(1));")]
1132        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem(0), None);")]
1133        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem(-1), None);")]
1134        #[stable(feature = "wrapping", since = "1.7.0")]
1136        #[rustc_const_stable(feature = "const_checked_int_div", since = "1.52.0")]
1137        #[must_use = "this returns the result of the operation, \
1138                      without modifying the original"]
1139        #[inline]
1140        #[cfg(not(feature = "ferrocene_certified"))]
1141        pub const fn checked_rem(self, rhs: Self) -> Option<Self> {
1142            if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) && (rhs == -1))) {
1143                None
1144            } else {
1145                Some(unsafe { intrinsics::unchecked_rem(self, rhs) })
1147            }
1148        }
1149
1150        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_rem(2), 1);")]
1168        #[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem(0);")]
1174        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem(-1);")]
1180        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1182        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1183        #[must_use = "this returns the result of the operation, \
1184                      without modifying the original"]
1185        #[inline]
1186        #[track_caller]
1187        #[cfg(not(feature = "ferrocene_certified"))]
1188        pub const fn strict_rem(self, rhs: Self) -> Self {
1189            let (a, b) = self.overflowing_rem(rhs);
1190            if b { overflow_panic::rem() } else { a }
1191        }
1192
1193        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(2), Some(1));")]
1200        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_rem_euclid(0), None);")]
1201        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_rem_euclid(-1), None);")]
1202        #[stable(feature = "euclidean_division", since = "1.38.0")]
1204        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
1205        #[must_use = "this returns the result of the operation, \
1206                      without modifying the original"]
1207        #[inline]
1208        #[cfg(not(feature = "ferrocene_certified"))]
1209        pub const fn checked_rem_euclid(self, rhs: Self) -> Option<Self> {
1210            if intrinsics::unlikely(rhs == 0 || ((self == Self::MIN) & (rhs == -1))) {
1212                None
1213            } else {
1214                Some(self.rem_euclid(rhs))
1215            }
1216        }
1217
1218        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_rem_euclid(2), 1);")]
1236        #[doc = concat!("let _ = 5", stringify!($SelfT), ".strict_rem_euclid(0);")]
1242        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_rem_euclid(-1);")]
1248        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1250        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1251        #[must_use = "this returns the result of the operation, \
1252                      without modifying the original"]
1253        #[inline]
1254        #[track_caller]
1255        #[cfg(not(feature = "ferrocene_certified"))]
1256        pub const fn strict_rem_euclid(self, rhs: Self) -> Self {
1257            let (a, b) = self.overflowing_rem_euclid(rhs);
1258            if b { overflow_panic::rem() } else { a }
1259        }
1260
1261        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_neg(), Some(-5));")]
1267        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_neg(), None);")]
1268        #[stable(feature = "wrapping", since = "1.7.0")]
1270        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
1271        #[must_use = "this returns the result of the operation, \
1272                      without modifying the original"]
1273        #[inline]
1274        #[cfg(not(feature = "ferrocene_certified"))]
1275        pub const fn checked_neg(self) -> Option<Self> {
1276            let (a, b) = self.overflowing_neg();
1277            if intrinsics::unlikely(b) { None } else { Some(a) }
1278        }
1279
1280        #[doc = concat!("`self == ", stringify!($SelfT), "::MIN`,")]
1286        #[doc = concat!("[`checked_neg`]: ", stringify!($SelfT), "::checked_neg")]
1289        #[unstable(
1290            feature = "unchecked_neg",
1291            reason = "niche optimization path",
1292            issue = "85122",
1293        )]
1294        #[must_use = "this returns the result of the operation, \
1295                      without modifying the original"]
1296        #[inline(always)]
1297        #[track_caller]
1298        #[cfg(not(feature = "ferrocene_certified"))]
1299        pub const unsafe fn unchecked_neg(self) -> Self {
1300            assert_unsafe_precondition!(
1301                check_language_ub,
1302                concat!(stringify!($SelfT), "::unchecked_neg cannot overflow"),
1303                (
1304                    lhs: $SelfT = self,
1305                ) => !lhs.overflowing_neg().1,
1306            );
1307
1308            unsafe {
1310                intrinsics::unchecked_sub(0, self)
1311            }
1312        }
1313
1314        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".strict_neg(), -5);")]
1326        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_neg();")]
1332        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1334        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1335        #[must_use = "this returns the result of the operation, \
1336                      without modifying the original"]
1337        #[inline]
1338        #[track_caller]
1339        #[cfg(not(feature = "ferrocene_certified"))]
1340        pub const fn strict_neg(self) -> Self {
1341            let (a, b) = self.overflowing_neg();
1342            if b { overflow_panic::neg() } else { a }
1343        }
1344
1345        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(4), Some(0x10));")]
1352        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".checked_shl(129), None);")]
1353        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shl(", stringify!($BITS_MINUS_ONE), "), Some(0));")]
1354        #[stable(feature = "wrapping", since = "1.7.0")]
1356        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
1357        #[must_use = "this returns the result of the operation, \
1358                      without modifying the original"]
1359        #[inline]
1360        #[cfg(not(feature = "ferrocene_certified"))]
1361        pub const fn checked_shl(self, rhs: u32) -> Option<Self> {
1362            if rhs < Self::BITS {
1364                Some(unsafe { self.unchecked_shl(rhs) })
1366            } else {
1367                None
1368            }
1369        }
1370
1371        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".strict_shl(4), 0x10);")]
1384        #[doc = concat!("let _ = 0x1", stringify!($SelfT), ".strict_shl(129);")]
1390        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1392        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1393        #[must_use = "this returns the result of the operation, \
1394                      without modifying the original"]
1395        #[inline]
1396        #[track_caller]
1397        #[cfg(not(feature = "ferrocene_certified"))]
1398        pub const fn strict_shl(self, rhs: u32) -> Self {
1399            let (a, b) = self.overflowing_shl(rhs);
1400            if b { overflow_panic::shl() } else { a }
1401        }
1402
1403        #[doc = concat!("[`checked_shl`]: ", stringify!($SelfT), "::checked_shl")]
1413        #[unstable(
1414            feature = "unchecked_shifts",
1415            reason = "niche optimization path",
1416            issue = "85122",
1417        )]
1418        #[must_use = "this returns the result of the operation, \
1419                      without modifying the original"]
1420        #[inline(always)]
1421        #[track_caller]
1422        #[cfg(not(feature = "ferrocene_certified"))]
1423        pub const unsafe fn unchecked_shl(self, rhs: u32) -> Self {
1424            assert_unsafe_precondition!(
1425                check_language_ub,
1426                concat!(stringify!($SelfT), "::unchecked_shl cannot overflow"),
1427                (
1428                    rhs: u32 = rhs,
1429                ) => rhs < <$ActualT>::BITS,
1430            );
1431
1432            unsafe {
1434                intrinsics::unchecked_shl(self, rhs)
1435            }
1436        }
1437
1438        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(4), 0x10);")]
1447        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".unbounded_shl(129), 0);")]
1448        #[stable(feature = "unbounded_shifts", since = "1.87.0")]
1450        #[rustc_const_stable(feature = "unbounded_shifts", since = "1.87.0")]
1451        #[must_use = "this returns the result of the operation, \
1452                      without modifying the original"]
1453        #[inline]
1454        #[cfg(not(feature = "ferrocene_certified"))]
1455        pub const fn unbounded_shl(self, rhs: u32) -> $SelfT{
1456            if rhs < Self::BITS {
1457                unsafe { self.unchecked_shl(rhs) }
1460            } else {
1461                0
1462            }
1463        }
1464
1465        #[doc = concat!("`", stringify!($SelfT), "::BITS`.")]
1470        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(4), Some(0x10));")]
1478        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 2), Some(1 << ", stringify!($SelfT), "::BITS - 2));")]
1479        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT), ".exact_shl(", stringify!($SelfT), "::BITS - 1), None);")]
1480        #[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 2), Some(-0x2 << ", stringify!($SelfT), "::BITS - 2));")]
1481        #[doc = concat!("assert_eq!((-0x2", stringify!($SelfT), ").exact_shl(", stringify!($SelfT), "::BITS - 1), None);")]
1482        #[unstable(feature = "exact_bitshifts", issue = "144336")]
1484        #[must_use = "this returns the result of the operation, \
1485                      without modifying the original"]
1486        #[inline]
1487        #[cfg(not(feature = "ferrocene_certified"))]
1488        pub const fn exact_shl(self, rhs: u32) -> Option<$SelfT> {
1489            if rhs < self.leading_zeros() || rhs < self.leading_ones() {
1490                Some(unsafe { self.unchecked_shl(rhs) })
1492            } else {
1493                None
1494            }
1495        }
1496
1497        #[doc = concat!("`", stringify!($SelfT), "::BITS`.")]
1500        #[doc = concat!("[`", stringify!($SelfT), "::exact_shl`]")]
1506        #[unstable(feature = "exact_bitshifts", issue = "144336")]
1508        #[must_use = "this returns the result of the operation, \
1509                      without modifying the original"]
1510        #[inline]
1511        #[cfg(not(feature = "ferrocene_certified"))]
1512        pub const unsafe fn unchecked_exact_shl(self, rhs: u32) -> $SelfT {
1513            assert_unsafe_precondition!(
1514                check_library_ub,
1515                concat!(stringify!($SelfT), "::unchecked_exact_shl cannot shift out bits that would change the value of the first bit"),
1516                (
1517                    zeros: u32 = self.leading_zeros(),
1518                    ones: u32 = self.leading_ones(),
1519                    rhs: u32 = rhs,
1520                ) => rhs < zeros || rhs < ones,
1521            );
1522
1523            unsafe { self.unchecked_shl(rhs) }
1525        }
1526
1527        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shr(4), Some(0x1));")]
1534        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".checked_shr(128), None);")]
1535        #[stable(feature = "wrapping", since = "1.7.0")]
1537        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
1538        #[must_use = "this returns the result of the operation, \
1539                      without modifying the original"]
1540        #[inline]
1541        #[cfg(not(feature = "ferrocene_certified"))]
1542        pub const fn checked_shr(self, rhs: u32) -> Option<Self> {
1543            if rhs < Self::BITS {
1545                Some(unsafe { self.unchecked_shr(rhs) })
1547            } else {
1548                None
1549            }
1550        }
1551
1552        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".strict_shr(4), 0x1);")]
1565        #[doc = concat!("let _ = 0x10", stringify!($SelfT), ".strict_shr(128);")]
1571        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1573        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1574        #[must_use = "this returns the result of the operation, \
1575                      without modifying the original"]
1576        #[inline]
1577        #[track_caller]
1578        #[cfg(not(feature = "ferrocene_certified"))]
1579        pub const fn strict_shr(self, rhs: u32) -> Self {
1580            let (a, b) = self.overflowing_shr(rhs);
1581            if b { overflow_panic::shr() } else { a }
1582        }
1583
1584        #[doc = concat!("[`checked_shr`]: ", stringify!($SelfT), "::checked_shr")]
1594        #[unstable(
1595            feature = "unchecked_shifts",
1596            reason = "niche optimization path",
1597            issue = "85122",
1598        )]
1599        #[must_use = "this returns the result of the operation, \
1600                      without modifying the original"]
1601        #[inline(always)]
1602        #[track_caller]
1603        #[cfg(not(feature = "ferrocene_certified"))]
1604        pub const unsafe fn unchecked_shr(self, rhs: u32) -> Self {
1605            assert_unsafe_precondition!(
1606                check_language_ub,
1607                concat!(stringify!($SelfT), "::unchecked_shr cannot overflow"),
1608                (
1609                    rhs: u32 = rhs,
1610                ) => rhs < <$ActualT>::BITS,
1611            );
1612
1613            unsafe {
1615                intrinsics::unchecked_shr(self, rhs)
1616            }
1617        }
1618
1619        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(4), 0x1);")]
1629        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".unbounded_shr(129), 0);")]
1630        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.unbounded_shr(129), -1);")]
1631        #[stable(feature = "unbounded_shifts", since = "1.87.0")]
1633        #[rustc_const_stable(feature = "unbounded_shifts", since = "1.87.0")]
1634        #[must_use = "this returns the result of the operation, \
1635                      without modifying the original"]
1636        #[inline]
1637        #[cfg(not(feature = "ferrocene_certified"))]
1638        pub const fn unbounded_shr(self, rhs: u32) -> $SelfT{
1639            if rhs < Self::BITS {
1640                unsafe { self.unchecked_shr(rhs) }
1643            } else {
1644                unsafe { self.unchecked_shr(Self::BITS - 1) }
1649            }
1650        }
1651
1652        #[doc = concat!("`", stringify!($SelfT), "::BITS`.")]
1656        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(4), Some(0x1));")]
1664        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".exact_shr(5), None);")]
1665        #[unstable(feature = "exact_bitshifts", issue = "144336")]
1667        #[must_use = "this returns the result of the operation, \
1668                      without modifying the original"]
1669        #[inline]
1670        #[cfg(not(feature = "ferrocene_certified"))]
1671        pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
1672            if rhs <= self.trailing_zeros() && rhs < <$SelfT>::BITS {
1673                Some(unsafe { self.unchecked_shr(rhs) })
1675            } else {
1676                None
1677            }
1678        }
1679
1680        #[doc = concat!("`", stringify!($SelfT), "::BITS`.")]
1683        #[doc = concat!(stringify!($SelfT), "::BITS`")]
1688        #[doc = concat!("[`", stringify!($SelfT), "::exact_shr`]")]
1690        #[unstable(feature = "exact_bitshifts", issue = "144336")]
1692        #[must_use = "this returns the result of the operation, \
1693                      without modifying the original"]
1694        #[inline]
1695        #[cfg(not(feature = "ferrocene_certified"))]
1696        pub const unsafe fn unchecked_exact_shr(self, rhs: u32) -> $SelfT {
1697            assert_unsafe_precondition!(
1698                check_library_ub,
1699                concat!(stringify!($SelfT), "::unchecked_exact_shr cannot shift out non-zero bits"),
1700                (
1701                    zeros: u32 = self.trailing_zeros(),
1702                    bits: u32 =  <$SelfT>::BITS,
1703                    rhs: u32 = rhs,
1704                ) => rhs <= zeros && rhs < bits,
1705            );
1706
1707            unsafe { self.unchecked_shr(rhs) }
1709        }
1710
1711        #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").checked_abs(), Some(5));")]
1718        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.checked_abs(), None);")]
1719        #[stable(feature = "no_panic_abs", since = "1.13.0")]
1721        #[rustc_const_stable(feature = "const_checked_int_methods", since = "1.47.0")]
1722        #[must_use = "this returns the result of the operation, \
1723                      without modifying the original"]
1724        #[inline]
1725        #[cfg(not(feature = "ferrocene_certified"))]
1726        pub const fn checked_abs(self) -> Option<Self> {
1727            if self.is_negative() {
1728                self.checked_neg()
1729            } else {
1730                Some(self)
1731            }
1732        }
1733
1734        #[doc = concat!("assert_eq!((-5", stringify!($SelfT), ").strict_abs(), 5);")]
1747        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.strict_abs();")]
1753        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1755        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1756        #[must_use = "this returns the result of the operation, \
1757                      without modifying the original"]
1758        #[inline]
1759        #[track_caller]
1760        #[cfg(not(feature = "ferrocene_certified"))]
1761        pub const fn strict_abs(self) -> Self {
1762            if self.is_negative() {
1763                self.strict_neg()
1764            } else {
1765                self
1766            }
1767        }
1768
1769        #[doc = concat!("assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64));")]
1776        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
1777        #[stable(feature = "no_panic_pow", since = "1.34.0")]
1780        #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
1781        #[must_use = "this returns the result of the operation, \
1782                      without modifying the original"]
1783        #[inline]
1784        #[cfg(not(feature = "ferrocene_certified"))]
1785        pub const fn checked_pow(self, mut exp: u32) -> Option<Self> {
1786            if exp == 0 {
1787                return Some(1);
1788            }
1789            let mut base = self;
1790            let mut acc: Self = 1;
1791
1792            loop {
1793                if (exp & 1) == 1 {
1794                    acc = try_opt!(acc.checked_mul(base));
1795                    if exp == 1 {
1797                        return Some(acc);
1798                    }
1799                }
1800                exp /= 2;
1801                base = try_opt!(base.checked_mul(base));
1802            }
1803        }
1804
1805        #[doc = concat!("assert_eq!(8", stringify!($SelfT), ".strict_pow(2), 64);")]
1818        #[doc = concat!("let _ = ", stringify!($SelfT), "::MAX.strict_pow(2);")]
1824        #[stable(feature = "strict_overflow_ops", since = "1.91.0")]
1826        #[rustc_const_stable(feature = "strict_overflow_ops", since = "1.91.0")]
1827        #[must_use = "this returns the result of the operation, \
1828                      without modifying the original"]
1829        #[inline]
1830        #[track_caller]
1831        #[cfg(not(feature = "ferrocene_certified"))]
1832        pub const fn strict_pow(self, mut exp: u32) -> Self {
1833            if exp == 0 {
1834                return 1;
1835            }
1836            let mut base = self;
1837            let mut acc: Self = 1;
1838
1839            loop {
1840                if (exp & 1) == 1 {
1841                    acc = acc.strict_mul(base);
1842                    if exp == 1 {
1844                        return acc;
1845                    }
1846                }
1847                exp /= 2;
1848                base = base.strict_mul(base);
1849            }
1850        }
1851
1852        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_isqrt(), Some(3));")]
1860        #[stable(feature = "isqrt", since = "1.84.0")]
1862        #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
1863        #[must_use = "this returns the result of the operation, \
1864                      without modifying the original"]
1865        #[inline]
1866        #[cfg(not(feature = "ferrocene_certified"))]
1867        pub const fn checked_isqrt(self) -> Option<Self> {
1868            if self < 0 {
1869                None
1870            } else {
1871                let result = unsafe {
1873                    crate::num::int_sqrt::$ActualT(self as $ActualT) as $SelfT
1874                };
1875
1876                unsafe {
1888                    const MAX_RESULT: $SelfT = unsafe {
1890                        crate::num::int_sqrt::$ActualT(<$ActualT>::MAX) as $SelfT
1891                    };
1892
1893                    crate::hint::assert_unchecked(result >= 0);
1894                    crate::hint::assert_unchecked(result <= MAX_RESULT);
1895                }
1896
1897                Some(result)
1898            }
1899        }
1900
1901        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_add(1), 101);")]
1908        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add(100), ", stringify!($SelfT), "::MAX);")]
1909        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_add(-1), ", stringify!($SelfT), "::MIN);")]
1910        #[stable(feature = "rust1", since = "1.0.0")]
1913        #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
1914        #[must_use = "this returns the result of the operation, \
1915                      without modifying the original"]
1916        #[inline(always)]
1917        #[cfg(not(feature = "ferrocene_certified"))]
1918        pub const fn saturating_add(self, rhs: Self) -> Self {
1919            intrinsics::saturating_add(self, rhs)
1920        }
1921
1922        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_unsigned(2), 3);")]
1929        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add_unsigned(100), ", stringify!($SelfT), "::MAX);")]
1930        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
1932        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
1933        #[must_use = "this returns the result of the operation, \
1934                      without modifying the original"]
1935        #[inline]
1936        #[cfg(not(feature = "ferrocene_certified"))]
1937        pub const fn saturating_add_unsigned(self, rhs: $UnsignedT) -> Self {
1938            match self.checked_add_unsigned(rhs) {
1941                Some(x) => x,
1942                None => Self::MAX,
1943            }
1944        }
1945
1946        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_sub(127), -27);")]
1953        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub(100), ", stringify!($SelfT), "::MIN);")]
1954        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_sub(-1), ", stringify!($SelfT), "::MAX);")]
1955        #[stable(feature = "rust1", since = "1.0.0")]
1957        #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
1958        #[must_use = "this returns the result of the operation, \
1959                      without modifying the original"]
1960        #[inline(always)]
1961        #[cfg(not(feature = "ferrocene_certified"))]
1962        pub const fn saturating_sub(self, rhs: Self) -> Self {
1963            intrinsics::saturating_sub(self, rhs)
1964        }
1965
1966        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_sub_unsigned(127), -27);")]
1973        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub_unsigned(100), ", stringify!($SelfT), "::MIN);")]
1974        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
1976        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
1977        #[must_use = "this returns the result of the operation, \
1978                      without modifying the original"]
1979        #[inline]
1980        #[cfg(not(feature = "ferrocene_certified"))]
1981        pub const fn saturating_sub_unsigned(self, rhs: $UnsignedT) -> Self {
1982            match self.checked_sub_unsigned(rhs) {
1985                Some(x) => x,
1986                None => Self::MIN,
1987            }
1988        }
1989
1990        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_neg(), -100);")]
1997        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").saturating_neg(), 100);")]
1998        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_neg(), ", stringify!($SelfT), "::MAX);")]
1999        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_neg(), ", stringify!($SelfT), "::MIN + 1);")]
2000        #[stable(feature = "saturating_neg", since = "1.45.0")]
2003        #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
2004        #[must_use = "this returns the result of the operation, \
2005                      without modifying the original"]
2006        #[inline(always)]
2007        #[cfg(not(feature = "ferrocene_certified"))]
2008        pub const fn saturating_neg(self) -> Self {
2009            intrinsics::saturating_sub(0, self)
2010        }
2011
2012        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_abs(), 100);")]
2019        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").saturating_abs(), 100);")]
2020        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_abs(), ", stringify!($SelfT), "::MAX);")]
2021        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 1).saturating_abs(), ", stringify!($SelfT), "::MAX);")]
2022        #[stable(feature = "saturating_neg", since = "1.45.0")]
2025        #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
2026        #[must_use = "this returns the result of the operation, \
2027                      without modifying the original"]
2028        #[inline]
2029        #[cfg(not(feature = "ferrocene_certified"))]
2030        pub const fn saturating_abs(self) -> Self {
2031            if self.is_negative() {
2032                self.saturating_neg()
2033            } else {
2034                self
2035            }
2036        }
2037
2038        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".saturating_mul(12), 120);")]
2045        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_mul(10), ", stringify!($SelfT), "::MAX);")]
2046        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_mul(10), ", stringify!($SelfT), "::MIN);")]
2047        #[stable(feature = "wrapping", since = "1.7.0")]
2049        #[rustc_const_stable(feature = "const_saturating_int_methods", since = "1.47.0")]
2050        #[must_use = "this returns the result of the operation, \
2051                      without modifying the original"]
2052        #[inline]
2053        #[cfg(not(feature = "ferrocene_certified"))]
2054        pub const fn saturating_mul(self, rhs: Self) -> Self {
2055            match self.checked_mul(rhs) {
2056                Some(x) => x,
2057                None => if (self < 0) == (rhs < 0) {
2058                    Self::MAX
2059                } else {
2060                    Self::MIN
2061                }
2062            }
2063        }
2064
2065        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".saturating_div(2), 2);")]
2076        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_div(-1), ", stringify!($SelfT), "::MIN + 1);")]
2077        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_div(-1), ", stringify!($SelfT), "::MAX);")]
2078        #[stable(feature = "saturating_div", since = "1.58.0")]
2081        #[rustc_const_stable(feature = "saturating_div", since = "1.58.0")]
2082        #[must_use = "this returns the result of the operation, \
2083                      without modifying the original"]
2084        #[inline]
2085        #[cfg(not(feature = "ferrocene_certified"))]
2086        pub const fn saturating_div(self, rhs: Self) -> Self {
2087            match self.overflowing_div(rhs) {
2088                (result, false) => result,
2089                (_result, true) => Self::MAX, }
2091        }
2092
2093        #[doc = concat!("assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64);")]
2100        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
2101        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT), "::MIN);")]
2102        #[stable(feature = "no_panic_pow", since = "1.34.0")]
2104        #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
2105        #[must_use = "this returns the result of the operation, \
2106                      without modifying the original"]
2107        #[inline]
2108        #[cfg(not(feature = "ferrocene_certified"))]
2109        pub const fn saturating_pow(self, exp: u32) -> Self {
2110            match self.checked_pow(exp) {
2111                Some(x) => x,
2112                None if self < 0 && exp % 2 == 1 => Self::MIN,
2113                None => Self::MAX,
2114            }
2115        }
2116
2117        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_add(27), 127);")]
2124        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add(2), ", stringify!($SelfT), "::MIN + 1);")]
2125        #[stable(feature = "rust1", since = "1.0.0")]
2127        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2128        #[must_use = "this returns the result of the operation, \
2129                      without modifying the original"]
2130        #[inline(always)]
2131        #[cfg(not(feature = "ferrocene_certified"))]
2132        pub const fn wrapping_add(self, rhs: Self) -> Self {
2133            intrinsics::wrapping_add(self, rhs)
2134        }
2135
2136        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_add_unsigned(27), 127);")]
2143        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add_unsigned(2), ", stringify!($SelfT), "::MIN + 1);")]
2144        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
2146        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
2147        #[must_use = "this returns the result of the operation, \
2148                      without modifying the original"]
2149        #[inline(always)]
2150        #[cfg(not(feature = "ferrocene_certified"))]
2151        pub const fn wrapping_add_unsigned(self, rhs: $UnsignedT) -> Self {
2152            self.wrapping_add(rhs as Self)
2153        }
2154
2155        #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".wrapping_sub(127), -127);")]
2162        #[doc = concat!("assert_eq!((-2", stringify!($SelfT), ").wrapping_sub(", stringify!($SelfT), "::MAX), ", stringify!($SelfT), "::MAX);")]
2163        #[stable(feature = "rust1", since = "1.0.0")]
2165        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2166        #[must_use = "this returns the result of the operation, \
2167                      without modifying the original"]
2168        #[inline(always)]
2169        pub const fn wrapping_sub(self, rhs: Self) -> Self {
2170            intrinsics::wrapping_sub(self, rhs)
2171        }
2172
2173        #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".wrapping_sub_unsigned(127), -127);")]
2180        #[doc = concat!("assert_eq!((-2", stringify!($SelfT), ").wrapping_sub_unsigned(", stringify!($UnsignedT), "::MAX), -1);")]
2181        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
2183        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
2184        #[must_use = "this returns the result of the operation, \
2185                      without modifying the original"]
2186        #[inline(always)]
2187        #[cfg(not(feature = "ferrocene_certified"))]
2188        pub const fn wrapping_sub_unsigned(self, rhs: $UnsignedT) -> Self {
2189            self.wrapping_sub(rhs as Self)
2190        }
2191
2192        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".wrapping_mul(12), 120);")]
2199        #[stable(feature = "rust1", since = "1.0.0")]
2202        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2203        #[must_use = "this returns the result of the operation, \
2204                      without modifying the original"]
2205        #[inline(always)]
2206        #[cfg(not(feature = "ferrocene_certified"))]
2207        pub const fn wrapping_mul(self, rhs: Self) -> Self {
2208            intrinsics::wrapping_mul(self, rhs)
2209        }
2210
2211        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div(10), 10);")]
2226        #[stable(feature = "num_wrapping", since = "1.2.0")]
2229        #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.52.0")]
2230        #[must_use = "this returns the result of the operation, \
2231                      without modifying the original"]
2232        #[inline]
2233        #[cfg(not(feature = "ferrocene_certified"))]
2234        pub const fn wrapping_div(self, rhs: Self) -> Self {
2235            self.overflowing_div(rhs).0
2236        }
2237
2238        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_div_euclid(10), 10);")]
2253        #[stable(feature = "euclidean_division", since = "1.38.0")]
2256        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
2257        #[must_use = "this returns the result of the operation, \
2258                      without modifying the original"]
2259        #[inline]
2260        #[cfg(not(feature = "ferrocene_certified"))]
2261        pub const fn wrapping_div_euclid(self, rhs: Self) -> Self {
2262            self.overflowing_div_euclid(rhs).0
2263        }
2264
2265        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem(10), 0);")]
2280        #[stable(feature = "num_wrapping", since = "1.2.0")]
2283        #[rustc_const_stable(feature = "const_wrapping_int_methods", since = "1.52.0")]
2284        #[must_use = "this returns the result of the operation, \
2285                      without modifying the original"]
2286        #[inline]
2287        #[cfg(not(feature = "ferrocene_certified"))]
2288        pub const fn wrapping_rem(self, rhs: Self) -> Self {
2289            self.overflowing_rem(rhs).0
2290        }
2291
2292        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_rem_euclid(10), 0);")]
2306        #[stable(feature = "euclidean_division", since = "1.38.0")]
2309        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
2310        #[must_use = "this returns the result of the operation, \
2311                      without modifying the original"]
2312        #[inline]
2313        #[cfg(not(feature = "ferrocene_certified"))]
2314        pub const fn wrapping_rem_euclid(self, rhs: Self) -> Self {
2315            self.overflowing_rem_euclid(rhs).0
2316        }
2317
2318        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_neg(), -100);")]
2329        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").wrapping_neg(), 100);")]
2330        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.wrapping_neg(), ", stringify!($SelfT), "::MIN);")]
2331        #[stable(feature = "num_wrapping", since = "1.2.0")]
2333        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2334        #[must_use = "this returns the result of the operation, \
2335                      without modifying the original"]
2336        #[inline(always)]
2337        pub const fn wrapping_neg(self) -> Self {
2338            (0 as $SelfT).wrapping_sub(self)
2339        }
2340
2341        #[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(7), -128);")]
2353        #[doc = concat!("assert_eq!((-1", stringify!($SelfT), ").wrapping_shl(128), -1);")]
2354        #[stable(feature = "num_wrapping", since = "1.2.0")]
2356        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2357        #[must_use = "this returns the result of the operation, \
2358                      without modifying the original"]
2359        #[inline(always)]
2360        #[cfg(not(feature = "ferrocene_certified"))]
2361        pub const fn wrapping_shl(self, rhs: u32) -> Self {
2362            unsafe {
2365                self.unchecked_shl(rhs & (Self::BITS - 1))
2366            }
2367        }
2368
2369        #[doc = concat!("assert_eq!((-128", stringify!($SelfT), ").wrapping_shr(7), -1);")]
2381        #[stable(feature = "num_wrapping", since = "1.2.0")]
2384        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2385        #[must_use = "this returns the result of the operation, \
2386                      without modifying the original"]
2387        #[inline(always)]
2388        #[cfg(not(feature = "ferrocene_certified"))]
2389        pub const fn wrapping_shr(self, rhs: u32) -> Self {
2390            unsafe {
2393                self.unchecked_shr(rhs & (Self::BITS - 1))
2394            }
2395        }
2396
2397        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_abs(), 100);")]
2408        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").wrapping_abs(), 100);")]
2409        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.wrapping_abs(), ", stringify!($SelfT), "::MIN);")]
2410        #[stable(feature = "no_panic_abs", since = "1.13.0")]
2413        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2414        #[must_use = "this returns the result of the operation, \
2415                      without modifying the original"]
2416        #[allow(unused_attributes)]
2417        #[inline]
2418        pub const fn wrapping_abs(self) -> Self {
2419             if self.is_negative() {
2420                 self.wrapping_neg()
2421             } else {
2422                 self
2423             }
2424        }
2425
2426        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");")]
2434        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");")]
2435        #[stable(feature = "unsigned_abs", since = "1.51.0")]
2438        #[rustc_const_stable(feature = "unsigned_abs", since = "1.51.0")]
2439        #[must_use = "this returns the result of the operation, \
2440                      without modifying the original"]
2441        #[inline]
2442        pub const fn unsigned_abs(self) -> $UnsignedT {
2443             self.wrapping_abs() as $UnsignedT
2444        }
2445
2446        #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(4), 81);")]
2453        #[stable(feature = "no_panic_pow", since = "1.34.0")]
2457        #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
2458        #[must_use = "this returns the result of the operation, \
2459                      without modifying the original"]
2460        #[inline]
2461        #[cfg(not(feature = "ferrocene_certified"))]
2462        pub const fn wrapping_pow(self, mut exp: u32) -> Self {
2463            if exp == 0 {
2464                return 1;
2465            }
2466            let mut base = self;
2467            let mut acc: Self = 1;
2468
2469            if intrinsics::is_val_statically_known(exp) {
2470                while exp > 1 {
2471                    if (exp & 1) == 1 {
2472                        acc = acc.wrapping_mul(base);
2473                    }
2474                    exp /= 2;
2475                    base = base.wrapping_mul(base);
2476                }
2477
2478                acc.wrapping_mul(base)
2482            } else {
2483                loop {
2488                    if (exp & 1) == 1 {
2489                        acc = acc.wrapping_mul(base);
2490                        if exp == 1 {
2492                            return acc;
2493                        }
2494                    }
2495                    exp /= 2;
2496                    base = base.wrapping_mul(base);
2497                }
2498            }
2499        }
2500
2501        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_add(2), (7, false));")]
2511        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.overflowing_add(1), (", stringify!($SelfT), "::MIN, true));")]
2512        #[stable(feature = "wrapping", since = "1.7.0")]
2514        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2515        #[must_use = "this returns the result of the operation, \
2516                      without modifying the original"]
2517        #[inline(always)]
2518        #[cfg(not(feature = "ferrocene_certified"))]
2519        pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) {
2520            let (a, b) = intrinsics::add_with_overflow(self as $ActualT, rhs as $ActualT);
2521            (a as Self, b)
2522        }
2523
2524        #[doc = concat!("[`", stringify!($UnsignedT), "::carrying_add`]")]
2536        #[doc = concat!("//   10  MAX    (a = 10 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
2551        #[doc = concat!("// + -5    9    (b = -5 × 2^", stringify!($BITS), " + 9)")]
2552        #[doc = concat!("//    6    8    (sum = 6 × 2^", stringify!($BITS), " + 8)")]
2554        #[doc = concat!("let (a1, a0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (10, ", stringify!($UnsignedT), "::MAX);")]
2556        #[doc = concat!("let (b1, b0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (-5, 9);")]
2557        #[doc = concat!("// ", stringify!($UnsignedT), "::carrying_add for the less significant words")]
2560        #[doc = concat!("// ", stringify!($SelfT), "::carrying_add for the most significant word")]
2564        #[unstable(feature = "bigint_helper_methods", issue = "85532")]
2570        #[must_use = "this returns the result of the operation, \
2571                      without modifying the original"]
2572        #[inline]
2573        #[cfg(not(feature = "ferrocene_certified"))]
2574        pub const fn carrying_add(self, rhs: Self, carry: bool) -> (Self, bool) {
2575            let (a, b) = self.overflowing_add(rhs);
2578            let (c, d) = a.overflowing_add(carry as $SelfT);
2579            (c, b != d)
2580        }
2581
2582        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_unsigned(2), (3, false));")]
2592        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN).overflowing_add_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MAX, false));")]
2593        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).overflowing_add_unsigned(3), (", stringify!($SelfT), "::MIN, true));")]
2594        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
2596        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
2597        #[must_use = "this returns the result of the operation, \
2598                      without modifying the original"]
2599        #[inline]
2600        #[cfg(not(feature = "ferrocene_certified"))]
2601        pub const fn overflowing_add_unsigned(self, rhs: $UnsignedT) -> (Self, bool) {
2602            let rhs = rhs as Self;
2603            let (res, overflowed) = self.overflowing_add(rhs);
2604            (res, overflowed ^ (rhs < 0))
2605        }
2606
2607        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_sub(2), (3, false));")]
2616        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_sub(1), (", stringify!($SelfT), "::MAX, true));")]
2617        #[stable(feature = "wrapping", since = "1.7.0")]
2619        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2620        #[must_use = "this returns the result of the operation, \
2621                      without modifying the original"]
2622        #[inline(always)]
2623        #[cfg(not(feature = "ferrocene_certified"))]
2624        pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) {
2625            let (a, b) = intrinsics::sub_with_overflow(self as $ActualT, rhs as $ActualT);
2626            (a as Self, b)
2627        }
2628
2629        #[doc = concat!("[`", stringify!($UnsignedT), "::borrowing_sub`]")]
2642        #[doc = concat!("//    6    8    (a = 6 × 2^", stringify!($BITS), " + 8)")]
2657        #[doc = concat!("// - -5    9    (b = -5 × 2^", stringify!($BITS), " + 9)")]
2658        #[doc = concat!("//   10  MAX    (diff = 10 × 2^", stringify!($BITS), " + 2^", stringify!($BITS), " - 1)")]
2660        #[doc = concat!("let (a1, a0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (6, 8);")]
2662        #[doc = concat!("let (b1, b0): (", stringify!($SelfT), ", ", stringify!($UnsignedT), ") = (-5, 9);")]
2663        #[doc = concat!("// ", stringify!($UnsignedT), "::borrowing_sub for the less significant words")]
2666        #[doc = concat!("// ", stringify!($SelfT), "::borrowing_sub for the most significant word")]
2670        #[doc = concat!("assert_eq!((diff1, diff0), (10, ", stringify!($UnsignedT), "::MAX));")]
2674        #[unstable(feature = "bigint_helper_methods", issue = "85532")]
2676        #[must_use = "this returns the result of the operation, \
2677                      without modifying the original"]
2678        #[inline]
2679        #[cfg(not(feature = "ferrocene_certified"))]
2680        pub const fn borrowing_sub(self, rhs: Self, borrow: bool) -> (Self, bool) {
2681            let (a, b) = self.overflowing_sub(rhs);
2684            let (c, d) = a.overflowing_sub(borrow as $SelfT);
2685            (c, b != d)
2686        }
2687
2688        #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_sub_unsigned(2), (-1, false));")]
2698        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX).overflowing_sub_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MIN, false));")]
2699        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).overflowing_sub_unsigned(3), (", stringify!($SelfT), "::MAX, true));")]
2700        #[stable(feature = "mixed_integer_ops", since = "1.66.0")]
2702        #[rustc_const_stable(feature = "mixed_integer_ops", since = "1.66.0")]
2703        #[must_use = "this returns the result of the operation, \
2704                      without modifying the original"]
2705        #[inline]
2706        #[cfg(not(feature = "ferrocene_certified"))]
2707        pub const fn overflowing_sub_unsigned(self, rhs: $UnsignedT) -> (Self, bool) {
2708            let rhs = rhs as Self;
2709            let (res, overflowed) = self.overflowing_sub(rhs);
2710            (res, overflowed ^ (rhs < 0))
2711        }
2712
2713        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_mul(2), (10, false));")]
2722        #[stable(feature = "wrapping", since = "1.7.0")]
2725        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2726        #[must_use = "this returns the result of the operation, \
2727                      without modifying the original"]
2728        #[inline(always)]
2729        #[cfg(not(feature = "ferrocene_certified"))]
2730        pub const fn overflowing_mul(self, rhs: Self) -> (Self, bool) {
2731            let (a, b) = intrinsics::mul_with_overflow(self as $ActualT, rhs as $ActualT);
2732            (a as Self, b)
2733        }
2734
2735        #[unstable(feature = "bigint_helper_methods", issue = "85532")]
2753        #[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
2754        #[must_use = "this returns the result of the operation, \
2755                      without modifying the original"]
2756        #[inline]
2757        #[cfg(not(feature = "ferrocene_certified"))]
2758        pub const fn widening_mul(self, rhs: Self) -> ($UnsignedT, Self) {
2759            Self::carrying_mul_add(self, rhs, 0, 0)
2760        }
2761
2762        #[doc = concat!("assert_eq!(",
2785            stringify!($SelfT), "::MAX.carrying_mul(", stringify!($SelfT), "::MAX, ", stringify!($SelfT), "::MAX), ",
2786            "(", stringify!($SelfT), "::MAX.unsigned_abs() + 1, ", stringify!($SelfT), "::MAX / 2));"
2787        )]
2788        #[unstable(feature = "bigint_helper_methods", issue = "85532")]
2790        #[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
2791        #[must_use = "this returns the result of the operation, \
2792                      without modifying the original"]
2793        #[inline]
2794        #[cfg(not(feature = "ferrocene_certified"))]
2795        pub const fn carrying_mul(self, rhs: Self, carry: Self) -> ($UnsignedT, Self) {
2796            Self::carrying_mul_add(self, rhs, carry, 0)
2797        }
2798
2799        #[doc = concat!("assert_eq!(",
2823            stringify!($SelfT), "::MAX.carrying_mul_add(", stringify!($SelfT), "::MAX, ", stringify!($SelfT), "::MAX, ", stringify!($SelfT), "::MAX), ",
2824            "(", stringify!($UnsignedT), "::MAX, ", stringify!($SelfT), "::MAX / 2));"
2825        )]
2826        #[unstable(feature = "bigint_helper_methods", issue = "85532")]
2828        #[rustc_const_unstable(feature = "bigint_helper_methods", issue = "85532")]
2829        #[must_use = "this returns the result of the operation, \
2830                      without modifying the original"]
2831        #[inline]
2832        #[cfg(not(feature = "ferrocene_certified"))]
2833        pub const fn carrying_mul_add(self, rhs: Self, carry: Self, add: Self) -> ($UnsignedT, Self) {
2834            intrinsics::carrying_mul_add(self, rhs, carry, add)
2835        }
2836
2837        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div(2), (2, false));")]
2850        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div(-1), (", stringify!($SelfT), "::MIN, true));")]
2851        #[inline]
2853        #[stable(feature = "wrapping", since = "1.7.0")]
2854        #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")]
2855        #[must_use = "this returns the result of the operation, \
2856                      without modifying the original"]
2857        #[cfg(not(feature = "ferrocene_certified"))]
2858        pub const fn overflowing_div(self, rhs: Self) -> (Self, bool) {
2859            if intrinsics::unlikely((self == Self::MIN) & (rhs == -1)) {
2861                (self, true)
2862            } else {
2863                (self / rhs, false)
2864            }
2865        }
2866
2867        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_div_euclid(2), (2, false));")]
2880        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_div_euclid(-1), (", stringify!($SelfT), "::MIN, true));")]
2881        #[inline]
2883        #[stable(feature = "euclidean_division", since = "1.38.0")]
2884        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
2885        #[must_use = "this returns the result of the operation, \
2886                      without modifying the original"]
2887        #[cfg(not(feature = "ferrocene_certified"))]
2888        pub const fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) {
2889            if intrinsics::unlikely((self == Self::MIN) & (rhs == -1)) {
2891                (self, true)
2892            } else {
2893                (self.div_euclid(rhs), false)
2894            }
2895        }
2896
2897        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem(2), (1, false));")]
2910        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem(-1), (0, true));")]
2911        #[inline]
2913        #[stable(feature = "wrapping", since = "1.7.0")]
2914        #[rustc_const_stable(feature = "const_overflowing_int_methods", since = "1.52.0")]
2915        #[must_use = "this returns the result of the operation, \
2916                      without modifying the original"]
2917        #[cfg(not(feature = "ferrocene_certified"))]
2918        pub const fn overflowing_rem(self, rhs: Self) -> (Self, bool) {
2919            if intrinsics::unlikely(rhs == -1) {
2920                (0, self == Self::MIN)
2921            } else {
2922                (self % rhs, false)
2923            }
2924        }
2925
2926
2927        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".overflowing_rem_euclid(2), (1, false));")]
2940        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_rem_euclid(-1), (0, true));")]
2941        #[stable(feature = "euclidean_division", since = "1.38.0")]
2943        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
2944        #[must_use = "this returns the result of the operation, \
2945                      without modifying the original"]
2946        #[inline]
2947        #[track_caller]
2948        #[cfg(not(feature = "ferrocene_certified"))]
2949        pub const fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) {
2950            if intrinsics::unlikely(rhs == -1) {
2951                (0, self == Self::MIN)
2952            } else {
2953                (self.rem_euclid(rhs), false)
2954            }
2955        }
2956
2957
2958        #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".overflowing_neg(), (-2, false));")]
2968        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.overflowing_neg(), (", stringify!($SelfT), "::MIN, true));")]
2969        #[inline]
2971        #[stable(feature = "wrapping", since = "1.7.0")]
2972        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
2973        #[must_use = "this returns the result of the operation, \
2974                      without modifying the original"]
2975        #[allow(unused_attributes)]
2976        #[cfg(not(feature = "ferrocene_certified"))]
2977        pub const fn overflowing_neg(self) -> (Self, bool) {
2978            if intrinsics::unlikely(self == Self::MIN) {
2979                (Self::MIN, true)
2980            } else {
2981                (-self, false)
2982            }
2983        }
2984
2985        #[doc = concat!("assert_eq!(0x1", stringify!($SelfT),".overflowing_shl(4), (0x10, false));")]
2995        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shl(", stringify!($BITS_MINUS_ONE), "), (0, false));")]
2997        #[stable(feature = "wrapping", since = "1.7.0")]
2999        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
3000        #[must_use = "this returns the result of the operation, \
3001                      without modifying the original"]
3002        #[inline]
3003        #[cfg(not(feature = "ferrocene_certified"))]
3004        pub const fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
3005            (self.wrapping_shl(rhs), rhs >= Self::BITS)
3006        }
3007
3008        #[doc = concat!("assert_eq!(0x10", stringify!($SelfT), ".overflowing_shr(4), (0x1, false));")]
3018        #[stable(feature = "wrapping", since = "1.7.0")]
3021        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
3022        #[must_use = "this returns the result of the operation, \
3023                      without modifying the original"]
3024        #[inline]
3025        #[cfg(not(feature = "ferrocene_certified"))]
3026        pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
3027            (self.wrapping_shr(rhs), rhs >= Self::BITS)
3028        }
3029
3030        #[doc = concat!("(e.g., ", stringify!($SelfT), "::MIN for values of type ", stringify!($SelfT), "),")]
3035        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".overflowing_abs(), (10, false));")]
3042        #[doc = concat!("assert_eq!((-10", stringify!($SelfT), ").overflowing_abs(), (10, false));")]
3043        #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN).overflowing_abs(), (", stringify!($SelfT), "::MIN, true));")]
3044        #[stable(feature = "no_panic_abs", since = "1.13.0")]
3046        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
3047        #[must_use = "this returns the result of the operation, \
3048                      without modifying the original"]
3049        #[inline]
3050        #[cfg(not(feature = "ferrocene_certified"))]
3051        pub const fn overflowing_abs(self) -> (Self, bool) {
3052            (self.wrapping_abs(), self == Self::MIN)
3053        }
3054
3055        #[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(4), (81, false));")]
3064        #[stable(feature = "no_panic_pow", since = "1.34.0")]
3067        #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
3068        #[must_use = "this returns the result of the operation, \
3069                      without modifying the original"]
3070        #[inline]
3071        #[cfg(not(feature = "ferrocene_certified"))]
3072        pub const fn overflowing_pow(self, mut exp: u32) -> (Self, bool) {
3073            if exp == 0 {
3074                return (1,false);
3075            }
3076            let mut base = self;
3077            let mut acc: Self = 1;
3078            let mut overflown = false;
3079            let mut r;
3081
3082            loop {
3083                if (exp & 1) == 1 {
3084                    r = acc.overflowing_mul(base);
3085                    if exp == 1 {
3087                        r.1 |= overflown;
3088                        return r;
3089                    }
3090                    acc = r.0;
3091                    overflown |= r.1;
3092                }
3093                exp /= 2;
3094                r = base.overflowing_mul(base);
3095                base = r.0;
3096                overflown |= r.1;
3097            }
3098        }
3099
3100        #[doc = concat!("let x: ", stringify!($SelfT), " = 2; // or any other integer type")]
3106        #[stable(feature = "rust1", since = "1.0.0")]
3110        #[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
3111        #[must_use = "this returns the result of the operation, \
3112                      without modifying the original"]
3113        #[inline]
3114        #[rustc_inherit_overflow_checks]
3115        #[cfg(not(feature = "ferrocene_certified"))]
3116        pub const fn pow(self, mut exp: u32) -> Self {
3117            if exp == 0 {
3118                return 1;
3119            }
3120            let mut base = self;
3121            let mut acc = 1;
3122
3123            if intrinsics::is_val_statically_known(exp) {
3124                while exp > 1 {
3125                    if (exp & 1) == 1 {
3126                        acc = acc * base;
3127                    }
3128                    exp /= 2;
3129                    base = base * base;
3130                }
3131
3132                acc * base
3137            } else {
3138                loop {
3143                    if (exp & 1) == 1 {
3144                        acc = acc * base;
3145                        if exp == 1 {
3147                            return acc;
3148                        }
3149                    }
3150                    exp /= 2;
3151                    base = base * base;
3152                }
3153            }
3154        }
3155
3156        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".isqrt(), 3);")]
3166        #[stable(feature = "isqrt", since = "1.84.0")]
3168        #[rustc_const_stable(feature = "isqrt", since = "1.84.0")]
3169        #[must_use = "this returns the result of the operation, \
3170                      without modifying the original"]
3171        #[inline]
3172        #[track_caller]
3173        #[cfg(not(feature = "ferrocene_certified"))]
3174        pub const fn isqrt(self) -> Self {
3175            match self.checked_isqrt() {
3176                Some(sqrt) => sqrt,
3177                None => crate::num::int_sqrt::panic_for_negative_argument(),
3178            }
3179        }
3180
3181        #[doc = concat!("let a: ", stringify!($SelfT), " = 7; // or any other integer type")]
3202        #[stable(feature = "euclidean_division", since = "1.38.0")]
3210        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
3211        #[must_use = "this returns the result of the operation, \
3212                      without modifying the original"]
3213        #[inline]
3214        #[track_caller]
3215        #[cfg(not(feature = "ferrocene_certified"))]
3216        pub const fn div_euclid(self, rhs: Self) -> Self {
3217            let q = self / rhs;
3218            if self % rhs < 0 {
3219                return if rhs > 0 { q - 1 } else { q + 1 }
3220            }
3221            q
3222        }
3223
3224
3225        #[doc = concat!("let a: ", stringify!($SelfT), " = 7; // or any other integer type")]
3240        #[doc = concat!("let _ = ", stringify!($SelfT), "::MIN.rem_euclid(-1);")]
3251        #[doc(alias = "modulo", alias = "mod")]
3253        #[stable(feature = "euclidean_division", since = "1.38.0")]
3254        #[rustc_const_stable(feature = "const_euclidean_int_methods", since = "1.52.0")]
3255        #[must_use = "this returns the result of the operation, \
3256                      without modifying the original"]
3257        #[inline]
3258        #[track_caller]
3259        #[cfg(not(feature = "ferrocene_certified"))]
3260        pub const fn rem_euclid(self, rhs: Self) -> Self {
3261            let r = self % rhs;
3262            if r < 0 {
3263                r.wrapping_add(rhs.wrapping_abs())
3272            } else {
3273                r
3274            }
3275        }
3276
3277        #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")]
3289        #[unstable(feature = "int_roundings", issue = "88581")]
3297        #[must_use = "this returns the result of the operation, \
3298                      without modifying the original"]
3299        #[inline]
3300        #[track_caller]
3301        #[cfg(not(feature = "ferrocene_certified"))]
3302        pub const fn div_floor(self, rhs: Self) -> Self {
3303            let d = self / rhs;
3304            let r = self % rhs;
3305
3306            let correction = (self ^ rhs) >> (Self::BITS - 1);
3313            if r != 0 {
3314                d + correction
3315            } else {
3316                d
3317            }
3318        }
3319
3320        #[doc = concat!("let a: ", stringify!($SelfT)," = 8;")]
3332        #[unstable(feature = "int_roundings", issue = "88581")]
3340        #[must_use = "this returns the result of the operation, \
3341                      without modifying the original"]
3342        #[inline]
3343        #[track_caller]
3344        #[cfg(not(feature = "ferrocene_certified"))]
3345        pub const fn div_ceil(self, rhs: Self) -> Self {
3346            let d = self / rhs;
3347            let r = self % rhs;
3348
3349            let correction = 1 + ((self ^ rhs) >> (Self::BITS - 1));
3352            if r != 0 {
3353                d + correction
3354            } else {
3355                d
3356            }
3357        }
3358
3359        #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(8), 16);")]
3378        #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".next_multiple_of(8), 24);")]
3379        #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".next_multiple_of(-8), 16);")]
3380        #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".next_multiple_of(-8), 16);")]
3381        #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").next_multiple_of(8), -16);")]
3382        #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").next_multiple_of(8), -16);")]
3383        #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").next_multiple_of(-8), -16);")]
3384        #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").next_multiple_of(-8), -24);")]
3385        #[unstable(feature = "int_roundings", issue = "88581")]
3387        #[must_use = "this returns the result of the operation, \
3388                      without modifying the original"]
3389        #[inline]
3390        #[rustc_inherit_overflow_checks]
3391        #[cfg(not(feature = "ferrocene_certified"))]
3392        pub const fn next_multiple_of(self, rhs: Self) -> Self {
3393            if rhs == -1 {
3395                return self;
3396            }
3397
3398            let r = self % rhs;
3399            let m = if (r > 0 && rhs < 0) || (r < 0 && rhs > 0) {
3400                r + rhs
3401            } else {
3402                r
3403            };
3404
3405            if m == 0 {
3406                self
3407            } else {
3408                self + (rhs - m)
3409            }
3410        }
3411
3412        #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".checked_next_multiple_of(8), Some(16));")]
3423        #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".checked_next_multiple_of(8), Some(24));")]
3424        #[doc = concat!("assert_eq!(16_", stringify!($SelfT), ".checked_next_multiple_of(-8), Some(16));")]
3425        #[doc = concat!("assert_eq!(23_", stringify!($SelfT), ".checked_next_multiple_of(-8), Some(16));")]
3426        #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").checked_next_multiple_of(8), Some(-16));")]
3427        #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").checked_next_multiple_of(8), Some(-16));")]
3428        #[doc = concat!("assert_eq!((-16_", stringify!($SelfT), ").checked_next_multiple_of(-8), Some(-16));")]
3429        #[doc = concat!("assert_eq!((-23_", stringify!($SelfT), ").checked_next_multiple_of(-8), Some(-24));")]
3430        #[doc = concat!("assert_eq!(1_", stringify!($SelfT), ".checked_next_multiple_of(0), None);")]
3431        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_next_multiple_of(2), None);")]
3432        #[unstable(feature = "int_roundings", issue = "88581")]
3434        #[must_use = "this returns the result of the operation, \
3435                      without modifying the original"]
3436        #[inline]
3437        #[cfg(not(feature = "ferrocene_certified"))]
3438        pub const fn checked_next_multiple_of(self, rhs: Self) -> Option<Self> {
3439            if rhs == -1 {
3441                return Some(self);
3442            }
3443
3444            let r = try_opt!(self.checked_rem(rhs));
3445            let m = if (r > 0 && rhs < 0) || (r < 0 && rhs > 0) {
3446                r + rhs
3448            } else {
3449                r
3450            };
3451
3452            if m == 0 {
3453                Some(self)
3454            } else {
3455                self.checked_add(rhs - m)
3457            }
3458        }
3459
3460        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".ilog(5), 1);")]
3476        #[stable(feature = "int_log", since = "1.67.0")]
3478        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
3479        #[must_use = "this returns the result of the operation, \
3480                      without modifying the original"]
3481        #[inline]
3482        #[track_caller]
3483        #[cfg(not(feature = "ferrocene_certified"))]
3484        pub const fn ilog(self, base: Self) -> u32 {
3485            assert!(base >= 2, "base of integer logarithm must be at least 2");
3486            if let Some(log) = self.checked_ilog(base) {
3487                log
3488            } else {
3489                int_log10::panic_for_nonpositive_argument()
3490            }
3491        }
3492
3493        #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".ilog2(), 1);")]
3503        #[stable(feature = "int_log", since = "1.67.0")]
3505        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
3506        #[must_use = "this returns the result of the operation, \
3507                      without modifying the original"]
3508        #[inline]
3509        #[track_caller]
3510        #[cfg(not(feature = "ferrocene_certified"))]
3511        pub const fn ilog2(self) -> u32 {
3512            if let Some(log) = self.checked_ilog2() {
3513                log
3514            } else {
3515                int_log10::panic_for_nonpositive_argument()
3516            }
3517        }
3518
3519        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".ilog10(), 1);")]
3529        #[stable(feature = "int_log", since = "1.67.0")]
3531        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
3532        #[must_use = "this returns the result of the operation, \
3533                      without modifying the original"]
3534        #[inline]
3535        #[track_caller]
3536        #[cfg(not(feature = "ferrocene_certified"))]
3537        pub const fn ilog10(self) -> u32 {
3538            if let Some(log) = self.checked_ilog10() {
3539                log
3540            } else {
3541                int_log10::panic_for_nonpositive_argument()
3542            }
3543        }
3544
3545        #[doc = concat!("assert_eq!(5", stringify!($SelfT), ".checked_ilog(5), Some(1));")]
3558        #[stable(feature = "int_log", since = "1.67.0")]
3560        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
3561        #[must_use = "this returns the result of the operation, \
3562                      without modifying the original"]
3563        #[inline]
3564        #[cfg(not(feature = "ferrocene_certified"))]
3565        pub const fn checked_ilog(self, base: Self) -> Option<u32> {
3566            if self <= 0 || base <= 1 {
3567                None
3568            } else {
3569                (self as $UnsignedT).checked_ilog(base as $UnsignedT)
3572            }
3573        }
3574
3575        #[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_ilog2(), Some(1));")]
3583        #[stable(feature = "int_log", since = "1.67.0")]
3585        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
3586        #[must_use = "this returns the result of the operation, \
3587                      without modifying the original"]
3588        #[inline]
3589        #[cfg(not(feature = "ferrocene_certified"))]
3590        pub const fn checked_ilog2(self) -> Option<u32> {
3591            if self <= 0 {
3592                None
3593            } else {
3594                let log = (Self::BITS - 1) - unsafe { intrinsics::ctlz_nonzero(self) as u32 };
3596                Some(log)
3597            }
3598        }
3599
3600        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".checked_ilog10(), Some(1));")]
3608        #[stable(feature = "int_log", since = "1.67.0")]
3610        #[rustc_const_stable(feature = "int_log", since = "1.67.0")]
3611        #[must_use = "this returns the result of the operation, \
3612                      without modifying the original"]
3613        #[inline]
3614        #[cfg(not(feature = "ferrocene_certified"))]
3615        pub const fn checked_ilog10(self) -> Option<u32> {
3616            if self > 0 {
3617                Some(int_log10::$ActualT(self as $ActualT))
3618            } else {
3619                None
3620            }
3621        }
3622
3623        #[doc = concat!("`", stringify!($SelfT), "::MIN`")]
3629        #[doc = concat!("`", stringify!($SelfT), "`,")]
3631        #[doc = concat!("`", stringify!($SelfT), "::MIN`")]
3635        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".abs(), 10);")]
3642        #[doc = concat!("assert_eq!((-10", stringify!($SelfT), ").abs(), 10);")]
3643        #[stable(feature = "rust1", since = "1.0.0")]
3645        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
3646        #[allow(unused_attributes)]
3647        #[must_use = "this returns the result of the operation, \
3648                      without modifying the original"]
3649        #[inline]
3650        #[rustc_inherit_overflow_checks]
3651        #[cfg(not(feature = "ferrocene_certified"))]
3652        pub const fn abs(self) -> Self {
3653            if self.is_negative() {
3657                -self
3658            } else {
3659                self
3660            }
3661        }
3662
3663        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(80), 20", stringify!($UnsignedT), ");")]
3672        #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".abs_diff(110), 10", stringify!($UnsignedT), ");")]
3673        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").abs_diff(80), 180", stringify!($UnsignedT), ");")]
3674        #[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").abs_diff(-120), 20", stringify!($UnsignedT), ");")]
3675        #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.abs_diff(", stringify!($SelfT), "::MAX), ", stringify!($UnsignedT), "::MAX);")]
3676        #[stable(feature = "int_abs_diff", since = "1.60.0")]
3678        #[rustc_const_stable(feature = "int_abs_diff", since = "1.60.0")]
3679        #[must_use = "this returns the result of the operation, \
3680                      without modifying the original"]
3681        #[inline]
3682        #[cfg(not(feature = "ferrocene_certified"))]
3683        pub const fn abs_diff(self, other: Self) -> $UnsignedT {
3684            if self < other {
3685                (other as $UnsignedT).wrapping_sub(self as $UnsignedT)
3699            } else {
3700                (self as $UnsignedT).wrapping_sub(other as $UnsignedT)
3701            }
3702        }
3703
3704        #[doc = concat!("assert_eq!(10", stringify!($SelfT), ".signum(), 1);")]
3714        #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".signum(), 0);")]
3715        #[doc = concat!("assert_eq!((-10", stringify!($SelfT), ").signum(), -1);")]
3716        #[stable(feature = "rust1", since = "1.0.0")]
3718        #[rustc_const_stable(feature = "const_int_sign", since = "1.47.0")]
3719        #[must_use = "this returns the result of the operation, \
3720                      without modifying the original"]
3721        #[inline(always)]
3722        #[cfg(not(feature = "ferrocene_certified"))]
3723        pub const fn signum(self) -> Self {
3724            crate::intrinsics::three_way_compare(self, 0) as Self
3730        }
3731
3732        #[doc = concat!("assert!(10", stringify!($SelfT), ".is_positive());")]
3739        #[doc = concat!("assert!(!(-10", stringify!($SelfT), ").is_positive());")]
3740        #[must_use]
3742        #[stable(feature = "rust1", since = "1.0.0")]
3743        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
3744        #[inline(always)]
3745        #[cfg(not(feature = "ferrocene_certified"))]
3746        pub const fn is_positive(self) -> bool { self > 0 }
3747
3748        #[doc = concat!("assert!((-10", stringify!($SelfT), ").is_negative());")]
3755        #[doc = concat!("assert!(!10", stringify!($SelfT), ".is_negative());")]
3756        #[must_use]
3758        #[stable(feature = "rust1", since = "1.0.0")]
3759        #[rustc_const_stable(feature = "const_int_methods", since = "1.32.0")]
3760        #[inline(always)]
3761        pub const fn is_negative(self) -> bool { self < 0 }
3762
3763        #[doc = $to_xe_bytes_doc]
3767        #[doc = concat!("let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();")]
3772        #[doc = concat!("assert_eq!(bytes, ", $be_bytes, ");")]
3773        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
3775        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
3776        #[must_use = "this returns the result of the operation, \
3777                      without modifying the original"]
3778        #[inline]
3779        #[cfg(not(feature = "ferrocene_certified"))]
3780        pub const fn to_be_bytes(self) -> [u8; size_of::<Self>()] {
3781            self.to_be().to_ne_bytes()
3782        }
3783
3784        #[doc = $to_xe_bytes_doc]
3788        #[doc = concat!("let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();")]
3793        #[doc = concat!("assert_eq!(bytes, ", $le_bytes, ");")]
3794        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
3796        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
3797        #[must_use = "this returns the result of the operation, \
3798                      without modifying the original"]
3799        #[inline]
3800        pub const fn to_le_bytes(self) -> [u8; size_of::<Self>()] {
3801            self.to_le().to_ne_bytes()
3802        }
3803
3804        #[doc = $to_xe_bytes_doc]
3812        #[doc = concat!("let bytes = ", $swap_op, stringify!($SelfT), ".to_ne_bytes();")]
3820        #[doc = concat!("        ", $be_bytes)]
3824        #[doc = concat!("        ", $le_bytes)]
3826        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
3830        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
3831        #[allow(unnecessary_transmutes)]
3832        #[must_use = "this returns the result of the operation, \
3835                      without modifying the original"]
3836        #[inline]
3837        pub const fn to_ne_bytes(self) -> [u8; size_of::<Self>()] {
3838            unsafe { mem::transmute(self) }
3841        }
3842
3843        #[doc = $from_xe_bytes_doc]
3847        #[doc = concat!("let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");")]
3852        #[doc = concat!("assert_eq!(value, ", $swap_op, ");")]
3853        #[doc = concat!("fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")]
3859        #[doc = concat!("    let (int_bytes, rest) = input.split_at(size_of::<", stringify!($SelfT), ">());")]
3860        #[doc = concat!("    ", stringify!($SelfT), "::from_be_bytes(int_bytes.try_into().unwrap())")]
3862        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
3865        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
3866        #[must_use]
3867        #[inline]
3868        #[cfg(not(feature = "ferrocene_certified"))]
3869        pub const fn from_be_bytes(bytes: [u8; size_of::<Self>()]) -> Self {
3870            Self::from_be(Self::from_ne_bytes(bytes))
3871        }
3872
3873        #[doc = $from_xe_bytes_doc]
3877        #[doc = concat!("let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");")]
3882        #[doc = concat!("assert_eq!(value, ", $swap_op, ");")]
3883        #[doc = concat!("fn read_le_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")]
3889        #[doc = concat!("    let (int_bytes, rest) = input.split_at(size_of::<", stringify!($SelfT), ">());")]
3890        #[doc = concat!("    ", stringify!($SelfT), "::from_le_bytes(int_bytes.try_into().unwrap())")]
3892        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
3895        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
3896        #[must_use]
3897        #[inline]
3898        pub const fn from_le_bytes(bytes: [u8; size_of::<Self>()]) -> Self {
3899            Self::from_le(Self::from_ne_bytes(bytes))
3900        }
3901
3902        #[doc = $from_xe_bytes_doc]
3913        #[doc = concat!("let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"big\") {")]
3918        #[doc = concat!("    ", $be_bytes)]
3919        #[doc = concat!("    ", $le_bytes)]
3921        #[doc = concat!("assert_eq!(value, ", $swap_op, ");")]
3923        #[doc = concat!("fn read_ne_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " {")]
3929        #[doc = concat!("    let (int_bytes, rest) = input.split_at(size_of::<", stringify!($SelfT), ">());")]
3930        #[doc = concat!("    ", stringify!($SelfT), "::from_ne_bytes(int_bytes.try_into().unwrap())")]
3932        #[stable(feature = "int_to_from_bytes", since = "1.32.0")]
3935        #[rustc_const_stable(feature = "const_int_conversion", since = "1.44.0")]
3936        #[allow(unnecessary_transmutes)]
3937        #[must_use]
3938        #[inline]
3941        pub const fn from_ne_bytes(bytes: [u8; size_of::<Self>()]) -> Self {
3942            unsafe { mem::transmute(bytes) }
3944        }
3945
3946        #[doc = concat!("[`", stringify!($SelfT), "::MIN", "`] instead.")]
3948        #[stable(feature = "rust1", since = "1.0.0")]
3951        #[inline(always)]
3952        #[rustc_promotable]
3953        #[rustc_const_stable(feature = "const_min_value", since = "1.32.0")]
3954        #[deprecated(since = "TBD", note = "replaced by the `MIN` associated constant on this type")]
3955        #[rustc_diagnostic_item = concat!(stringify!($SelfT), "_legacy_fn_min_value")]
3956        #[cfg(not(feature = "ferrocene_certified"))]
3957        pub const fn min_value() -> Self {
3958            Self::MIN
3959        }
3960
3961        #[doc = concat!("[`", stringify!($SelfT), "::MAX", "`] instead.")]
3963        #[stable(feature = "rust1", since = "1.0.0")]
3966        #[inline(always)]
3967        #[rustc_promotable]
3968        #[rustc_const_stable(feature = "const_max_value", since = "1.32.0")]
3969        #[deprecated(since = "TBD", note = "replaced by the `MAX` associated constant on this type")]
3970        #[rustc_diagnostic_item = concat!(stringify!($SelfT), "_legacy_fn_max_value")]
3971        #[cfg(not(feature = "ferrocene_certified"))]
3972        pub const fn max_value() -> Self {
3973            Self::MAX
3974        }
3975    }
3976}