From 8b12e6a6c65ad4c540aaf92584a2e5310b5fe028 Mon Sep 17 00:00:00 2001 From: YakoYakoYokuYoku <39890836+YakoYakoYokuYoku@users.noreply.github.com> Date: Sat, 9 Feb 2019 16:51:02 -0300 Subject: [PATCH] Added real and imaginary parts methods I added them in purpose to match the num-complex crate methods. --- src/float.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/float.rs b/src/float.rs index c91233c..275f85e 100644 --- a/src/float.rs +++ b/src/float.rs @@ -1778,6 +1778,32 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg { /// assert!(abs_difference < 1.0e-10); /// ``` 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 { + 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 { + Self::zero() + } /// Returns the mantissa, base 2 exponent, and sign as integers, respectively. /// The original number can be recovered by `sign * mantissa * 2 ^ exponent`. @@ -1875,6 +1901,8 @@ macro_rules! float_impl { Self::asinh(self) -> Self; Self::acosh(self) -> Self; Self::atanh(self) -> Self; + Self::real(self) -> Self; + Self::imag(self) -> Self; } } };