[Bf-committers] Verse 2005 Errors

Emil Brink emil at obsession.se
Thu Sep 14 20:42:43 CEST 2006

Branan Riley wrote:
> Any system using the proper IEEE floating point sizes will have
> 0x7f7fffff as the maximum float value. The largest (smallest, I
> suppose) negative number should be 0xff7fffff. Sign bit is set.
> 0x7ffxxxxx (where x is any hex digit) is positive infinity, and
> 0xfffxxxxx is negative infinity.

Agreed. The problem was mainly how to get this exact bit sequence
from a floating point literal. Having done a quick experiment, I
now think that the proper value to use is 3.4028235e+38f.

I have not actually done the bit-level maths to test that theory
though, just tried loading 0x7f7fffff into a float using a simple
pointer indirection (for variety), snprintf()ing it, and then
sscanf()ing it back.

Not there is any guarantee that the compiler uses the same code as
sscanf() to read float literals, of course. Still, using the literal
above generates the proper bit pattern here (Linux, GCC 4.1.1), so
maybe there's hope it will in the various MS compilers, too.

Anyway, thanks for the input.



More information about the Bf-committers mailing list