summary refs log tree commit diff stats
diff options
context:
space:
mode:
authordef <dennis@felsin9.de>2014-07-14 14:44:58 +0200
committerdef <dennis@felsin9.de>2014-07-14 14:44:58 +0200
commitb1a494e8b917750f92cb41692fa550e37243a22c (patch)
treee8446ec6acd5959c067de9f6ea55e878cf8c2ac3
parentc260b22fbca0e8a3be903c1c6db2027cfcf1c7f2 (diff)
downloadNim-b1a494e8b917750f92cb41692fa550e37243a22c.tar.gz
Add missing complex arithmetic procs
-rw-r--r--lib/pure/complex.nim39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/pure/complex.nim b/lib/pure/complex.nim
index df08ace72..1392b73aa 100644
--- a/lib/pure/complex.nim
+++ b/lib/pure/complex.nim
@@ -113,6 +113,45 @@ proc `*` *(x: TComplex, y: float): TComplex =
   result.im = x.im * y
 
 
+proc `+=` *(x: var TComplex, y: TComplex) =
+  ## Add `y` to `x`.
+  x.re += y.re
+  x.im += y.im
+
+proc `+=` *(x: var TComplex, y: float) =
+  ## Add `y` to the complex number `x`.
+  x.re += y
+
+proc `-=` *(x: var TComplex, y: TComplex) =
+  ## Subtract `y` from `x`.
+  x.re -= y.re
+  x.im -= y.im
+
+proc `-=` *(x: var TComplex, y: float) =
+  ## Subtract `y` from the complex number `x`.
+  x.re -= y
+
+proc `*=` *(x: var TComplex, y: TComplex) =
+  ## Multiply `y` to `x`.
+  let im = x.im * y.re + x.re * y.im
+  x.re = x.re * y.re - x.im * y.im
+  x.im = im
+
+proc `*=` *(x: var TComplex, y: float) =
+  ## Multiply `y` to the complex number `x`.
+  x.re *= y
+  x.im *= y
+
+proc `/=` *(x: var TComplex, y: TComplex) =
+  ## Divide `x` by `y` in place.
+  x = x / y
+
+proc `/=` *(x : var TComplex, y: float) =
+  ## Divide complex `x` by float `y` in place.
+  x.re /= y
+  x.im /= y
+
+
 proc abs*(z: TComplex): float =
   ## Return the distance from (0,0) to `z`.