Make it compile on 1.8.0

This commit is contained in:
Yoan Lecoq 2019-02-03 14:49:38 +01:00 committed by Josh Stone
parent fec6c3610c
commit b4558d1c49
2 changed files with 47 additions and 20 deletions

View File

@ -17,7 +17,7 @@ exclude = ["/ci/*", "/.travis.yml", "/bors.toml"]
features = ["std"] features = ["std"]
[dependencies] [dependencies]
libm = { version = "~0.1.2", optional = true } libm = { version = "0.1", optional = true }
[features] [features]
default = ["std"] default = ["std"]

View File

@ -10,6 +10,7 @@ use {Num, NumCast, ToPrimitive};
#[cfg(feature = "libm")] #[cfg(feature = "libm")]
use libm::{F32Ext, F64Ext}; use libm::{F32Ext, F64Ext};
/// Generic trait for floating point numbers that works with `no_std`. /// Generic trait for floating point numbers that works with `no_std`.
/// ///
/// This trait implements a subset of the `Float` trait. /// This trait implements a subset of the `Float` trait.
@ -1808,9 +1809,9 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
fn integer_decode(self) -> (u64, i16, i8); fn integer_decode(self) -> (u64, i16, i8);
} }
#[cfg(any(feature = "std", feature = "libm"))] #[cfg(feature = "std")]
macro_rules! float_impl { macro_rules! float_impl_std {
($T:ident $decode:ident $LibmImpl:ident) => { ($T:ident $decode:ident) => {
impl Float for $T { impl Float for $T {
constant! { constant! {
nan() -> $T::NAN; nan() -> $T::NAN;
@ -1823,26 +1824,17 @@ macro_rules! float_impl {
max_value() -> $T::MAX; max_value() -> $T::MAX;
} }
#[cfg(feature = "std")]
#[inline] #[inline]
#[allow(deprecated)] #[allow(deprecated)]
fn abs_sub(self, other: Self) -> Self { fn abs_sub(self, other: Self) -> Self {
<$T>::abs_sub(self, other) <$T>::abs_sub(self, other)
} }
#[cfg(all(not(feature = "std"), feature = "libm"))]
#[inline]
#[allow(deprecated)]
fn abs_sub(self, other: Self) -> Self {
<$T as $LibmImpl>::fdim(self, other)
}
#[inline] #[inline]
fn integer_decode(self) -> (u64, i16, i8) { fn integer_decode(self) -> (u64, i16, i8) {
$decode(self) $decode(self)
} }
#[cfg(feature = "std")]
forward!{ forward!{
Self::is_nan(self) -> bool; Self::is_nan(self) -> bool;
Self::is_infinite(self) -> bool; Self::is_infinite(self) -> bool;
@ -1892,7 +1884,36 @@ macro_rules! float_impl {
Self::acosh(self) -> Self; Self::acosh(self) -> Self;
Self::atanh(self) -> Self; Self::atanh(self) -> Self;
} }
#[cfg(all(not(feature = "std"), feature = "libm"))] }
};
}
#[cfg(feature = "libm")]
macro_rules! float_impl_libm {
($T:ident $decode:ident $LibmImpl:ident) => {
impl Float for $T {
constant! {
nan() -> $T::NAN;
infinity() -> $T::INFINITY;
neg_infinity() -> $T::NEG_INFINITY;
neg_zero() -> -0.0;
min_value() -> $T::MIN;
min_positive_value() -> $T::MIN_POSITIVE;
epsilon() -> $T::EPSILON;
max_value() -> $T::MAX;
}
#[inline]
#[allow(deprecated)]
fn abs_sub(self, other: Self) -> Self {
<$T as $LibmImpl>::fdim(self, other)
}
#[inline]
fn integer_decode(self) -> (u64, i16, i8) {
$decode(self)
}
forward!{ forward!{
FloatCore::is_nan(self) -> bool; FloatCore::is_nan(self) -> bool;
FloatCore::is_infinite(self) -> bool; FloatCore::is_infinite(self) -> bool;
@ -1978,10 +1999,16 @@ fn integer_decode_f64(f: f64) -> (u64, i16, i8) {
(mantissa, exponent, sign) (mantissa, exponent, sign)
} }
#[cfg(any(feature = "std", feature = "libm"))] #[cfg(feature = "std")]
float_impl!(f32 integer_decode_f32 F32Ext); float_impl_std!(f32 integer_decode_f32);
#[cfg(any(feature = "std", feature = "libm"))] #[cfg(feature = "std")]
float_impl!(f64 integer_decode_f64 F64Ext); float_impl_std!(f64 integer_decode_f64);
#[cfg(all(not(feature = "std"), feature = "libm"))]
float_impl_libm!(f32 integer_decode_f32 F32Ext);
#[cfg(all(not(feature = "std"), feature = "libm"))]
float_impl_libm!(f64 integer_decode_f64 F64Ext);
macro_rules! float_const_impl { macro_rules! float_const_impl {
($(#[$doc:meta] $constant:ident,)+) => ( ($(#[$doc:meta] $constant:ident,)+) => (