[floats][infinity][C99]

Raymond Toy toy.raymond at gmail.com
Fri Sep 4 15:22:23 UTC 2015


>>>>> "Daniel" == Daniel Kochma <Daniel> writes:

    Daniel> Hello,
    Daniel> I'm little in doubt. Problem is related to ieee-floating-point
    Daniel> extensions, which provide infinities and nan. Everything works fine
    Daniel> until we generate C code, which simply breaks, because it isn't taken
    Daniel> into account.

    Daniel> There are two possible solutions:

    Daniel> - for these cases use constant expressions, which trigger an error on
    Daniel> some compilers, that is (0.0 / 0.0) for nan, (1.0 / 0.0) for infinity


    Daniel> - use defined by C99 macros: INFINITY and NAN, which will work on any
    Daniel> compiler supporting C99.

Option 3:  Create them yourself in portable C.  Something like

   union {
     int i[2];
     double d;
   } u;

   /* +Infinity */
   u.i[MSB] = 0x7ff00000;
   u.i[LSB] = 0;
   u.d is +Infinity

where MSB and LSB are 0 or 1 depending on the endianness of machine.
If you have 64-bit integers, you can replace int i[2] with long i and
just use i = 0x7ff0000000000000;

This works for NaN too, but there are many different values for NaN,
so you'll have to choose something.

--
Ray




More information about the ecl-devel mailing list