chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] IEEE float arithmetic


From: John Cowan
Subject: Re: [Chicken-users] IEEE float arithmetic
Date: Tue, 20 Jun 2006 11:30:34 -0400
User-agent: Mutt/1.3.28i

felix winkelmann scripsit:

> Chicken already supports +inf, -inf and +nan.

Not so much.

Version 2, Build 320 - windows-cygwin-x86 - [ dload ptables applyhook ]
(c)2000-2006 Felix L. Winkelmann
#;1> +inf
Error: unbound variable: +inf
#;1> +inf.0
Error: unbound variable: +inf.0
#;1> -inf
Error: unbound variable: -inf
#;1> -inf.0
Error: unbound variable: -inf.0
#;1> +nan
NaN.0
#;2> +nan.0
Error: unbound variable: +nan.0
#;2>

> (+inf.0, ... are supported as well, but a bug I just fixed
> in the number-parser prevented it from working).

Fair enough.  Could the number->string behavior be fixed as well, then?
I know Chicken doesn't guarantee full read-write equivalence, but this
case is rather drastic: the output format isn't even recognized by the
input routines at all, nor vice versa.

Here are some handy C routines for detecting infs and nans that I worked
out with Albert Gräf (the Q author):

int isnan(double f) {
        return !(f == f);
        }

int isinf(double f) {
        return f == f + 1.0;
        }

The first one works because any comparison involving a NaN is always
false.  In the second one, obviously no finite argument can return
true, and although NaN + 1.0 gives NaN, it will still not compare equal
to itself!

-- 
Time alone is real                      John Cowan <address@hidden>
  the rest imaginary
like a quaternion       --phma          http://www.ccil.org/~cowan




reply via email to

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