[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] rectnum? misdefined in numbers egg?

From: Kon Lovett
Subject: Re: [Chicken-users] rectnum? misdefined in numbers egg?
Date: Tue, 25 Aug 2009 21:02:20 -0700

On Jun 25, 2009, at 12:27 PM, John Cowan wrote:

Normally, a rectnum is understood to be a representation of a non-real
number as two boxes containing arbitrary real numbers, whereas a
compnum uses two unboxed flonums.  However, the numbers egg defines
rectnum? as returning #t if its argument is an exact non-real number.
Consequently, numbers like 1.0+1i are neither rectnums nor compnums.

Thanks for pointing this out. A real problem.

I think rectnum? should be changed to recognize them as rectnums.

Here are portable implementations of bignum?, flonum?, ratnum?, compnum?,
and rectnum?, given only R5RS and fixnum?:

(define (bignum? x) (and (integer? x) (not (fixnum? x))))

(define (flonum? x) (and (real? x) (inexact? x)))

(define (ratnum? x) (and (exact? x) (not (integer? x))))

(define (compnum? x) (and (not (real? x))
    (let ((re (real-part x))
          (im (imag-part x)))
       (and (inexact? re) (inexact? im)))))

(define (rectnum? x) (and (not (real? x)) (not (compnum? x))))

So 1.1+1i is a rectnum?

See numbers-1.808 where:

(define (compnum? x) (and (not (real? x)) (inexact? x)))

(define (rectnum? x) (and (not (real? x))
  (let ((re (real-part x)) (im (imag-part x)))
    (and (or (exact? re) (integer? re))
         (or (exact? im) (integer? im))))))

Also added (cplxnum? X) and (cintnum? X) procs.

The Unicode Standard does not encode            John Cowan
idiosyncratic, personal, novel, or private
use characters, nor does it encode logos
or graphics.                                    address@hidden

Chicken-users mailing list

Note that Chicken converts FP|FX x 0.0/0 -> FP|FX:

(flonum? 3.4+0.0i) ;=> #t
(fixnum? 3+0i) ;=> #t

If a complex number form is read (or programmatically generated, i.e. 'make-polar' & 'make-rectangular') should the programmer expect the result to be a complex number representation?

I guess this is similar to other read/print issues.

Best Wishes,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]