Auto merge of #148526 - reddevilmidzy:docs, r=Mark-Simulacrum
Expand pow docs with special-case tests resolve: rust-lang/rust#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
This commit is contained in:
commit
54f417673c
8 changed files with 20 additions and 0 deletions
|
|
@ -1770,6 +1770,7 @@ impl 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]
|
||||
|
|
|
|||
|
|
@ -1745,6 +1745,7 @@ impl 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]
|
||||
|
|
|
|||
|
|
@ -1720,6 +1720,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);")]
|
||||
/// ```
|
||||
|
||||
|
|
@ -1761,6 +1762,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:
|
||||
|
|
@ -2033,6 +2035,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);")]
|
||||
/// ```
|
||||
|
|
@ -2377,6 +2380,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")]
|
||||
|
|
@ -2967,6 +2971,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")]
|
||||
|
|
@ -3010,6 +3015,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")]
|
||||
|
|
|
|||
|
|
@ -2055,6 +2055,7 @@ macro_rules! uint_impl {
|
|||
///
|
||||
/// ```
|
||||
#[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")]
|
||||
|
|
@ -2095,6 +2096,7 @@ macro_rules! uint_impl {
|
|||
///
|
||||
/// ```
|
||||
#[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:
|
||||
|
|
@ -2269,6 +2271,7 @@ macro_rules! uint_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), "::MAX.saturating_pow(2), ", stringify!($SelfT), "::MAX);")]
|
||||
/// ```
|
||||
#[stable(feature = "no_panic_pow", since = "1.34.0")]
|
||||
|
|
@ -2578,6 +2581,7 @@ macro_rules! uint_impl {
|
|||
/// ```
|
||||
#[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")]
|
||||
|
|
@ -3252,6 +3256,7 @@ macro_rules! uint_impl {
|
|||
///
|
||||
/// ```
|
||||
#[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")]
|
||||
|
|
@ -3293,6 +3298,7 @@ macro_rules! uint_impl {
|
|||
///
|
||||
/// ```
|
||||
#[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")]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -308,6 +308,7 @@ impl 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 @@ impl 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"]
|
||||
|
|
|
|||
|
|
@ -308,6 +308,7 @@ impl 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 @@ impl 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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue