浏览代码

Merge branch 'master' into develop

Conflicts:
	src/complex.rs
William Rieger 9 年之前
父节点
当前提交
50d89519a2
共有 1 个文件被更改,包括 16 次插入19 次删除
  1. 16 19
      src/complex.rs

+ 16 - 19
src/complex.rs

@@ -81,6 +81,22 @@ impl<T: Clone + Float> Complex<T> {
     pub fn norm(&self) -> T {
     pub fn norm(&self) -> T {
         self.re.clone().hypot(self.im.clone())
         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<T> {
+        Complex::new(*r * theta.cos(), *r * theta.sin())
+    }
 
 
     /// Computes e^(self), where e is the base of the natural logarithm.
     /// Computes e^(self), where e is the base of the natural logarithm.
     #[inline]
     #[inline]
@@ -153,25 +169,6 @@ impl<T: Clone + Float> Complex<T> {
     }
     }
 }
 }
 
 
-impl<T: Clone + Float + Num> Complex<T> {
-    /// 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<T> {
-        Complex::new(*r * theta.cos(), *r * theta.sin())
-    }
-}
-
 macro_rules! forward_val_val_binop {
 macro_rules! forward_val_val_binop {
     (impl $imp:ident, $method:ident) => {
     (impl $imp:ident, $method:ident) => {
         impl<T: Clone + Num> $imp<Complex<T>> for Complex<T> {
         impl<T: Clone + Num> $imp<Complex<T>> for Complex<T> {