diff --git a/src/complex.rs b/src/complex.rs index 79b1cd9..0f2f40d 100644 --- a/src/complex.rs +++ b/src/complex.rs @@ -81,6 +81,22 @@ impl Complex { pub fn norm(&self) -> T { self.re.clone().hypot(self.im.clone()) } + /// Calculate the principal Arg of self. + #[inline] + pub fn arg(&self) -> T { + self.im.clone().atan2(self.re.clone()) + } + /// Convert to polar form (r, theta), such that `self = r * exp(i + /// * theta)` + #[inline] + pub fn to_polar(&self) -> (T, T) { + (self.norm(), self.arg()) + } + /// Convert a polar representation into a complex number. + #[inline] + pub fn from_polar(r: &T, theta: &T) -> Complex { + Complex::new(*r * theta.cos(), *r * theta.sin()) + } /// Computes e^(self), where e is the base of the natural logarithm. #[inline] @@ -153,25 +169,6 @@ impl Complex { } } -impl Complex { - /// Calculate the principal Arg of self. - #[inline] - pub fn arg(&self) -> T { - self.im.clone().atan2(self.re.clone()) - } - /// Convert to polar form (r, theta), such that `self = r * exp(i - /// * theta)` - #[inline] - pub fn to_polar(&self) -> (T, T) { - (self.norm(), self.arg()) - } - /// Convert a polar representation into a complex number. - #[inline] - pub fn from_polar(r: &T, theta: &T) -> Complex { - Complex::new(*r * theta.cos(), *r * theta.sin()) - } -} - macro_rules! forward_val_val_binop { (impl $imp:ident, $method:ident) => { impl $imp> for Complex {