From 37741f28fdae14201fb6c087ae93eb9ba2586823 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 7 Jan 2011 00:32:15 +0100 Subject: [PATCH] additions to complex module --- lib/pure/complex.nim | 211 +++++++++++++++++++++++++++++++++++++++++-- todo.txt | 1 - web/news.txt | 1 + 3 files changed, 206 insertions(+), 7 deletions(-) diff --git a/lib/pure/complex.nim b/lib/pure/complex.nim index c06451ca8c..df08ace723 100755 --- a/lib/pure/complex.nim +++ b/lib/pure/complex.nim @@ -10,36 +10,66 @@ ## This module implements complex numbers. - {.push checks:off, line_dir:off, stack_trace:off, debugger:off.} # the user does not want to trace a part # of the standard library! + import math + +const + EPS = 5.0e-6 ## Epsilon used for float comparisons (should be smaller + ## if float is really float64, but w/ the current version + ## it seems to be float32?) + type - TComplex* = tuple[re, im: float] + TComplex* = tuple[re, im: float] ## a complex number, consisting of a real and an imaginary part proc `==` *(x, y: TComplex): bool = ## Compare two complex numbers `x` and `y` for equality. result = x.re == y.re and x.im == y.im +proc `=~` *(x, y: TComplex): bool = + ## Compare two complex numbers `x` and `y` approximately. + result = abs(x.re-y.re)