diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2018-04-10 16:36:23 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2018-04-21 09:47:37 +0200 |
| commit | 18ab16b5104403ef7a55a2d241c566e35c5ae57a (patch) | |
| tree | 7f2f5f8a80067698befb742e0f99720a0fd1fa29 /src/libstd | |
| parent | 8a374f2827a222322a631e313cd8fd8d9ba34932 (diff) | |
| download | rust-18ab16b5104403ef7a55a2d241c566e35c5ae57a.tar.gz rust-18ab16b5104403ef7a55a2d241c566e35c5ae57a.zip | |
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
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/f32.rs | 17 | ||||
| -rw-r--r-- | src/libstd/f64.rs | 17 |
2 files changed, 28 insertions, 6 deletions
diff --git a/src/libstd/f32.rs b/src/libstd/f32.rs index 82f4192de19..26644c76957 100644 --- a/src/libstd/f32.rs +++ b/src/libstd/f32.rs @@ -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. /// diff --git a/src/libstd/f64.rs b/src/libstd/f64.rs index d4a8f700a90..a7e63f59b1c 100644 --- a/src/libstd/f64.rs +++ b/src/libstd/f64.rs @@ -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. /// |
