Yes, but in (some versions of) Scheme, (sqrt -1) yields i.

Representing complex numbers and just doing math between two complex
numbers is not the problem.  Retrofitting Clojure math so that all
operations work on the entire numeric tower, allowing you to
seamlessly manipulate complex and non-complex numbers together, is
non-trivial.

On Mon, Jun 7, 2010 at 12:09 AM, Steven Devijver
<steven.devij...@gmail.com> wrote:
> For what it's worth, I found that working with complex numbers in
> clojure doesn't require specialist types or notation at all:
>
> (defn complex-times [[a_re a_im] [b_re b_im]] [(- (* a_re b_re) (*
> a_im b_im)) (+ (* a_re b_im) (* a_im b_re))])
> (defn complex-plus  [[a_re a_im] [b_re b_im]] [(+ a_re b_re) (+ a_im
> b_im)])
> (defn complex-minus [[a_re a_im] [b_re b_im]] [(- a_re b_re) (- a_im
> b_im)])
> (defn complex-abs [[re im]] (Math/hypot re im))
>
> (prn (complex-abs (complex-plus [1.5 1] (complex-times [1 -2] [2
> -1]))))
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to