Update float.rs
This commit is contained in:
parent
dcf51dd9a0
commit
66bd294256
|
@ -1905,9 +1905,6 @@ pub trait CommonFloat where Self: Num + Copy + NumCast + Neg<Output = Self> {
|
||||||
/// Take the reciprocal (inverse) of a number, `1/x`.
|
/// Take the reciprocal (inverse) of a number, `1/x`.
|
||||||
fn recip(self) -> Self;
|
fn recip(self) -> Self;
|
||||||
|
|
||||||
/// Raise a number to a floating point power.
|
|
||||||
fn powf(self, n: Self) -> Self;
|
|
||||||
|
|
||||||
/// Takes self to the power of a.
|
/// Takes self to the power of a.
|
||||||
///
|
///
|
||||||
/// Returns NaN if self is negative.
|
/// Returns NaN if self is negative.
|
||||||
|
@ -2078,7 +2075,6 @@ macro_rules! cfloat_impl {
|
||||||
Float::is_nan(self) -> bool;
|
Float::is_nan(self) -> bool;
|
||||||
Float::mul_add(self, a: Self, b: Self) -> Self;
|
Float::mul_add(self, a: Self, b: Self) -> Self;
|
||||||
Float::recip(self) -> Self;
|
Float::recip(self) -> Self;
|
||||||
Float::powf(self, n: Self) -> Self;
|
|
||||||
Float::sqrt(self) -> Self;
|
Float::sqrt(self) -> Self;
|
||||||
Float::exp(self) -> Self;
|
Float::exp(self) -> Self;
|
||||||
Float::exp2(self) -> Self;
|
Float::exp2(self) -> Self;
|
||||||
|
|
|
@ -29,6 +29,7 @@ pub use bounds::Bounded;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use float::Float;
|
pub use float::Float;
|
||||||
pub use float::FloatConst;
|
pub use float::FloatConst;
|
||||||
|
pub use float::CommonFloat;
|
||||||
// pub use real::{FloatCore, Real}; // NOTE: Don't do this, it breaks `use num_traits::*;`.
|
// pub use real::{FloatCore, Real}; // NOTE: Don't do this, it breaks `use num_traits::*;`.
|
||||||
pub use cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive};
|
pub use cast::{cast, AsPrimitive, FromPrimitive, NumCast, ToPrimitive};
|
||||||
pub use identities::{one, zero, One, Zero};
|
pub use identities::{one, zero, One, Zero};
|
||||||
|
|
53
src/real.rs
53
src/real.rs
|
@ -13,7 +13,6 @@ use {Float, Num, NumCast};
|
||||||
///
|
///
|
||||||
/// This trait is only available with the `std` feature.
|
/// This trait is only available with the `std` feature.
|
||||||
pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
|
pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
|
||||||
type Typo;
|
|
||||||
/// Returns the smallest finite value that this type can represent.
|
/// Returns the smallest finite value that this type can represent.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -776,61 +775,9 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
|
||||||
/// assert!(abs_difference < 1.0e-10);
|
/// assert!(abs_difference < 1.0e-10);
|
||||||
/// ```
|
/// ```
|
||||||
fn atanh(self) -> Self;
|
fn atanh(self) -> Self;
|
||||||
|
|
||||||
/// Returns the real part of the float.
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use num_traits::Float;
|
|
||||||
///
|
|
||||||
/// let n = 0.5f64;
|
|
||||||
///
|
|
||||||
/// assert!(n.real() > 0.4f64);
|
|
||||||
/// ```
|
|
||||||
fn real(self) -> Self;
|
|
||||||
|
|
||||||
/// Returns the imaginary part of the float which equals to zero.
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use num_traits::Float;
|
|
||||||
///
|
|
||||||
/// let n = 2.7f64;
|
|
||||||
///
|
|
||||||
/// assert!(n.imag() == 0.0f64);
|
|
||||||
/// ```
|
|
||||||
fn imag(self) -> Self;
|
|
||||||
|
|
||||||
/// Computes the argument of the float.Float
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use num_traits::Float;
|
|
||||||
///
|
|
||||||
/// let n = 0.8f32;
|
|
||||||
///
|
|
||||||
/// assert_eq!(n.arg(), 0.0f32);
|
|
||||||
/// ```
|
|
||||||
fn arg(self) -> Self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Float + PartialOrd> Real for T {
|
impl<T: Float + PartialOrd> Real for T {
|
||||||
type Typo = T;
|
|
||||||
#[inline]
|
|
||||||
fn real(self) -> T {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
#[inline]
|
|
||||||
fn imag(self) -> T {
|
|
||||||
T::neg_zero()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn arg(self) -> Self::Typo {
|
|
||||||
if self >= T::from(0).unwrap() {
|
|
||||||
T::from(0).unwrap()
|
|
||||||
} else {
|
|
||||||
T::from(3.14159265358979323846264338327950288_f64).unwrap()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
forward! {
|
forward! {
|
||||||
Float::min_value() -> Self;
|
Float::min_value() -> Self;
|
||||||
Float::min_positive_value() -> Self;
|
Float::min_positive_value() -> Self;
|
||||||
|
|
Loading…
Reference in New Issue