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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Jun 4 18:07:34 EDT 2007

At Mon, 04 Jun 2007 17:03:06 -0500, Chongkai Zhu wrote:
> Yes, my `0-imag-part?' fails for some cases.

Which cases?

> Jens Axel Søgaard wrote:
> >
> > The problem is that 3.0 and 3.0+0.0i is the same number.
> > The real part and the imaginary part shares the exactness.

No, they're different:

 > (eqv? 3.0 3.0+0.0i)
 #f

The imaginary part of a number in MzScheme can be exactly 0, even if
the real part is inexact. That is, PLT Scheme supports inexact numbers
that are exactly real.

Besides Chongkai's test, you could use:

 (define (exactly-real? x)
   (eqv? x (real-part x)))

But Chongkai's test seems fine to me, too, and I'm puzzled by the
suggestion that it isn't. Maybe I've misunderstood the original
request.


FWIW, the real part can also be exactly 0 when the imaginary part is
inexact. The combination of an inexact number and an exact zero is the
only implemented combination exact and inexact parts for complex
numbers. As I recall, special-casing exact 0 simplifies the
implementation of various transcendental functions over complex numbers
(in combination with multiplication by an exact 0 always yielding
exactly 0, etc.).

Matthew



Posted on the users mailing list.