From ac503261ca1d82457a5a3a72332c050cf4eb8369 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 27 Feb 2018 14:41:09 -0800 Subject: [PATCH] Forward FloatCore to inherent methods when possible --- src/cast.rs | 1 - src/float.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/cast.rs b/src/cast.rs index 3d7d0a6..630341f 100644 --- a/src/cast.rs +++ b/src/cast.rs @@ -1,4 +1,3 @@ -use core::f64; use core::mem::size_of; use core::num::Wrapping; diff --git a/src/float.rs b/src/float.rs index d09bef7..c2e28d4 100644 --- a/src/float.rs +++ b/src/float.rs @@ -166,6 +166,7 @@ impl FloatCore for f32 { } #[inline] + #[cfg(not(feature = "std"))] fn classify(self) -> FpCategory { const EXP_MASK: u32 = 0x7f800000; const MAN_MASK: u32 = 0x007fffff; @@ -181,14 +182,35 @@ impl FloatCore for f32 { } #[inline] + #[cfg(not(feature = "std"))] fn to_degrees(self) -> Self { self * (180.0 / ::core::f32::consts::PI) } #[inline] + #[cfg(not(feature = "std"))] fn to_radians(self) -> Self { self * (::core::f32::consts::PI / 180.0) } + + #[cfg(feature = "std")] + forward! { + Self::is_nan(self) -> bool; + Self::is_infinite(self) -> bool; + Self::is_finite(self) -> bool; + Self::is_normal(self) -> bool; + Self::classify(self) -> FpCategory; + Self::abs(self) -> Self; + Self::signum(self) -> Self; + Self::is_sign_positive(self) -> bool; + Self::is_sign_negative(self) -> bool; + Self::min(self, other: Self) -> Self; + Self::max(self, other: Self) -> Self; + Self::recip(self) -> Self; + Self::powi(self, n: i32) -> Self; + Self::to_degrees(self) -> Self; + Self::to_radians(self) -> Self; + } } impl FloatCore for f64 { @@ -208,6 +230,7 @@ impl FloatCore for f64 { } #[inline] + #[cfg(not(feature = "std"))] fn classify(self) -> FpCategory { const EXP_MASK: u64 = 0x7ff0000000000000; const MAN_MASK: u64 = 0x000fffffffffffff; @@ -223,14 +246,35 @@ impl FloatCore for f64 { } #[inline] + #[cfg(not(feature = "std"))] fn to_degrees(self) -> Self { self * (180.0 / ::core::f64::consts::PI) } #[inline] + #[cfg(not(feature = "std"))] fn to_radians(self) -> Self { self * (::core::f64::consts::PI / 180.0) } + + #[cfg(feature = "std")] + forward! { + Self::is_nan(self) -> bool; + Self::is_infinite(self) -> bool; + Self::is_finite(self) -> bool; + Self::is_normal(self) -> bool; + Self::classify(self) -> FpCategory; + Self::abs(self) -> Self; + Self::signum(self) -> Self; + Self::is_sign_positive(self) -> bool; + Self::is_sign_negative(self) -> bool; + Self::min(self, other: Self) -> Self; + Self::max(self, other: Self) -> Self; + Self::recip(self) -> Self; + Self::powi(self, n: i32) -> Self; + Self::to_degrees(self) -> Self; + Self::to_radians(self) -> Self; + } } // FIXME: these doctests aren't actually helpful, because they're using and