diff --git a/src/float.rs b/src/float.rs index 3094dd4..185a346 100644 --- a/src/float.rs +++ b/src/float.rs @@ -1836,6 +1836,52 @@ pub trait Float where Self: Num + Copy + NumCast + Neg { /// assert!(abs_difference < 1e-10); /// ``` fn integer_decode(self) -> (u64, i16, i8); + + /// Returns the real part of the float. + /// + /// ``` + /// use num_traits::Float; + /// + /// let n = 0.5f64; + /// + /// assert!(n.real() > 0.4f64); + /// ``` + #[inline] + fn real(self) -> 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); + /// ``` + #[inline] + fn imag(self) -> Self { + Self::zero() + } + + /// Computes the argument of the float + /// + /// ``` + /// use num_traits::Float; + /// + /// let r = 0.8f64; + /// + /// assert_eq!(r.arg(), 0.0f64); + /// ``` + #[inline] + fn arg(self) -> Self { + if self >= Self::zero() { + Self::zero() + } else { + Self::from(f64::consts::PI).unwrap() + } + } } #[cfg(feature = "std")] diff --git a/src/real.rs b/src/real.rs index f891d0f..e66cc3b 100644 --- a/src/real.rs +++ b/src/real.rs @@ -786,7 +786,11 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg { /// /// assert!(n.real() > 0.4f64); /// ``` +<<<<<<< HEAD fn real(self) -> Self::Typo; +======= + fn real(self) -> Self; +>>>>>>> e2ea775447e536007f4f4cac3d90d02f294d16c0 /// Returns the imaginary part of the float which equals to zero. /// @@ -797,7 +801,11 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg { /// /// assert!(n.imag() == 0.0f64); /// ``` +<<<<<<< HEAD fn imag(self) -> Self::Typo; +======= + fn imag(self) -> Self; +>>>>>>> e2ea775447e536007f4f4cac3d90d02f294d16c0 /// Computes the argument of the float.Float /// @@ -808,7 +816,11 @@ pub trait Real: Num + Copy + NumCast + PartialOrd + Neg { /// /// assert_eq!(n.arg(), 0.0f32); /// ``` +<<<<<<< HEAD fn arg(self) -> Self::Typo; +======= + fn arg(self) -> Self; +>>>>>>> e2ea775447e536007f4f4cac3d90d02f294d16c0 } impl Real for T { @@ -881,5 +893,8 @@ impl Real for T { Float::asinh(self) -> Self; Float::acosh(self) -> Self; Float::atanh(self) -> Self; + Float::real(self) -> Self; + Float::imag(self) -> Self; + Float::arg(self) -> Self; } }