Skip to content

Commit 54f4176

Browse files
committed
Auto merge of #148526 - reddevilmidzy:docs, r=Mark-Simulacrum
Expand pow docs with special-case tests resolve: #148316 Files changed: * library/std/src/num: f32.rs, f64.rs, * powi * powf * library/std/src/num: f16.rs, f128.rs * powf * library/core/src/num: f16.rs, f128.rs * powi * library/core/src/num: int_macros.rs, uint_macros.rs * checked_pow * strict_pow * saturating_pow * wrapping_pow * overflowing_pow * pow
2 parents e65b983 + 5d595cf commit 54f4176

File tree

8 files changed

+20
-0
lines changed

8 files changed

+20
-0
lines changed

library/core/src/num/f128.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,6 +1770,7 @@ impl f128 {
17701770
/// assert!(abs_difference <= f128::EPSILON);
17711771
///
17721772
/// assert_eq!(f128::powi(f128::NAN, 0), 1.0);
1773+
/// assert_eq!(f128::powi(0.0, 0), 1.0);
17731774
/// # }
17741775
/// ```
17751776
#[inline]

library/core/src/num/f16.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,7 @@ impl f16 {
17451745
/// assert!(abs_difference <= f16::EPSILON);
17461746
///
17471747
/// assert_eq!(f16::powi(f16::NAN, 0), 1.0);
1748+
/// assert_eq!(f16::powi(0.0, 0), 1.0);
17481749
/// # }
17491750
/// ```
17501751
#[inline]

library/core/src/num/int_macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,7 @@ macro_rules! int_impl {
17201720
///
17211721
/// ```
17221722
#[doc = concat!("assert_eq!(8", stringify!($SelfT), ".checked_pow(2), Some(64));")]
1723+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".checked_pow(0), Some(1));")]
17231724
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
17241725
/// ```
17251726
@@ -1761,6 +1762,7 @@ macro_rules! int_impl {
17611762
///
17621763
/// ```
17631764
#[doc = concat!("assert_eq!(8", stringify!($SelfT), ".strict_pow(2), 64);")]
1765+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".strict_pow(0), 1);")]
17641766
/// ```
17651767
///
17661768
/// The following panics because of overflow:
@@ -2033,6 +2035,7 @@ macro_rules! int_impl {
20332035
///
20342036
/// ```
20352037
#[doc = concat!("assert_eq!((-4", stringify!($SelfT), ").saturating_pow(3), -64);")]
2038+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".saturating_pow(0), 1);")]
20362039
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
20372040
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_pow(3), ", stringify!($SelfT), "::MIN);")]
20382041
/// ```
@@ -2377,6 +2380,7 @@ macro_rules! int_impl {
23772380
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(4), 81);")]
23782381
/// assert_eq!(3i8.wrapping_pow(5), -13);
23792382
/// assert_eq!(3i8.wrapping_pow(6), -39);
2383+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".wrapping_pow(0), 1);")]
23802384
/// ```
23812385
#[stable(feature = "no_panic_pow", since = "1.34.0")]
23822386
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
@@ -2967,6 +2971,7 @@ macro_rules! int_impl {
29672971
///
29682972
/// ```
29692973
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(4), (81, false));")]
2974+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".overflowing_pow(0), (1, false));")]
29702975
/// assert_eq!(3i8.overflowing_pow(5), (-13, true));
29712976
/// ```
29722977
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -3010,6 +3015,7 @@ macro_rules! int_impl {
30103015
#[doc = concat!("let x: ", stringify!($SelfT), " = 2; // or any other integer type")]
30113016
///
30123017
/// assert_eq!(x.pow(5), 32);
3018+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".pow(0), 1);")]
30133019
/// ```
30143020
#[stable(feature = "rust1", since = "1.0.0")]
30153021
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]

