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
+1
View File
@@ -1770,6 +1770,7 @@ pub fn rem_euclid(self, rhs: f128) -> f128 {
/// assert!(abs_difference <= f128::EPSILON);
///
/// assert_eq!(f128::powi(f128::NAN, 0), 1.0);
/// assert_eq!(f128::powi(0.0, 0), 1.0);
/// # }
/// ```
#[inline]
+1
View File
@@ -1745,6 +1745,7 @@ pub fn rem_euclid(self, rhs: f16) -> f16 {
/// assert!(abs_difference <= f16::EPSILON);
///
/// assert_eq!(f16::powi(f16::NAN, 0), 1.0);
/// assert_eq!(f16::powi(0.0, 0), 1.0);
/// # }
/// ```
#[inline]
+6
View File
@@ -1714,6 +1714,7 @@ pub const fn strict_abs(self) -> Self {
///
/// ```
#[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 @@ pub const fn checked_pow(self, mut exp: u32) -> Option<Self> {
///
/// ```
#[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 @@ pub const fn saturating_div(self, rhs: Self) -> Self {
///
/// ```
#[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 @@ pub const fn unsigned_abs(self) -> $UnsignedT {
#[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 @@ pub const fn overflowing_abs(self) -> (Self, bool) {
///
/// ```
#[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 @@ pub const fn overflowing_pow(self, mut exp: u32) -> (Self, bool) {
#[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")]
+6
View File
@@ -2057,6 +2057,7 @@ pub const fn exact_shr(self, rhs: u32) -> Option<$SelfT> {
///
/// ```
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_pow(5), Some(32));")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".checked_pow(0), Some(1));")]
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
/// ```
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -2097,6 +2098,7 @@ pub const fn checked_pow(self, mut exp: u32) -> Option<Self> {
///
/// ```
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".strict_pow(5), 32);")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".strict_pow(0), 1);")]
/// ```
///
/// The following panics because of overflow:
@@ -2271,6 +2273,7 @@ pub const fn saturating_div(self, rhs: Self) -> Self {
///
/// ```
#[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), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
/// ```
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -2580,6 +2583,7 @@ pub const fn wrapping_shr(self, rhs: u32) -> Self {
/// ```
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(5), 243);")]
/// assert_eq!(3u8.wrapping_pow(6), 217);
#[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")]
@@ -3254,6 +3258,7 @@ pub const fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
///
/// ```
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(5), (243, false));")]
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".overflowing_pow(0), (1, false));")]
/// assert_eq!(3u8.overflowing_pow(6), (217, true));
/// ```
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -3295,6 +3300,7 @@ pub const fn overflowing_pow(self, mut exp: u32) -> (Self, bool) {
///
/// ```
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".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")]
+1
View File
@@ -37,6 +37,7 @@ impl f128 {
///
/// assert_eq!(f128::powf(1.0, f128::NAN), 1.0);
/// assert_eq!(f128::powf(f128::NAN, 0.0), 1.0);
/// assert_eq!(f128::powf(0.0, 0.0), 1.0);
/// # }
/// ```
#[inline]
+1
View File
@@ -37,6 +37,7 @@ impl f16 {
///
/// assert_eq!(f16::powf(1.0, f16::NAN), 1.0);
/// assert_eq!(f16::powf(f16::NAN, 0.0), 1.0);
/// assert_eq!(f16::powf(0.0, 0.0), 1.0);
/// # }
/// ```
#[inline]
+2
View File
@@ -308,6 +308,7 @@ pub fn rem_euclid(self, rhs: f32) -> f32 {
/// assert!(abs_difference <= 1e-5);
///
/// assert_eq!(f32::powi(f32::NAN, 0), 1.0);
/// assert_eq!(f32::powi(0.0, 0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
@@ -333,6 +334,7 @@ pub fn powi(self, n: i32) -> f32 {
///
/// assert_eq!(f32::powf(1.0, f32::NAN), 1.0);
/// assert_eq!(f32::powf(f32::NAN, 0.0), 1.0);
/// assert_eq!(f32::powf(0.0, 0.0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
+2
View File
@@ -308,6 +308,7 @@ pub fn rem_euclid(self, rhs: f64) -> f64 {
/// assert!(abs_difference <= 1e-14);
///
/// assert_eq!(f64::powi(f64::NAN, 0), 1.0);
/// assert_eq!(f64::powi(0.0, 0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
@@ -333,6 +334,7 @@ pub fn powi(self, n: i32) -> f64 {
///
/// assert_eq!(f64::powf(1.0, f64::NAN), 1.0);
/// assert_eq!(f64::powf(f64::NAN, 0.0), 1.0);
/// assert_eq!(f64::powf(0.0, 0.0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]