From 88029f5786f7c0e924774c872821259c6d26660b Mon Sep 17 00:00:00 2001 From: YakoYakoYokuYoku <39890836+YakoYakoYokuYoku@users.noreply.github.com> Date: Mon, 11 Feb 2019 15:35:35 -0300 Subject: [PATCH 1/3] Update float.rs --- src/float.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/float.rs b/src/float.rs index c91233c..e767893 100644 --- a/src/float.rs +++ b/src/float.rs @@ -1799,6 +1799,52 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + 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) + } + } } #[cfg(feature = "std")] From f06b736e02b7de243097f8fbc9f7045bdcb78ac0 Mon Sep 17 00:00:00 2001 From: YakoYakoYokuYoku <39890836+YakoYakoYokuYoku@users.noreply.github.com> Date: Mon, 11 Feb 2019 16:19:54 -0300 Subject: [PATCH 2/3] Fixed float.rs --- src/float.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/float.rs b/src/float.rs index e767893..16ffb93 100644 --- a/src/float.rs +++ b/src/float.rs @@ -1842,7 +1842,7 @@ pub trait Float: Num + Copy + NumCast + PartialOrd + Neg { if self >= Self::zero() { Self::zero() } else { - Self::from(f64::consts::PI) + Self::from(f64::consts::PI).unwrap() } } } From e2ea775447e536007f4f4cac3d90d02f294d16c0 Mon Sep 17 00:00:00 2001 From: YakoYakoYokuYoku <39890836+YakoYakoYokuYoku@users.noreply.github.com> Date: Mon, 11 Feb 2019 16:29:34 -0300 Subject: [PATCH 3/3] Adding more methods to real.rs --- src/real.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/real.rs b/src/real.rs index 23ac6b8..138c7f7 100644 --- a/src/real.rs +++ b/src/real.rs @@ -775,6 +775,39 @@ pub trait Real: 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; + + /// 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; + + /// Computes the argument of the float.Float + /// + /// ``` + /// use num_traits::Float; + /// + /// let n = 0.8f32; + /// + /// assert_eq!(n.arg(), 0.0f32); + /// ``` + fn arg(self) -> Self; } impl Real for T { @@ -828,5 +861,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; } }