Use rint instead of roundeven

Use rint intrinsic instead of roundeven to impement `round_ties_even`. They do the same thing when rounding mode is default, which Rust assumes.
And `rint` has better platform support.

Keeps `roundeven` around in `core::intrinsics`, it's doing no harm there.
This commit is contained in:
Jules Bertholet 2022-11-07 13:10:36 -05:00
parent 03c166d389
commit f8138110bc
No known key found for this signature in database
GPG Key ID: 32034DAFC38C1BFC
4 changed files with 12 additions and 7 deletions

View File

@ -295,6 +295,8 @@ fn codegen_float_intrinsic_call<'tcx>(
sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64),
sym::truncf32 => ("truncf", 1, fx.tcx.types.f32),
sym::truncf64 => ("trunc", 1, fx.tcx.types.f64),
sym::rintf32 => ("rintf", 1, fx.tcx.types.f32),
sym::rintf64 => ("rint", 1, fx.tcx.types.f64),
sym::roundf32 => ("roundf", 1, fx.tcx.types.f32),
sym::roundf64 => ("round", 1, fx.tcx.types.f64),
sym::roundevenf32 => ("roundevenf", 1, fx.tcx.types.f32),

View File

@ -1588,9 +1588,15 @@ extern "rust-intrinsic" {
/// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
/// if the argument is not an integer.
///
/// The stabilized version of this intrinsic is
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
pub fn rintf32(x: f32) -> f32;
/// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
/// if the argument is not an integer.
///
/// The stabilized version of this intrinsic is
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
pub fn rintf64(x: f64) -> f64;
/// Returns the nearest integer to an `f32`.
@ -1616,16 +1622,13 @@ extern "rust-intrinsic" {
/// Returns the nearest integer to an `f32`. Rounds half-way cases to the number
/// with an even least significant digit.
///
/// The stabilized version of this intrinsic is
/// [`f32::round_ties_even`](../../std/primitive.f32.html#method.round_ties_even)
/// This intrinsic does not have a stable counterpart.
#[cfg(not(bootstrap))]
pub fn roundevenf32(x: f32) -> f32;
/// Returns the nearest integer to an `f64`. Rounds half-way cases to the number
/// with an even least significant digit.
///
/// The stabilized version of this intrinsic is
/// [`f64::round_ties_even`](../../std/primitive.f64.html#method.round_ties_even)
/// This intrinsic does not have a stable counterpart.
#[cfg(not(bootstrap))]
pub fn roundevenf64(x: f64) -> f64;

View File

@ -119,7 +119,7 @@ impl f32 {
#[unstable(feature = "round_ties_even", issue = "96710")]
#[inline]
pub fn round_ties_even(self) -> f32 {
unsafe { intrinsics::roundevenf32(self) }
unsafe { intrinsics::rintf32(self) }
}
/// Returns the integer part of `self`.

View File

@ -119,7 +119,7 @@ impl f64 {
#[unstable(feature = "round_ties_even", issue = "96710")]
#[inline]
pub fn round_ties_even(self) -> f64 {
unsafe { intrinsics::roundevenf64(self) }
unsafe { intrinsics::rintf64(self) }
}
/// Returns the integer part of `self`.