Skip to content

Document powf and powi values that are always 1.0 #136012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion library/std/src/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ impl f128 {
///
/// The precision of this function is non-deterministic. This means it varies by platform,
/// Rust version, and can even differ within the same execution from one invocation to the next.
///
/// # Examples
///
/// ```
/// #![feature(f128)]
/// # #[cfg(reliable_f128_math)] {
///
/// let x = 2.0_f128;
/// let abs_difference = (x.powi(2) - (x * x)).abs();
/// assert!(abs_difference <= f128::EPSILON);
///
/// assert_eq!(f128::powi(f128::NAN, 0), 1.0);
/// # }
/// ```
#[inline]
#[rustc_allow_incoherent_impl]
#[unstable(feature = "f128", issue = "116909")]
Expand All @@ -347,8 +361,10 @@ impl f128 {
///
/// let x = 2.0_f128;
/// let abs_difference = (x.powf(2.0) - (x * x)).abs();
///
/// assert!(abs_difference <= f128::EPSILON);
///
/// assert_eq!(f128::powf(1.0, f128::NAN), 1.0);
/// assert_eq!(f128::powf(f128::NAN, 0.0), 1.0);
/// # }
/// ```
#[inline]
Expand Down
18 changes: 17 additions & 1 deletion library/std/src/f16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,20 @@ impl f16 {
///
/// The precision of this function is non-deterministic. This means it varies by platform,
/// Rust version, and can even differ within the same execution from one invocation to the next.
///
/// # Examples
///
/// ```
/// #![feature(f16)]
/// # #[cfg(reliable_f16_math)] {
///
/// let x = 2.0_f16;
/// let abs_difference = (x.powi(2) - (x * x)).abs();
/// assert!(abs_difference <= f16::EPSILON);
///
/// assert_eq!(f16::powi(f16::NAN, 0), 1.0);
/// # }
/// ```
#[inline]
#[rustc_allow_incoherent_impl]
#[unstable(feature = "f16", issue = "116909")]
Expand All @@ -347,8 +361,10 @@ impl f16 {
///
/// let x = 2.0_f16;
/// let abs_difference = (x.powf(2.0) - (x * x)).abs();
///
/// assert!(abs_difference <= f16::EPSILON);
///
/// assert_eq!(f16::powf(1.0, f16::NAN), 1.0);
/// assert_eq!(f16::powf(f16::NAN, 0.0), 1.0);
/// # }
/// ```
#[inline]
Expand Down
7 changes: 5 additions & 2 deletions library/std/src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ impl f32 {
/// ```
/// let x = 2.0_f32;
/// let abs_difference = (x.powi(2) - (x * x)).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
///
/// assert_eq!(f32::powi(f32::NAN, 0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
Expand All @@ -329,8 +330,10 @@ impl f32 {
/// ```
/// let x = 2.0_f32;
/// let abs_difference = (x.powf(2.0) - (x * x)).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
///
/// assert_eq!(f32::powf(1.0, f32::NAN), 1.0);
/// assert_eq!(f32::powf(f32::NAN, 0.0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
Expand Down
7 changes: 5 additions & 2 deletions library/std/src/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,9 @@ impl f64 {
/// ```
/// let x = 2.0_f64;
/// let abs_difference = (x.powi(2) - (x * x)).abs();
/// assert!(abs_difference <= f64::EPSILON);
///
/// assert!(abs_difference < 1e-10);
/// assert_eq!(f64::powi(f64::NAN, 0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
Expand All @@ -329,8 +330,10 @@ impl f64 {
/// ```
/// let x = 2.0_f64;
/// let abs_difference = (x.powf(2.0) - (x * x)).abs();
/// assert!(abs_difference <= f64::EPSILON);
///
/// assert!(abs_difference < 1e-10);
/// assert_eq!(f64::powf(1.0, f64::NAN), 1.0);
/// assert_eq!(f64::powf(f64::NAN, 0.0), 1.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
Expand Down
Loading