summaryrefslogtreecommitdiffstats
path: root/library/std/src/f32.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:39 +0000
commit1376c5a617be5c25655d0d7cb63e3beaa5a6e026 (patch)
tree3bb8d61aee02bc7a15eab3f36e3b921afc2075d0 /library/std/src/f32.rs
parentReleasing progress-linux version 1.69.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.tar.xz
rustc-1376c5a617be5c25655d0d7cb63e3beaa5a6e026.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/std/src/f32.rs')
-rw-r--r--library/std/src/f32.rs36
1 files changed, 34 insertions, 2 deletions
diff --git a/library/std/src/f32.rs b/library/std/src/f32.rs
index 6b1f0cba8..408244b2c 100644
--- a/library/std/src/f32.rs
+++ b/library/std/src/f32.rs
@@ -78,10 +78,14 @@ impl f32 {
/// let f = 3.3_f32;
/// let g = -3.3_f32;
/// let h = -3.7_f32;
+ /// let i = 3.5_f32;
+ /// let j = 4.5_f32;
///
/// 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 f32 {
unsafe { intrinsics::roundf32(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_f32;
+ /// let g = -3.3_f32;
+ /// let h = 3.5_f32;
+ /// let i = 4.5_f32;
+ ///
+ /// 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) -> f32 {
+ unsafe { intrinsics::rintf32(self) }
+ }
+
/// Returns the integer part of `self`.
/// This means that non-integer numbers are always truncated towards zero.
///
@@ -551,8 +581,10 @@ impl f32 {
unsafe { cmath::cbrtf(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
///