This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: IS_INF bug?


On  9-May-2000, Dirk Herrmann <dirk@ida.ing.tu-bs.de> wrote:

| On Tue, 9 May 2000, Ivan Toshkov wrote:
| 
| > On Tue, May 09, 2000 at 01:19:29PM +0200, Han-Wen Nienhuys wrote:
| > > 
| > > I think the naming of the following macro should be changed to
| > > NONZERO_IS_INF, or something alike. The name is misleading.
| > > 
| > > 
| > > 	/* IS_INF tests its floating point number for infiniteness
| > > 	 */
| > > 	#ifndef IS_INF
| > > 	#define IS_INF(x) ((x) == (x) / 2)
| > > 	#endif
| [...]
| > If you meant that the check will work for zero, it seems that you are
| > right. A (mathematically) corect test for infinity would be 
| > ((x) == (x) + 1) but I don't know if this makes sense for the macro.
| 
| Hello!
| 
| I just changed the test to 
|   IS_INF(x) ((x) == (x) + 1)
| so that people can experiment with it.

I'm assuming this macro is supposed to be applied to doubles or
floats, and not some other type.

If so, the value of the expression in the macro above will be 1 when x
is less than or equal to the maximum representable value, but greater
than the largest integer value that can be represented in a float or
double (whatever the type of x).  For example

  #include <math.h>
  #include <stdio.h>

  #define IS_INF(x) ((x) == (x) + 1)

  int
  main (void)
  {
    double x = 1.2345e300;

    printf ("%g, %d\n", x, IS_INF (x));

    return 0;
  }

prints

  1.2345e+300, 1

on systems with IEEE floating point.

If you want to get this kind of thing right in guile, I think it would
be best to use configure to look for isinf, finite, isnan,
etc. functions, and then use them if they are available.  If they are
not, then you need to provide good replacements, or just punt, and
don't try to deal with IEEE Inf/NaN problems on systems that don't
have the necessary support.

jwe

-- 
www.che.wisc.edu/octave | Thanking you in advance.  This sounds as if the
www.che.wisc.edu/~jwe   | writer meant, "It will not be worth my while to
                        | write to you again."        -- Strunk and White

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]