Skip to content

Commit 18f43f2

Browse files
authored
Document powf and powi values that are always 1.0 (f16)
f16 part for bug rust-lang#90429
1 parent 8231e85 commit 18f43f2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

library/std/src/f16.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,15 @@ impl f16 {
324324
///
325325
/// The precision of this function is non-deterministic. This means it varies by platform,
326326
/// Rust version, and can even differ within the same execution from one invocation to the next.
327+
/// # Examples
328+
///
329+
/// ```
330+
/// let x = 2.0_f16;
331+
/// let abs_difference = (x.powi(2) - (x * x)).abs();
332+
/// assert!(abs_difference < f16::EPSILON);
333+
///
334+
/// assert_eq!(f16::powi(f16::NAN, 0), 1.0);
335+
/// ```
327336
#[inline]
328337
#[rustc_allow_incoherent_impl]
329338
#[unstable(feature = "f16", issue = "116909")]
@@ -347,8 +356,10 @@ impl f16 {
347356
///
348357
/// let x = 2.0_f16;
349358
/// let abs_difference = (x.powf(2.0) - (x * x)).abs();
350-
///
351359
/// assert!(abs_difference <= f16::EPSILON);
360+
///
361+
/// assert_eq!(f16::powf(1.0, f16::NAN), 1.0)
362+
/// assert_eq!(f16::powf(f16::NAN, 0.0), 1.0)
352363
/// # }
353364
/// ```
354365
#[inline]

0 commit comments

Comments
 (0)