Skip to content

[docs] Clarify behaviour of f64 and f32::sqrt when argument is negative zero #86951

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
Jul 11, 2021
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
4 changes: 3 additions & 1 deletion library/std/src/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,20 @@ impl f32 {

/// Returns the square root of a number.
///
/// Returns NaN if `self` is a negative number.
/// Returns NaN if `self` is a negative number other than `-0.0`.
///
/// # Examples
///
/// ```
/// let positive = 4.0_f32;
/// let negative = -4.0_f32;
/// let negative_zero = -0.0_f32;
///
/// let abs_difference = (positive.sqrt() - 2.0).abs();
///
/// assert!(abs_difference <= f32::EPSILON);
/// assert!(negative.sqrt().is_nan());
/// assert!(negative_zero.sqrt() == negative_zero);
/// ```
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
4 changes: 3 additions & 1 deletion library/std/src/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,20 @@ impl f64 {

/// Returns the square root of a number.
///
/// Returns NaN if `self` is a negative number.
/// Returns NaN if `self` is a negative number other than `-0.0`.
///
/// # Examples
///
/// ```
/// let positive = 4.0_f64;
/// let negative = -4.0_f64;
/// let negative_zero = -0.0_f64;
///
/// let abs_difference = (positive.sqrt() - 2.0).abs();
///
/// assert!(abs_difference < 1e-10);
/// assert!(negative.sqrt().is_nan());
/// assert!(negative_zero.sqrt() == negative_zero);
/// ```
#[must_use = "method returns a new number and does not mutate the original value"]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down