[plt-scheme] Test a numbers representation to see if it's complex?

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Jun 4 17:26:52 EDT 2007

How about this `0-imag-part?'?

(define (exact-zero? x)
  (and (exact? x)
       (zero? x)))

(define (0-imag-part? z)
  (exact-zero? (imag-part z)))


Ryan Newton wrote:
> Yes, this is not normally a nice thing to do.  But I have a need to
> distinguish 3.0 and 3.0+0.0i.  As far as I can tell, while PLT *could*
> turn 3.0+0.0i into 3.0, but for whatever reason the complex
> representation seems closed under PLT's arithmetic, which makes what I
> want to do somewhat sane.
> (For reference, I'm embedding a statically typed language in Scheme,
> and I would like to sanity check the object representations
> periodically.)
> -Ryan

Posted on the users mailing list.