[floats][infinity][C99]

Daniel Kochmański daniel at turtleware.eu
Fri Sep 4 15:48:51 UTC 2015


Thanks for reply.

Raymond Toy writes:

>>>>>> "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.

We have at least three float types – short-float, single-float and
double-float, plus on some architectures long-float. Will this approach
work on all of these types?

Also, we'll have to define such infinity for each architecture
separately, depending on the endianess?

I'm don't know float numbers well enough, but soft floats and hard
floats on arm architecture make any difference for us, or C compiler
will handle it without any intervention?

-- 
Daniel Kochmański | Poznań, Poland
;; aka jackdaniel

"Be the change that you wish to see in the world." - Mahatma Gandhi



More information about the ecl-devel mailing list