[Verse-dev] About NAN and various REAL_MAX

Emil Brink emil at obsession.se
Thu Sep 14 11:06:35 CEST 2006


Replying to self ...

[...]
> So, I came up with the following pretty nice snippet to load this value
> into a floating point variable:
> 
> float a = ((union { unsigned int x; float y; }) 0x7f7fffffu).y;
> 
> I believe this works, as long as
> 
> * unsigned int and float are both 32 bits
> * the endianness for ints is the same as for floats ... I think this is
>   the case on most "normal" platforms, but have only tested the above
>   in Linux on x86
> * the compiler understands the code at all :) GCC was pretty impressive
>   here ...

It seems to fail on the latter point, I can't get it to compile with MS'
compiler. Some googling, and adding the -pedantic switch to my GCC compile,
reveals the entire construct to be a GCC extension. Bleh. I guess it was
too good to be true, heh.

I'm sure we can come up with something similar, though, and perhaps use the
above on GCC since it seems to be pretty efficient.

Regards,

/Emil



More information about the Verse-dev mailing list