Mark methods in `Float` whether they require `std`

This removes the `BasicFloat` trait.
This commit is contained in:
Vinzent Steinberg 2017-06-02 11:27:52 +02:00
parent 351dfc6383
commit 6253669ef4
4 changed files with 262 additions and 237 deletions

View File

@ -3,7 +3,7 @@ use core::num::Wrapping;
use identities::Zero;
use bounds::Bounded;
use float::BasicFloat;
use float::Float;
/// A generic trait for converting a value to a number.
pub trait ToPrimitive {
@ -228,7 +228,7 @@ macro_rules! impl_to_primitive_float_to_float {
// NaN and +-inf are cast as they are.
let n = $slf as f64;
let max_value: $DstT = ::core::$DstT::MAX;
if !BasicFloat::is_finite(n) || (-max_value as f64 <= n && n <= max_value as f64) {
if !Float::is_finite(n) || (-max_value as f64 <= n && n <= max_value as f64) {
Some($slf as $DstT)
} else {
None

File diff suppressed because it is too large Load Diff

View File

@ -23,7 +23,7 @@ use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
use core::num::Wrapping;
pub use bounds::Bounded;
pub use float::{BasicFloat, Float, FloatConst};
pub use float::{Float, FloatConst};
pub use identities::{Zero, One, zero, one};
pub use ops::checked::*;
pub use ops::wrapping::*;
@ -185,9 +185,9 @@ macro_rules! float_trait_impl {
// Special values
match src {
"inf" => return Ok(BasicFloat::infinity()),
"-inf" => return Ok(BasicFloat::neg_infinity()),
"NaN" => return Ok(BasicFloat::nan()),
"inf" => return Ok(Float::infinity()),
"-inf" => return Ok(Float::neg_infinity()),
"NaN" => return Ok(Float::nan()),
_ => {},
}
@ -228,15 +228,15 @@ macro_rules! float_trait_impl {
// if we've not seen any non-zero digits.
if prev_sig != 0.0 {
if is_positive && sig <= prev_sig
{ return Ok(BasicFloat::infinity()); }
{ return Ok(Float::infinity()); }
if !is_positive && sig >= prev_sig
{ return Ok(BasicFloat::neg_infinity()); }
{ return Ok(Float::neg_infinity()); }
// Detect overflow by reversing the shift-and-add process
if is_positive && (prev_sig != (sig - digit as $t) / radix as $t)
{ return Ok(BasicFloat::infinity()); }
{ return Ok(Float::infinity()); }
if !is_positive && (prev_sig != (sig + digit as $t) / radix as $t)
{ return Ok(BasicFloat::neg_infinity()); }
{ return Ok(Float::neg_infinity()); }
}
prev_sig = sig;
},
@ -272,9 +272,9 @@ macro_rules! float_trait_impl {
};
// Detect overflow by comparing to last value
if is_positive && sig < prev_sig
{ return Ok(BasicFloat::infinity()); }
{ return Ok(Float::infinity()); }
if !is_positive && sig > prev_sig
{ return Ok(BasicFloat::neg_infinity()); }
{ return Ok(Float::neg_infinity()); }
prev_sig = sig;
},
None => match c {
@ -309,8 +309,8 @@ macro_rules! float_trait_impl {
};
match (is_positive, exp) {
(true, Ok(exp)) => BasicFloat::powi(base, exp as i32),
(false, Ok(exp)) => 1.0 / BasicFloat::powi(base, exp as i32),
(true, Ok(exp)) => Float::powi(base, exp as i32),
(false, Ok(exp)) => 1.0 / Float::powi(base, exp as i32),
(_, Err(_)) => return Err(PFE { kind: Invalid }),
}
},

View File

@ -2,7 +2,7 @@ use core::ops::Neg;
use core::{f32, f64};
use core::num::Wrapping;
use Num;
use {Num, Float};
/// Useful functions for signed numbers (i.e. numbers that can be negative).
pub trait Signed: Sized + Num + Neg<Output = Self> {
@ -122,7 +122,7 @@ macro_rules! signed_float_impl {
/// - `NAN` if the number is NaN
#[inline]
fn signum(&self) -> $t {
(*self).signum()
Float::signum(*self)
}
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`