use num::{Bounded, Signed};
use std::{f32, f64};
use approx::{RelativeEq, UlpsEq};
use crate::general::{ComplexField, Lattice};
#[cfg(not(feature = "std"))]
use num::Float;
#[allow(missing_docs)]
pub trait RealField:
ComplexField<RealField = Self>
+ RelativeEq<Epsilon = Self>
+ UlpsEq<Epsilon = Self>
+ Lattice
+ Signed
+ Bounded
{
fn is_sign_positive(self) -> bool;
fn is_sign_negative(self) -> bool;
fn max(self, other: Self) -> Self;
fn min(self, other: Self) -> Self;
fn atan2(self, other: Self) -> Self;
fn pi() -> Self;
fn two_pi() -> Self;
fn frac_pi_2() -> Self;
fn frac_pi_3() -> Self;
fn frac_pi_4() -> Self;
fn frac_pi_6() -> Self;
fn frac_pi_8() -> Self;
fn frac_1_pi() -> Self;
fn frac_2_pi() -> Self;
fn frac_2_sqrt_pi() -> Self;
fn e() -> Self;
fn log2_e() -> Self;
fn log10_e() -> Self;
fn ln_2() -> Self;
fn ln_10() -> Self;
}
macro_rules! impl_real(
($($T:ty, $M:ident, $libm: ident);*) => ($(
impl RealField for $T {
#[inline]
fn is_sign_positive(self) -> bool {
$M::is_sign_positive(self)
}
#[inline]
fn is_sign_negative(self) -> bool {
$M::is_sign_negative(self)
}
#[inline]
fn max(self, other: Self) -> Self {
$M::max(self, other)
}
#[inline]
fn min(self, other: Self) -> Self {
$M::min(self, other)
}
#[inline]
fn atan2(self, other: Self) -> Self {
$libm::atan2(self, other)
}
#[inline]
fn pi() -> Self {
$M::consts::PI
}
#[inline]
fn two_pi() -> Self {
$M::consts::PI + $M::consts::PI
}
#[inline]
fn frac_pi_2() -> Self {
$M::consts::FRAC_PI_2
}
#[inline]
fn frac_pi_3() -> Self {
$M::consts::FRAC_PI_3
}
#[inline]
fn frac_pi_4() -> Self {
$M::consts::FRAC_PI_4
}
#[inline]
fn frac_pi_6() -> Self {
$M::consts::FRAC_PI_6
}
#[inline]
fn frac_pi_8() -> Self {
$M::consts::FRAC_PI_8
}
#[inline]
fn frac_1_pi() -> Self {
$M::consts::FRAC_1_PI
}
#[inline]
fn frac_2_pi() -> Self {
$M::consts::FRAC_2_PI
}
#[inline]
fn frac_2_sqrt_pi() -> Self {
$M::consts::FRAC_2_SQRT_PI
}
#[inline]
fn e() -> Self {
$M::consts::E
}
#[inline]
fn log2_e() -> Self {
$M::consts::LOG2_E
}
#[inline]
fn log10_e() -> Self {
$M::consts::LOG10_E
}
#[inline]
fn ln_2() -> Self {
$M::consts::LN_2
}
#[inline]
fn ln_10() -> Self {
$M::consts::LN_10
}
}
)*)
);
#[cfg(not(feature = "std"))]
impl_real!(f32,f32,Float; f64,f64,Float);
#[cfg(feature = "std")]
impl_real!(f32,f32,f32; f64,f64,f64);