Mark methods in `Float` whether they require `std`
This removes the `BasicFloat` trait.
This commit is contained in:
parent
351dfc6383
commit
6253669ef4
|
@ -3,7 +3,7 @@ use core::num::Wrapping;
|
||||||
|
|
||||||
use identities::Zero;
|
use identities::Zero;
|
||||||
use bounds::Bounded;
|
use bounds::Bounded;
|
||||||
use float::BasicFloat;
|
use float::Float;
|
||||||
|
|
||||||
/// A generic trait for converting a value to a number.
|
/// A generic trait for converting a value to a number.
|
||||||
pub trait ToPrimitive {
|
pub trait ToPrimitive {
|
||||||
|
@ -228,7 +228,7 @@ macro_rules! impl_to_primitive_float_to_float {
|
||||||
// NaN and +-inf are cast as they are.
|
// NaN and +-inf are cast as they are.
|
||||||
let n = $slf as f64;
|
let n = $slf as f64;
|
||||||
let max_value: $DstT = ::core::$DstT::MAX;
|
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)
|
Some($slf as $DstT)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -23,7 +23,7 @@ use core::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
|
||||||
use core::num::Wrapping;
|
use core::num::Wrapping;
|
||||||
|
|
||||||
pub use bounds::Bounded;
|
pub use bounds::Bounded;
|
||||||
pub use float::{BasicFloat, Float, FloatConst};
|
pub use float::{Float, FloatConst};
|
||||||
pub use identities::{Zero, One, zero, one};
|
pub use identities::{Zero, One, zero, one};
|
||||||
pub use ops::checked::*;
|
pub use ops::checked::*;
|
||||||
pub use ops::wrapping::*;
|
pub use ops::wrapping::*;
|
||||||
|
@ -185,9 +185,9 @@ macro_rules! float_trait_impl {
|
||||||
|
|
||||||
// Special values
|
// Special values
|
||||||
match src {
|
match src {
|
||||||
"inf" => return Ok(BasicFloat::infinity()),
|
"inf" => return Ok(Float::infinity()),
|
||||||
"-inf" => return Ok(BasicFloat::neg_infinity()),
|
"-inf" => return Ok(Float::neg_infinity()),
|
||||||
"NaN" => return Ok(BasicFloat::nan()),
|
"NaN" => return Ok(Float::nan()),
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,15 +228,15 @@ macro_rules! float_trait_impl {
|
||||||
// if we've not seen any non-zero digits.
|
// if we've not seen any non-zero digits.
|
||||||
if prev_sig != 0.0 {
|
if prev_sig != 0.0 {
|
||||||
if is_positive && sig <= prev_sig
|
if is_positive && sig <= prev_sig
|
||||||
{ return Ok(BasicFloat::infinity()); }
|
{ return Ok(Float::infinity()); }
|
||||||
if !is_positive && sig >= prev_sig
|
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
|
// Detect overflow by reversing the shift-and-add process
|
||||||
if is_positive && (prev_sig != (sig - digit as $t) / radix as $t)
|
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)
|
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;
|
prev_sig = sig;
|
||||||
},
|
},
|
||||||
|
@ -272,9 +272,9 @@ macro_rules! float_trait_impl {
|
||||||
};
|
};
|
||||||
// Detect overflow by comparing to last value
|
// Detect overflow by comparing to last value
|
||||||
if is_positive && sig < prev_sig
|
if is_positive && sig < prev_sig
|
||||||
{ return Ok(BasicFloat::infinity()); }
|
{ return Ok(Float::infinity()); }
|
||||||
if !is_positive && sig > prev_sig
|
if !is_positive && sig > prev_sig
|
||||||
{ return Ok(BasicFloat::neg_infinity()); }
|
{ return Ok(Float::neg_infinity()); }
|
||||||
prev_sig = sig;
|
prev_sig = sig;
|
||||||
},
|
},
|
||||||
None => match c {
|
None => match c {
|
||||||
|
@ -309,8 +309,8 @@ macro_rules! float_trait_impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
match (is_positive, exp) {
|
match (is_positive, exp) {
|
||||||
(true, Ok(exp)) => BasicFloat::powi(base, exp as i32),
|
(true, Ok(exp)) => Float::powi(base, exp as i32),
|
||||||
(false, Ok(exp)) => 1.0 / BasicFloat::powi(base, exp as i32),
|
(false, Ok(exp)) => 1.0 / Float::powi(base, exp as i32),
|
||||||
(_, Err(_)) => return Err(PFE { kind: Invalid }),
|
(_, Err(_)) => return Err(PFE { kind: Invalid }),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,7 +2,7 @@ use core::ops::Neg;
|
||||||
use core::{f32, f64};
|
use core::{f32, f64};
|
||||||
use core::num::Wrapping;
|
use core::num::Wrapping;
|
||||||
|
|
||||||
use Num;
|
use {Num, Float};
|
||||||
|
|
||||||
/// Useful functions for signed numbers (i.e. numbers that can be negative).
|
/// Useful functions for signed numbers (i.e. numbers that can be negative).
|
||||||
pub trait Signed: Sized + Num + Neg<Output = Self> {
|
pub trait Signed: Sized + Num + Neg<Output = Self> {
|
||||||
|
@ -122,7 +122,7 @@ macro_rules! signed_float_impl {
|
||||||
/// - `NAN` if the number is NaN
|
/// - `NAN` if the number is NaN
|
||||||
#[inline]
|
#[inline]
|
||||||
fn signum(&self) -> $t {
|
fn signum(&self) -> $t {
|
||||||
(*self).signum()
|
Float::signum(*self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
|
/// Returns `true` if the number is positive, including `+0.0` and `INFINITY`
|
||||||
|
|
Loading…
Reference in New Issue