RealNum -> Real

This commit is contained in:
Yoan Lecoq 2018-01-06 15:51:10 +01:00
parent 52c87dd410
commit ddd664ae2b
2 changed files with 54 additions and 54 deletions

View File

@ -18,7 +18,7 @@ use std::num::Wrapping;
pub use bounds::Bounded; pub use bounds::Bounded;
pub use float::{Float, FloatConst}; pub use float::{Float, FloatConst};
// pub use realnum::RealNum; // NOTE: Don't do this, it breaks `use num_traits::*;`. // pub use real::Real; // NOTE: Don't do this, it breaks `use num_traits::*;`.
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::*;
@ -33,7 +33,7 @@ pub mod sign;
pub mod ops; pub mod ops;
pub mod bounds; pub mod bounds;
pub mod float; pub mod float;
pub mod realnum; pub mod real;
pub mod cast; pub mod cast;
pub mod int; pub mod int;
pub mod pow; pub mod pow;

View File

@ -3,14 +3,14 @@ use std::ops::Neg;
use {Num, NumCast, Float}; use {Num, NumCast, Float};
// NOTE: These doctests have the same issue as those in src/float.rs. // NOTE: These doctests have the same issue as those in src/float.rs.
// They're testing the inherent methods directly, and not those of `RealNum`. // They're testing the inherent methods directly, and not those of `Real`.
/// A trait for real number types that do not necessarily have /// A trait for real number types that do not necessarily have
/// floating-point-specific characteristics such as NaN and infinity. /// floating-point-specific characteristics such as NaN and infinity.
/// ///
/// See [this Wikipedia article](https://en.wikipedia.org/wiki/Real_data_type) /// See [this Wikipedia article](https://en.wikipedia.org/wiki/Real_data_type)
/// for a list of data types that could meaningfully implement this trait. /// for a list of data types that could meaningfully implement this trait.
pub trait RealNum pub trait Real
: Num : Num
+ Copy + Copy
+ NumCast + NumCast
@ -20,10 +20,10 @@ pub trait RealNum
/// Returns the smallest finite value that this type can represent. /// Returns the smallest finite value that this type can represent.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = RealNum::min_value(); /// let x: f64 = Real::min_value();
/// ///
/// assert_eq!(x, f64::MIN); /// assert_eq!(x, f64::MIN);
/// ``` /// ```
@ -32,10 +32,10 @@ pub trait RealNum
/// Returns the smallest positive, normalized value that this type can represent. /// Returns the smallest positive, normalized value that this type can represent.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = RealNum::min_positive_value(); /// let x: f64 = Real::min_positive_value();
/// ///
/// assert_eq!(x, f64::MIN_POSITIVE); /// assert_eq!(x, f64::MIN_POSITIVE);
/// ``` /// ```
@ -44,10 +44,10 @@ pub trait RealNum
/// Returns epsilon, a small positive value. /// Returns epsilon, a small positive value.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = RealNum::epsilon(); /// let x: f64 = Real::epsilon();
/// ///
/// assert_eq!(x, f64::EPSILON); /// assert_eq!(x, f64::EPSILON);
/// ``` /// ```
@ -63,10 +63,10 @@ pub trait RealNum
/// Returns the largest finite value that this type can represent. /// Returns the largest finite value that this type can represent.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = RealNum::max_value(); /// let x: f64 = Real::max_value();
/// assert_eq!(x, f64::MAX); /// assert_eq!(x, f64::MAX);
/// ``` /// ```
fn max_value() -> Self; fn max_value() -> Self;
@ -74,7 +74,7 @@ pub trait RealNum
/// Returns the largest integer less than or equal to a number. /// Returns the largest integer less than or equal to a number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let f = 3.99; /// let f = 3.99;
/// let g = 3.0; /// let g = 3.0;
@ -87,7 +87,7 @@ pub trait RealNum
/// Returns the smallest integer greater than or equal to a number. /// Returns the smallest integer greater than or equal to a number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let f = 3.01; /// let f = 3.01;
/// let g = 4.0; /// let g = 4.0;
@ -101,7 +101,7 @@ pub trait RealNum
/// `0.0`. /// `0.0`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let f = 3.3; /// let f = 3.3;
/// let g = -3.3; /// let g = -3.3;
@ -114,7 +114,7 @@ pub trait RealNum
/// Return the integer part of a number. /// Return the integer part of a number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let f = 3.3; /// let f = 3.3;
/// let g = -3.7; /// let g = -3.7;
@ -127,7 +127,7 @@ pub trait RealNum
/// Returns the fractional part of a number. /// Returns the fractional part of a number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 3.5; /// let x = 3.5;
/// let y = -3.5; /// let y = -3.5;
@ -143,7 +143,7 @@ pub trait RealNum
/// number is `Float::nan()`. /// number is `Float::nan()`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x = 3.5; /// let x = 3.5;
@ -166,7 +166,7 @@ pub trait RealNum
/// - `Float::nan()` if the number is `Float::nan()` /// - `Float::nan()` if the number is `Float::nan()`
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let f = 3.5; /// let f = 3.5;
@ -182,7 +182,7 @@ pub trait RealNum
/// `Float::infinity()`, and with newer versions of Rust `f64::NAN`. /// `Float::infinity()`, and with newer versions of Rust `f64::NAN`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let neg_nan: f64 = -f64::NAN; /// let neg_nan: f64 = -f64::NAN;
@ -200,7 +200,7 @@ pub trait RealNum
/// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`. /// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let nan: f64 = f64::NAN; /// let nan: f64 = f64::NAN;
@ -219,7 +219,7 @@ pub trait RealNum
/// a separate multiplication operation followed by an add. /// a separate multiplication operation followed by an add.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let m = 10.0; /// let m = 10.0;
/// let x = 4.0; /// let x = 4.0;
@ -235,7 +235,7 @@ pub trait RealNum
/// Take the reciprocal (inverse) of a number, `1/x`. /// Take the reciprocal (inverse) of a number, `1/x`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 2.0; /// let x = 2.0;
/// let abs_difference = (x.recip() - (1.0/x)).abs(); /// let abs_difference = (x.recip() - (1.0/x)).abs();
@ -249,7 +249,7 @@ pub trait RealNum
/// Using this function is generally faster than using `powf` /// Using this function is generally faster than using `powf`
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 2.0; /// let x = 2.0;
/// let abs_difference = (x.powi(2) - x*x).abs(); /// let abs_difference = (x.powi(2) - x*x).abs();
@ -261,7 +261,7 @@ pub trait RealNum
/// Raise a number to a real number power. /// Raise a number to a real number power.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 2.0; /// let x = 2.0;
/// let abs_difference = (x.powf(2.0) - x*x).abs(); /// let abs_difference = (x.powf(2.0) - x*x).abs();
@ -276,7 +276,7 @@ pub trait RealNum
/// If `self` is negative, but not floating-point, the implementation may panic. /// If `self` is negative, but not floating-point, the implementation may panic.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let positive = 4.0; /// let positive = 4.0;
/// let negative = -4.0; /// let negative = -4.0;
@ -291,7 +291,7 @@ pub trait RealNum
/// Returns `e^(self)`, (the exponential function). /// Returns `e^(self)`, (the exponential function).
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let one = 1.0; /// let one = 1.0;
/// // e^1 /// // e^1
@ -307,7 +307,7 @@ pub trait RealNum
/// Returns `2^(self)`. /// Returns `2^(self)`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let f = 2.0; /// let f = 2.0;
/// ///
@ -321,7 +321,7 @@ pub trait RealNum
/// Returns the natural logarithm of the number. /// Returns the natural logarithm of the number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let one = 1.0; /// let one = 1.0;
/// // e^1 /// // e^1
@ -337,7 +337,7 @@ pub trait RealNum
/// Returns the logarithm of the number with respect to an arbitrary base. /// Returns the logarithm of the number with respect to an arbitrary base.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let ten = 10.0; /// let ten = 10.0;
/// let two = 2.0; /// let two = 2.0;
@ -356,7 +356,7 @@ pub trait RealNum
/// Returns the base 2 logarithm of the number. /// Returns the base 2 logarithm of the number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let two = 2.0; /// let two = 2.0;
/// ///
@ -370,7 +370,7 @@ pub trait RealNum
/// Returns the base 10 logarithm of the number. /// Returns the base 10 logarithm of the number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let ten = 10.0; /// let ten = 10.0;
/// ///
@ -420,7 +420,7 @@ pub trait RealNum
/// Returns the maximum of the two numbers. /// Returns the maximum of the two numbers.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
/// let y = 2.0; /// let y = 2.0;
@ -432,7 +432,7 @@ pub trait RealNum
/// Returns the minimum of the two numbers. /// Returns the minimum of the two numbers.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
/// let y = 2.0; /// let y = 2.0;
@ -447,7 +447,7 @@ pub trait RealNum
/// * Else: `self - other` /// * Else: `self - other`
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 3.0; /// let x = 3.0;
/// let y = -3.0; /// let y = -3.0;
@ -463,7 +463,7 @@ pub trait RealNum
/// Take the cubic root of a number. /// Take the cubic root of a number.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 8.0; /// let x = 8.0;
/// ///
@ -478,7 +478,7 @@ pub trait RealNum
/// legs of length `x` and `y`. /// legs of length `x` and `y`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 2.0; /// let x = 2.0;
/// let y = 3.0; /// let y = 3.0;
@ -493,7 +493,7 @@ pub trait RealNum
/// Computes the sine of a number (in radians). /// Computes the sine of a number (in radians).
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x = f64::consts::PI/2.0; /// let x = f64::consts::PI/2.0;
@ -507,7 +507,7 @@ pub trait RealNum
/// Computes the cosine of a number (in radians). /// Computes the cosine of a number (in radians).
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x = 2.0*f64::consts::PI; /// let x = 2.0*f64::consts::PI;
@ -521,7 +521,7 @@ pub trait RealNum
/// Computes the tangent of a number (in radians). /// Computes the tangent of a number (in radians).
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x = f64::consts::PI/4.0; /// let x = f64::consts::PI/4.0;
@ -536,7 +536,7 @@ pub trait RealNum
/// [-1, 1]. /// [-1, 1].
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let f = f64::consts::PI / 2.0; /// let f = f64::consts::PI / 2.0;
@ -553,7 +553,7 @@ pub trait RealNum
/// [-1, 1]. /// [-1, 1].
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let f = f64::consts::PI / 4.0; /// let f = f64::consts::PI / 4.0;
@ -569,7 +569,7 @@ pub trait RealNum
/// range [-pi/2, pi/2]; /// range [-pi/2, pi/2];
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let f = 1.0; /// let f = 1.0;
/// ///
@ -588,7 +588,7 @@ pub trait RealNum
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let pi = f64::consts::PI; /// let pi = f64::consts::PI;
@ -613,7 +613,7 @@ pub trait RealNum
/// `(sin(x), cos(x))`. /// `(sin(x), cos(x))`.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x = f64::consts::PI/4.0; /// let x = f64::consts::PI/4.0;
@ -631,7 +631,7 @@ pub trait RealNum
/// number is close to zero. /// number is close to zero.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 7.0; /// let x = 7.0;
/// ///
@ -646,7 +646,7 @@ pub trait RealNum
/// the operations were performed separately. /// the operations were performed separately.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x = f64::consts::E - 1.0; /// let x = f64::consts::E - 1.0;
@ -661,7 +661,7 @@ pub trait RealNum
/// Hyperbolic sine function. /// Hyperbolic sine function.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let e = f64::consts::E; /// let e = f64::consts::E;
@ -679,7 +679,7 @@ pub trait RealNum
/// Hyperbolic cosine function. /// Hyperbolic cosine function.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let e = f64::consts::E; /// let e = f64::consts::E;
@ -697,7 +697,7 @@ pub trait RealNum
/// Hyperbolic tangent function. /// Hyperbolic tangent function.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let e = f64::consts::E; /// let e = f64::consts::E;
@ -715,7 +715,7 @@ pub trait RealNum
/// Inverse hyperbolic sine function. /// Inverse hyperbolic sine function.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
/// let f = x.sinh().asinh(); /// let f = x.sinh().asinh();
@ -729,7 +729,7 @@ pub trait RealNum
/// Inverse hyperbolic cosine function. /// Inverse hyperbolic cosine function.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
/// let f = x.cosh().acosh(); /// let f = x.cosh().acosh();
@ -743,7 +743,7 @@ pub trait RealNum
/// Inverse hyperbolic tangent function. /// Inverse hyperbolic tangent function.
/// ///
/// ``` /// ```
/// use num_traits::realnum::RealNum; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let e = f64::consts::E; /// let e = f64::consts::E;
@ -756,7 +756,7 @@ pub trait RealNum
fn atanh(self) -> Self; fn atanh(self) -> Self;
} }
impl<T: Float> RealNum for T { impl<T: Float> Real for T {
fn min_value() -> Self { fn min_value() -> Self {
Self::min_value() Self::min_value()
} }