Expand pow docs with special-case tests

This commit is contained in:
reddevilmidzy 2025-11-10 14:56:05 +09:00
parent e1243553b3
commit 5d595cf8ba
8 changed files with 20 additions and 0 deletions

View file

@ -1714,6 +1714,7 @@ macro_rules! int_impl {
///
/// ```
#[doc = concat!("assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64));")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".checked_pow(0), Some(1));")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
/// ```
@ -1755,6 +1756,7 @@ macro_rules! int_impl {
///
/// ```
#[doc = concat!("assert_eq!(8", stringify!($SelfT), ".strict_pow(2), 64);")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".strict_pow(0), 1);")]
/// ```
///
/// The following panics because of overflow:
@ -2027,6 +2029,7 @@ macro_rules! int_impl {
///
/// ```
#[doc = concat!("assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64);")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".saturating_pow(0), 1);")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT), "::MIN);")]
/// ```
@ -2371,6 +2374,7 @@ macro_rules! int_impl {
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(4), 81);")]
/// assert_eq!(3i8.wrapping_pow(5), -13);
/// assert_eq!(3i8.wrapping_pow(6), -39);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".wrapping_pow(0), 1);")]
/// ```
#[stable(feature = "no_panic_pow", since = "1.34.0")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
@ -2961,6 +2965,7 @@ macro_rules! int_impl {
///
/// ```
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(4), (81, false));")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".overflowing_pow(0), (1, false));")]
/// assert_eq!(3i8.overflowing_pow(5), (-13, true));
/// ```
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@ -3004,6 +3009,7 @@ macro_rules! int_impl {
#[doc = concat!("let x: ", stringify!($SelfT), " = 2; // or any other integer type")]
///
/// assert_eq!(x.pow(5), 32);
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".pow(0), 1);")]
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]