diff options
author | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-04-02 20:01:43 +0000 |
---|---|---|
committer | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-04-02 20:01:43 +0000 |
commit | eaeb3c8450a8c5f185869a0ec8e83f157c61d995 (patch) | |
tree | a7b08056958764ab4b8199564c84c86cbbc506e3 /src/clojure/contrib/test_contrib/complex_numbers.clj | |
parent | b006d0f4e371a16d37d5a8e78982dfb92deadef0 (diff) |
complex-numbers: exp and better sqrt
Diffstat (limited to 'src/clojure/contrib/test_contrib/complex_numbers.clj')
-rw-r--r-- | src/clojure/contrib/test_contrib/complex_numbers.clj | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/clojure/contrib/test_contrib/complex_numbers.clj b/src/clojure/contrib/test_contrib/complex_numbers.clj index b8b03f49..2ac2ff86 100644 --- a/src/clojure/contrib/test_contrib/complex_numbers.clj +++ b/src/clojure/contrib/test_contrib/complex_numbers.clj @@ -1,7 +1,7 @@ ;; Test routines for complex-numbers.clj ;; by Konrad Hinsen -;; last updated March 23, 2009 +;; last updated April 2, 2009 ;; Copyright (c) Konrad Hinsen, 2008. All rights reserved. The use ;; and distribution terms for this software are covered by the Eclipse @@ -20,7 +20,7 @@ [clojure.contrib.generic.comparison :only (= < > <= >=)] [clojure.contrib.generic.math-functions - :only (abs approx= conjugate sqr sqrt)] + :only (abs approx= conjugate exp sqr sqrt)] [clojure.contrib.complex-numbers :only (complex imaginary real imag)])) @@ -279,13 +279,35 @@ (is (= (conjugate (imaginary 5)) (imaginary -5)))) (deftest complex-abs - (doseq [c [(complex 1 2) (complex -3 -7) (imaginary -2) (imaginary 5)]] + (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2) + (complex -3 -7) (imaginary -2) (imaginary 5)]] (is (approx= (* c (conjugate c)) (sqr (abs c)) 1e-14)))) (deftest complex-sqrt - (doseq [c [(complex 1 2) (complex -3 -7) (imaginary -2) (imaginary 5)]] + (doseq [c [(complex 1 2) (complex -2 3) (complex 4 -2) + (complex -3 -7) (imaginary -2) (imaginary 5)]] (let [r (sqrt c)] (is (approx= c (sqr r) 1e-14)) (is (>= (real r) 0))))) + +(deftest complex-exp + (is (approx= (exp (complex 1 2)) + (complex -1.1312043837568135 2.4717266720048188) + 1e-14)) + (is (approx= (exp (complex 2 3)) + (complex -7.3151100949011028 1.0427436562359045) + 1e-14)) + (is (approx= (exp (complex 4 -2)) + (complex -22.720847417619233 -49.645957334580565) + 1e-14)) + (is (approx= (exp (complex 3 -7)) + (complex 15.142531566086868 -13.195928586605717) + 1e-14)) + (is (approx= (exp (imaginary -2)) + (complex -0.41614683654714241 -0.90929742682568171) + 1e-14)) + (is (approx= (exp (imaginary 5)) + (complex 0.2836621854632263 -0.95892427466313845) + 1e-14))) |