guile-devel
[Top][All Lists]
Advanced

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

Re: Why 'inexact' and 'exact' doesn't check 'number?' first?


From: Mark H Weaver
Subject: Re: Why 'inexact' and 'exact' doesn't check 'number?' first?
Date: Wed, 12 Dec 2012 01:32:53 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Daniel Hartwig <address@hidden> writes:
> On 12 December 2012 13:55, Nala Ginrut <address@hidden> wrote:
>> Are you suggesting I use (is-a? obj <fraction>) for 'fraction?' ?
>
> Absolutely not.  Use inexact? if you wish to determine that the
> *storage* of a value is using floating point format.

Apologies in advance for being pedantic, but there is no guarantee that
inexact numbers are represented in floating point format.  Having said
that, I'm not aware of any current Scheme implementation that uses a
different representation for inexacts.

Nala Ginrut <address@hidden> writes:
> (define (fraction? obj)
>   (and (number? obj) (inexact? obj)))

This definition implies that 3.1415927 is a fraction, and 1/2 is not.
I suspect you want something closer to this:

  (define (fraction? obj)
    (and (rational? obj)
         (exact? obj)
         (not (integer? obj))))

     Regards,
       Mark



reply via email to

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