summaryrefslogtreecommitdiffstats
path: root/library/std/src/f64.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/std/src/f64.rs')
-rw-r--r--library/std/src/f64.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/library/std/src/f64.rs b/library/std/src/f64.rs
index 16359766b..6782b861f 100644
--- a/library/std/src/f64.rs
+++ b/library/std/src/f64.rs
@@ -78,10 +78,14 @@ impl f64 {
/// let f = 3.3_f64;
/// let g = -3.3_f64;
/// let h = -3.7_f64;
+ /// let i = 3.5_f64;
+ /// let j = 4.5_f64;
///
/// assert_eq!(f.round(), 3.0);
/// assert_eq!(g.round(), -3.0);
/// assert_eq!(h.round(), -4.0);
+ /// assert_eq!(i.round(), 4.0);
+ /// assert_eq!(j.round(), 5.0);
/// ```
#[rustc_allow_incoherent_impl]
#[must_use = "method returns a new number and does not mutate the original value"]
@@ -91,6 +95,32 @@ impl f64 {
unsafe { intrinsics::roundf64(self) }
}
+ /// Returns the nearest integer to a number. Rounds half-way cases to the number
+ /// with an even least significant digit.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(round_ties_even)]
+ ///
+ /// let f = 3.3_f64;
+ /// let g = -3.3_f64;
+ /// let h = 3.5_f64;
+ /// let i = 4.5_f64;
+ ///
+ /// assert_eq!(f.round_ties_even(), 3.0);
+ /// assert_eq!(g.round_ties_even(), -3.0);
+ /// assert_eq!(h.round_ties_even(), 4.0);
+ /// assert_eq!(i.round_ties_even(), 4.0);
+ /// ```
+ #[rustc_allow_incoherent_impl]
+ #[must_use = "method returns a new number and does not mutate the original value"]
+ #[unstable(feature = "round_ties_even", issue = "96710")]
+ #[inline]
+ pub fn round_ties_even(self) -> f64 {
+ unsafe { intrinsics::rintf64(self) }
+ }
+
/// Returns the integer part of `self`.
/// This means that non-integer numbers are always truncated towards zero.
///
@@ -553,8 +583,10 @@ impl f64 {
unsafe { cmath::cbrt(self) }
}
- /// Calculates the length of the hypotenuse of a right-angle triangle given
- /// legs of length `x` and `y`.
+ /// Compute the distance between the origin and a point (`x`, `y`) on the
+ /// Euclidean plane. Equivalently, compute the length of the hypotenuse of a
+ /// right-angle triangle with other sides having length `x.abs()` and
+ /// `y.abs()`.
///
/// # Examples
///