Move intrinsics-based float methods out of libcore into libstd
Affected methods are `abs`, `signum`, and `powi`. CC https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[cfg(stage0)]
|
||||
use core::num::Float;
|
||||
#[cfg(not(test))]
|
||||
use intrinsics;
|
||||
@@ -163,7 +164,9 @@ impl f32 {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn abs(self) -> f32 { Float::abs(self) }
|
||||
pub fn abs(self) -> f32 {
|
||||
unsafe { intrinsics::fabsf32(self) }
|
||||
}
|
||||
|
||||
/// Returns a number that represents the sign of `self`.
|
||||
///
|
||||
@@ -183,7 +186,13 @@ impl f32 {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn signum(self) -> f32 { Float::signum(self) }
|
||||
pub fn signum(self) -> f32 {
|
||||
if self.is_nan() {
|
||||
NAN
|
||||
} else {
|
||||
unsafe { intrinsics::copysignf32(1.0, self) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
||||
/// error. This produces a more accurate result with better performance than
|
||||
@@ -272,7 +281,9 @@ impl f32 {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn powi(self, n: i32) -> f32 { Float::powi(self, n) }
|
||||
pub fn powi(self, n: i32) -> f32 {
|
||||
unsafe { intrinsics::powif32(self, n) }
|
||||
}
|
||||
|
||||
/// Raises a number to a floating point power.
|
||||
///
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#![allow(missing_docs)]
|
||||
|
||||
#[cfg(not(test))]
|
||||
#[cfg(stage0)]
|
||||
use core::num::Float;
|
||||
#[cfg(not(test))]
|
||||
use intrinsics;
|
||||
@@ -141,7 +142,9 @@ impl f64 {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn abs(self) -> f64 { Float::abs(self) }
|
||||
pub fn abs(self) -> f64 {
|
||||
unsafe { intrinsics::fabsf64(self) }
|
||||
}
|
||||
|
||||
/// Returns a number that represents the sign of `self`.
|
||||
///
|
||||
@@ -161,7 +164,13 @@ impl f64 {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn signum(self) -> f64 { Float::signum(self) }
|
||||
pub fn signum(self) -> f64 {
|
||||
if self.is_nan() {
|
||||
NAN
|
||||
} else {
|
||||
unsafe { intrinsics::copysignf64(1.0, self) }
|
||||
}
|
||||
}
|
||||
|
||||
/// Fused multiply-add. Computes `(self * a) + b` with only one rounding
|
||||
/// error. This produces a more accurate result with better performance than
|
||||
@@ -245,7 +254,9 @@ impl f64 {
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[inline]
|
||||
pub fn powi(self, n: i32) -> f64 { Float::powi(self, n) }
|
||||
pub fn powi(self, n: i32) -> f64 {
|
||||
unsafe { intrinsics::powif64(self, n) }
|
||||
}
|
||||
|
||||
/// Raises a number to a floating point power.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user