Real: Ignore doc tests if Float is disabled

This commit is contained in:
Yoan Lecoq 2019-02-03 16:51:04 +01:00 committed by Josh Stone
parent aaf3c267bd
commit c28e2fe062
1 changed files with 96 additions and 143 deletions

View File

@ -14,48 +14,45 @@ use Float;
/// 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.
/// ///
/// This trait is only available with the `std` feature, or with the `libm` feature otherwise. /// This trait is always available, however it requires either `std` or `libm`
#[doc(test(attr(cfg(any(feature = "std", feature = "libm")))))] /// in order for `f32` and `f64` to implement it.
pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> { pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// Returns the smallest finite value that this type can represent. /// Returns the smallest finite value that this type can represent.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = Real::min_value(); /// let x: f64 = Real::min_value();
/// ///
/// assert_eq!(x, f64::MIN); /// assert_eq!(x, f64::MIN);
/// # }
/// ``` /// ```
fn min_value() -> Self; fn min_value() -> Self;
/// Returns the smallest positive, normalized value that this type can represent. /// Returns the smallest positive, normalized value that this type can represent.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = Real::min_positive_value(); /// let x: f64 = Real::min_positive_value();
/// ///
/// assert_eq!(x, f64::MIN_POSITIVE); /// assert_eq!(x, f64::MIN_POSITIVE);
/// # }
/// ``` /// ```
fn min_positive_value() -> Self; fn min_positive_value() -> Self;
/// Returns epsilon, a small positive value. /// Returns epsilon, a small positive value.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = Real::epsilon(); /// let x: f64 = Real::epsilon();
/// ///
/// assert_eq!(x, f64::EPSILON); /// assert_eq!(x, f64::EPSILON);
/// # }
/// ``` /// ```
/// ///
/// # Panics /// # Panics
@ -66,21 +63,20 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// Returns the largest finite value that this type can represent. /// Returns the largest finite value that this type can represent.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
/// let x: f64 = Real::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;
/// Returns the largest integer less than or equal to a number. /// Returns the largest integer less than or equal to a number.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let f = 3.99; /// let f = 3.99;
@ -88,14 +84,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert_eq!(f.floor(), 3.0); /// assert_eq!(f.floor(), 3.0);
/// assert_eq!(g.floor(), 3.0); /// assert_eq!(g.floor(), 3.0);
/// # }
/// ``` /// ```
fn floor(self) -> Self; fn floor(self) -> Self;
/// Returns the smallest integer greater than or equal to a number. /// Returns the smallest integer greater than or equal to a number.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let f = 3.01; /// let f = 3.01;
@ -103,15 +98,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert_eq!(f.ceil(), 4.0); /// assert_eq!(f.ceil(), 4.0);
/// assert_eq!(g.ceil(), 4.0); /// assert_eq!(g.ceil(), 4.0);
/// # }
/// ``` /// ```
fn ceil(self) -> Self; fn ceil(self) -> Self;
/// Returns the nearest integer to a number. Round half-way cases away from /// Returns the nearest integer to a number. Round half-way cases away from
/// `0.0`. /// `0.0`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let f = 3.3; /// let f = 3.3;
@ -119,14 +113,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert_eq!(f.round(), 3.0); /// assert_eq!(f.round(), 3.0);
/// assert_eq!(g.round(), -3.0); /// assert_eq!(g.round(), -3.0);
/// # }
/// ``` /// ```
fn round(self) -> Self; fn round(self) -> Self;
/// Return the integer part of a number. /// Return the integer part of a number.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let f = 3.3; /// let f = 3.3;
@ -134,14 +127,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert_eq!(f.trunc(), 3.0); /// assert_eq!(f.trunc(), 3.0);
/// assert_eq!(g.trunc(), -3.0); /// assert_eq!(g.trunc(), -3.0);
/// # }
/// ``` /// ```
fn trunc(self) -> Self; fn trunc(self) -> Self;
/// Returns the fractional part of a number. /// Returns the fractional part of a number.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 3.5; /// let x = 3.5;
@ -151,15 +143,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert!(abs_difference_x < 1e-10); /// assert!(abs_difference_x < 1e-10);
/// assert!(abs_difference_y < 1e-10); /// assert!(abs_difference_y < 1e-10);
/// # }
/// ``` /// ```
fn fract(self) -> Self; fn fract(self) -> Self;
/// Computes the absolute value of `self`. Returns `Float::nan()` if the /// Computes the absolute value of `self`. Returns `Float::nan()` if the
/// number is `Float::nan()`. /// number is `Float::nan()`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -173,7 +164,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// assert!(abs_difference_y < 1e-10); /// assert!(abs_difference_y < 1e-10);
/// ///
/// assert!(::num_traits::Float::is_nan(f64::NAN.abs())); /// assert!(::num_traits::Float::is_nan(f64::NAN.abs()));
/// # }
/// ``` /// ```
fn abs(self) -> Self; fn abs(self) -> Self;
@ -183,8 +173,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()` /// - `-1.0` if the number is negative, `-0.0` or `Float::neg_infinity()`
/// - `Float::nan()` if the number is `Float::nan()` /// - `Float::nan()` if the number is `Float::nan()`
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -194,15 +184,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// assert_eq!(f64::NEG_INFINITY.signum(), -1.0); /// assert_eq!(f64::NEG_INFINITY.signum(), -1.0);
/// ///
/// assert!(f64::NAN.signum().is_nan()); /// assert!(f64::NAN.signum().is_nan());
/// # }
/// ``` /// ```
fn signum(self) -> Self; fn signum(self) -> Self;
/// Returns `true` if `self` is positive, including `+0.0`, /// Returns `true` if `self` is positive, including `+0.0`,
/// `Float::infinity()`, and with newer versions of Rust `f64::NAN`. /// `Float::infinity()`, and with newer versions of Rust `f64::NAN`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -214,15 +203,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// assert!(f.is_sign_positive()); /// assert!(f.is_sign_positive());
/// assert!(!g.is_sign_positive()); /// assert!(!g.is_sign_positive());
/// assert!(!neg_nan.is_sign_positive()); /// assert!(!neg_nan.is_sign_positive());
/// # }
/// ``` /// ```
fn is_sign_positive(self) -> bool; fn is_sign_positive(self) -> bool;
/// Returns `true` if `self` is negative, including `-0.0`, /// Returns `true` if `self` is negative, including `-0.0`,
/// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`. /// `Float::neg_infinity()`, and with newer versions of Rust `-f64::NAN`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -234,7 +222,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// assert!(!f.is_sign_negative()); /// assert!(!f.is_sign_negative());
/// assert!(g.is_sign_negative()); /// assert!(g.is_sign_negative());
/// assert!(!nan.is_sign_negative()); /// assert!(!nan.is_sign_negative());
/// # }
/// ``` /// ```
fn is_sign_negative(self) -> bool; fn is_sign_negative(self) -> bool;
@ -244,8 +231,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// Using `mul_add` can be more performant than an unfused multiply-add if /// Using `mul_add` can be more performant than an unfused multiply-add if
/// the target architecture has a dedicated `fma` CPU instruction. /// the target architecture has a dedicated `fma` CPU instruction.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let m = 10.0; /// let m = 10.0;
@ -256,21 +243,19 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs(); /// let abs_difference = (m.mul_add(x, b) - (m*x + b)).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn mul_add(self, a: Self, b: Self) -> Self; fn mul_add(self, a: Self, b: Self) -> Self;
/// Take the reciprocal (inverse) of a number, `1/x`. /// Take the reciprocal (inverse) of a number, `1/x`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// 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();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn recip(self) -> Self; fn recip(self) -> Self;
@ -278,29 +263,27 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// Using this function is generally faster than using `powf` /// Using this function is generally faster than using `powf`
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// 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();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn powi(self, n: i32) -> Self; fn powi(self, n: i32) -> Self;
/// Raise a number to a real number power. /// Raise a number to a real number power.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// 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();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn powf(self, n: Self) -> Self; fn powf(self, n: Self) -> Self;
@ -312,8 +295,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// If the implementing type doesn't support NaN, this method should panic if `self < 0`. /// If the implementing type doesn't support NaN, this method should panic if `self < 0`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let positive = 4.0; /// let positive = 4.0;
@ -323,14 +306,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// assert!(::num_traits::Float::is_nan(negative.sqrt())); /// assert!(::num_traits::Float::is_nan(negative.sqrt()));
/// # }
/// ``` /// ```
fn sqrt(self) -> Self; fn sqrt(self) -> Self;
/// Returns `e^(self)`, (the exponential function). /// Returns `e^(self)`, (the exponential function).
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let one = 1.0; /// let one = 1.0;
@ -341,14 +323,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (e.ln() - 1.0).abs(); /// let abs_difference = (e.ln() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn exp(self) -> Self; fn exp(self) -> Self;
/// Returns `2^(self)`. /// Returns `2^(self)`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let f = 2.0; /// let f = 2.0;
@ -357,7 +338,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f.exp2() - 4.0).abs(); /// let abs_difference = (f.exp2() - 4.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn exp2(self) -> Self; fn exp2(self) -> Self;
@ -367,8 +347,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// If `self <= 0` and this type does not support a NaN representation, this function should panic. /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let one = 1.0; /// let one = 1.0;
@ -379,7 +359,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (e.ln() - 1.0).abs(); /// let abs_difference = (e.ln() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn ln(self) -> Self; fn ln(self) -> Self;
@ -389,8 +368,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// If `self <= 0` and this type does not support a NaN representation, this function should panic. /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let ten = 10.0; /// let ten = 10.0;
@ -404,7 +383,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert!(abs_difference_10 < 1e-10); /// assert!(abs_difference_10 < 1e-10);
/// assert!(abs_difference_2 < 1e-10); /// assert!(abs_difference_2 < 1e-10);
/// # }
/// ``` /// ```
fn log(self, base: Self) -> Self; fn log(self, base: Self) -> Self;
@ -414,8 +392,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// If `self <= 0` and this type does not support a NaN representation, this function should panic. /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let two = 2.0; /// let two = 2.0;
@ -424,7 +402,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (two.log2() - 1.0).abs(); /// let abs_difference = (two.log2() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn log2(self) -> Self; fn log2(self) -> Self;
@ -435,8 +412,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// If `self <= 0` and this type does not support a NaN representation, this function should panic. /// If `self <= 0` and this type does not support a NaN representation, this function should panic.
/// ///
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let ten = 10.0; /// let ten = 10.0;
@ -445,14 +422,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (ten.log10() - 1.0).abs(); /// let abs_difference = (ten.log10() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn log10(self) -> Self; fn log10(self) -> Self;
/// Converts radians to degrees. /// Converts radians to degrees.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use std::f64::consts; /// use std::f64::consts;
/// ///
/// let angle = consts::PI; /// let angle = consts::PI;
@ -460,14 +436,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (angle.to_degrees() - 180.0).abs(); /// let abs_difference = (angle.to_degrees() - 180.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn to_degrees(self) -> Self; fn to_degrees(self) -> Self;
/// Converts degrees to radians. /// Converts degrees to radians.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use std::f64::consts; /// use std::f64::consts;
/// ///
/// let angle = 180.0_f64; /// let angle = 180.0_f64;
@ -475,35 +450,32 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (angle.to_radians() - consts::PI).abs(); /// let abs_difference = (angle.to_radians() - consts::PI).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn to_radians(self) -> Self; fn to_radians(self) -> Self;
/// Returns the maximum of the two numbers. /// Returns the maximum of the two numbers.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
/// let y = 2.0; /// let y = 2.0;
/// ///
/// assert_eq!(x.max(y), y); /// assert_eq!(x.max(y), y);
/// # }
/// ``` /// ```
fn max(self, other: Self) -> Self; fn max(self, other: Self) -> Self;
/// Returns the minimum of the two numbers. /// Returns the minimum of the two numbers.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
/// let y = 2.0; /// let y = 2.0;
/// ///
/// assert_eq!(x.min(y), x); /// assert_eq!(x.min(y), x);
/// # }
/// ``` /// ```
fn min(self, other: Self) -> Self; fn min(self, other: Self) -> Self;
@ -512,8 +484,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// * If `self <= other`: `0:0` /// * If `self <= other`: `0:0`
/// * Else: `self - other` /// * Else: `self - other`
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 3.0; /// let x = 3.0;
@ -524,14 +496,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert!(abs_difference_x < 1e-10); /// assert!(abs_difference_x < 1e-10);
/// assert!(abs_difference_y < 1e-10); /// assert!(abs_difference_y < 1e-10);
/// # }
/// ``` /// ```
fn abs_sub(self, other: Self) -> Self; fn abs_sub(self, other: Self) -> Self;
/// Take the cubic root of a number. /// Take the cubic root of a number.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 8.0; /// let x = 8.0;
@ -540,15 +511,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.cbrt() - 2.0).abs(); /// let abs_difference = (x.cbrt() - 2.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn cbrt(self) -> Self; fn cbrt(self) -> Self;
/// Calculate the length of the hypotenuse of a right-angle triangle given /// Calculate the length of the hypotenuse of a right-angle triangle given
/// legs of length `x` and `y`. /// legs of length `x` and `y`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 2.0; /// let x = 2.0;
@ -558,14 +528,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs(); /// let abs_difference = (x.hypot(y) - (x.powi(2) + y.powi(2)).sqrt()).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn hypot(self, other: Self) -> Self; fn hypot(self, other: Self) -> Self;
/// Computes the sine of a number (in radians). /// Computes the sine of a number (in radians).
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -574,14 +543,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.sin() - 1.0).abs(); /// let abs_difference = (x.sin() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn sin(self) -> Self; fn sin(self) -> Self;
/// Computes the cosine of a number (in radians). /// Computes the cosine of a number (in radians).
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -590,14 +558,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.cos() - 1.0).abs(); /// let abs_difference = (x.cos() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn cos(self) -> Self; fn cos(self) -> Self;
/// Computes the tangent of a number (in radians). /// Computes the tangent of a number (in radians).
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -605,7 +572,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.tan() - 1.0).abs(); /// let abs_difference = (x.tan() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-14); /// assert!(abs_difference < 1e-14);
/// # }
/// ``` /// ```
fn tan(self) -> Self; fn tan(self) -> Self;
@ -618,8 +584,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// If this type does not support a NaN representation, this function should panic /// If this type does not support a NaN representation, this function should panic
/// if the number is outside the range [-1, 1]. /// if the number is outside the range [-1, 1].
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -629,7 +595,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs(); /// let abs_difference = (f.sin().asin() - f64::consts::PI / 2.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn asin(self) -> Self; fn asin(self) -> Self;
@ -642,8 +607,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// If this type does not support a NaN representation, this function should panic /// If this type does not support a NaN representation, this function should panic
/// if the number is outside the range [-1, 1]. /// if the number is outside the range [-1, 1].
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -653,15 +618,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs(); /// let abs_difference = (f.cos().acos() - f64::consts::PI / 4.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn acos(self) -> Self; fn acos(self) -> Self;
/// Computes the arctangent of a number. Return value is in radians in the /// Computes the arctangent of a number. Return value is in radians in the
/// range [-pi/2, pi/2]; /// range [-pi/2, pi/2];
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let f = 1.0; /// let f = 1.0;
@ -670,7 +634,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f.tan().atan() - 1.0).abs(); /// let abs_difference = (f.tan().atan() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn atan(self) -> Self; fn atan(self) -> Self;
@ -681,8 +644,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]` /// * `y >= 0`: `arctan(y/x) + pi` -> `(pi/2, pi]`
/// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)` /// * `y < 0`: `arctan(y/x) - pi` -> `(-pi, -pi/2)`
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -701,15 +664,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert!(abs_difference_1 < 1e-10); /// assert!(abs_difference_1 < 1e-10);
/// assert!(abs_difference_2 < 1e-10); /// assert!(abs_difference_2 < 1e-10);
/// # }
/// ``` /// ```
fn atan2(self, other: Self) -> Self; fn atan2(self, other: Self) -> Self;
/// Simultaneously computes the sine and cosine of the number, `x`. Returns /// Simultaneously computes the sine and cosine of the number, `x`. Returns
/// `(sin(x), cos(x))`. /// `(sin(x), cos(x))`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -721,15 +683,14 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// assert!(abs_difference_0 < 1e-10); /// assert!(abs_difference_0 < 1e-10);
/// assert!(abs_difference_0 < 1e-10); /// assert!(abs_difference_0 < 1e-10);
/// # }
/// ``` /// ```
fn sin_cos(self) -> (Self, Self); fn sin_cos(self) -> (Self, Self);
/// Returns `e^(self) - 1` in a way that is accurate even if the /// Returns `e^(self) - 1` in a way that is accurate even if the
/// number is close to zero. /// number is close to zero.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 7.0; /// let x = 7.0;
@ -738,7 +699,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.ln().exp_m1() - 6.0).abs(); /// let abs_difference = (x.ln().exp_m1() - 6.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn exp_m1(self) -> Self; fn exp_m1(self) -> Self;
@ -750,8 +710,8 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// If this type does not support a NaN representation, this function should panic /// If this type does not support a NaN representation, this function should panic
/// if `self-1 <= 0`. /// if `self-1 <= 0`.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -761,14 +721,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (x.ln_1p() - 1.0).abs(); /// let abs_difference = (x.ln_1p() - 1.0).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn ln_1p(self) -> Self; fn ln_1p(self) -> Self;
/// Hyperbolic sine function. /// Hyperbolic sine function.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -781,14 +740,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f - g).abs(); /// let abs_difference = (f - g).abs();
/// ///
/// assert!(abs_difference < 1e-10); /// assert!(abs_difference < 1e-10);
/// # }
/// ``` /// ```
fn sinh(self) -> Self; fn sinh(self) -> Self;
/// Hyperbolic cosine function. /// Hyperbolic cosine function.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -801,14 +759,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// ///
/// // Same result /// // Same result
/// assert!(abs_difference < 1.0e-10); /// assert!(abs_difference < 1.0e-10);
/// # }
/// ``` /// ```
fn cosh(self) -> Self; fn cosh(self) -> Self;
/// Hyperbolic tangent function. /// Hyperbolic tangent function.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -821,14 +778,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f - g).abs(); /// let abs_difference = (f - g).abs();
/// ///
/// assert!(abs_difference < 1.0e-10); /// assert!(abs_difference < 1.0e-10);
/// # }
/// ``` /// ```
fn tanh(self) -> Self; fn tanh(self) -> Self;
/// Inverse hyperbolic sine function. /// Inverse hyperbolic sine function.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
@ -837,14 +793,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f - x).abs(); /// let abs_difference = (f - x).abs();
/// ///
/// assert!(abs_difference < 1.0e-10); /// assert!(abs_difference < 1.0e-10);
/// # }
/// ``` /// ```
fn asinh(self) -> Self; fn asinh(self) -> Self;
/// Inverse hyperbolic cosine function. /// Inverse hyperbolic cosine function.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// ///
/// let x = 1.0; /// let x = 1.0;
@ -853,14 +808,13 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f - x).abs(); /// let abs_difference = (f - x).abs();
/// ///
/// assert!(abs_difference < 1.0e-10); /// assert!(abs_difference < 1.0e-10);
/// # }
/// ``` /// ```
fn acosh(self) -> Self; fn acosh(self) -> Self;
/// Inverse hyperbolic tangent function. /// Inverse hyperbolic tangent function.
/// ///
/// ``` #[cfg_attr(any(feature = "std", feature = "libm"), doc="```")]
/// # #[cfg(any(feature = "std", feature = "libm"))] { #[cfg_attr(not(any(feature = "std", feature = "libm")), doc="```ignore")]
/// use num_traits::real::Real; /// use num_traits::real::Real;
/// use std::f64; /// use std::f64;
/// ///
@ -870,7 +824,6 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg<Output = Self> {
/// let abs_difference = (f - e).abs(); /// let abs_difference = (f - e).abs();
/// ///
/// assert!(abs_difference < 1.0e-10); /// assert!(abs_difference < 1.0e-10);
/// # }
/// ``` /// ```
fn atanh(self) -> Self; fn atanh(self) -> Self;
} }