library/core/src/num/uint_macros.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,7 @@ macro_rules! uint_impl {
20552055
///
20562056
/// ```
20572057
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".checked_pow(5), Some(32));")]
2058+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".checked_pow(0), Some(1));")]
20582059
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.checked_pow(2), None);")]
20592060
/// ```
20602061
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -2095,6 +2096,7 @@ macro_rules! uint_impl {
20952096
///
20962097
/// ```
20972098
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".strict_pow(5), 32);")]
2099+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".strict_pow(0), 1);")]
20982100
/// ```
20992101
///
21002102
/// The following panics because of overflow:
@@ -2269,6 +2271,7 @@ macro_rules! uint_impl {
22692271
///
22702272
/// ```
22712273
#[doc = concat!("assert_eq!(4", stringify!($SelfT), ".saturating_pow(3), 64);")]
2274+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".saturating_pow(0), 1);")]
22722275
#[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
22732276
/// ```
22742277
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -2578,6 +2581,7 @@ macro_rules! uint_impl {
25782581
/// ```
25792582
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".wrapping_pow(5), 243);")]
25802583
/// assert_eq!(3u8.wrapping_pow(6), 217);
2584+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".wrapping_pow(0), 1);")]
25812585
/// ```
25822586
#[stable(feature = "no_panic_pow", since = "1.34.0")]
25832587
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]
@@ -3252,6 +3256,7 @@ macro_rules! uint_impl {
32523256
///
32533257
/// ```
32543258
#[doc = concat!("assert_eq!(3", stringify!($SelfT), ".overflowing_pow(5), (243, false));")]
3259+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".overflowing_pow(0), (1, false));")]
32553260
/// assert_eq!(3u8.overflowing_pow(6), (217, true));
32563261
/// ```
32573262
#[stable(feature = "no_panic_pow", since = "1.34.0")]
@@ -3293,6 +3298,7 @@ macro_rules! uint_impl {
32933298
///
32943299
/// ```
32953300
#[doc = concat!("assert_eq!(2", stringify!($SelfT), ".pow(5), 32);")]
3301+
#[doc = concat!("assert_eq!(0_", stringify!($SelfT), ".pow(0), 1);")]
32963302
/// ```
32973303
#[stable(feature = "rust1", since = "1.0.0")]
32983304
#[rustc_const_stable(feature = "const_int_pow", since = "1.50.0")]

library/std/src/num/f128.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl f128 {
3737
///
3838
/// assert_eq!(f128::powf(1.0, f128::NAN), 1.0);
3939
/// assert_eq!(f128::powf(f128::NAN, 0.0), 1.0);
40+
/// assert_eq!(f128::powf(0.0, 0.0), 1.0);
4041
/// # }
4142
/// ```
4243
#[inline]

library/std/src/num/f16.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl f16 {
3737
///
3838
/// assert_eq!(f16::powf(1.0, f16::NAN), 1.0);
3939
/// assert_eq!(f16::powf(f16::NAN, 0.0), 1.0);
40+
/// assert_eq!(f16::powf(0.0, 0.0), 1.0);
4041
/// # }
4142
/// ```
4243
#[inline]

library/std/src/num/f32.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ impl f32 {
308308
/// assert!(abs_difference <= 1e-5);
309309
///
310310
/// assert_eq!(f32::powi(f32::NAN, 0), 1.0);
311+
/// assert_eq!(f32::powi(0.0, 0), 1.0);
311312
/// ```
312313
#[rustc_allow_incoherent_impl]
313314
#[must_use = "method returns a new number and does not mutate the original value"]
@@ -333,6 +334,7 @@ impl f32 {
333334
///
334335
/// assert_eq!(f32::powf(1.0, f32::NAN), 1.0);
335336
/// assert_eq!(f32::powf(f32::NAN, 0.0), 1.0);
337+
/// assert_eq!(f32::powf(0.0, 0.0), 1.0);
336338
/// ```
337339
#[rustc_allow_incoherent_impl]
338340
#[must_use = "method returns a new number and does not mutate the original value"]

library/std/src/num/f64.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ impl f64 {
308308
/// assert!(abs_difference <= 1e-14);
309309
///
310310
/// assert_eq!(f64::powi(f64::NAN, 0), 1.0);
311+
/// assert_eq!(f64::powi(0.0, 0), 1.0);
311312
/// ```
312313
#[rustc_allow_incoherent_impl]
313314
#[must_use = "method returns a new number and does not mutate the original value"]
@@ -333,6 +334,7 @@ impl f64 {
333334
///
334335
/// assert_eq!(f64::powf(1.0, f64::NAN), 1.0);
335336
/// assert_eq!(f64::powf(f64::NAN, 0.0), 1.0);
337+
/// assert_eq!(f64::powf(0.0, 0.0), 1.0);
336338
/// ```
337339
#[rustc_allow_incoherent_impl]
338340
#[must_use = "method returns a new number and does not mutate the original value"]

0 commit comments

Comments
 (0)