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

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Mon Jun 4 18:03:06 EDT 2007

Yes, my `0-imag-part?' fails for some cases. But you don't need to 
define your own implementation of imaginary numbers.

Using the `SCHEME_COMPLEXP' and `SCHEME_COMPLEX_IZIP' from "inside PLT" 
is enough. So all you need is to write a small MzScheme Extension.

Chongkai


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.
>
> So if you want to distinguish them, you need to defined
> your own implementation of imaginary numbers.
>
>
> > (0-imag-part? (- 3.0+0.5i 0+0.5i))
> #f
>
> > (0-imag-part? #i3.0)
> #t
>
> > (0-imag-part? #i3.5+0.0i)
> #f
>
>
> > (0-imag-part? 3.5+0.0i)
> #f
>
> > (0-imag-part? #i3.5+0.0i)
> #f
>
> > (0-imag-part? #e3.5+0.0i)
> #t
>
>
> /Jens Axel
>



Posted on the users mailing list.