Max float is defied as:
math.h
#define MAXFLOAT 0x1.fffffep+127f
I'm a little sad I never noticed this before. What's this actually say? I would have expected something like this:
#define MAXFLOAT 0xFFFFFFFF-1
Would that even work?
Max float is defied as:
math.h
#define MAXFLOAT 0x1.fffffep+127f
I'm a little sad I never noticed this before. What's this actually say? I would have expected something like this:
#define MAXFLOAT 0xFFFFFFFF-1
Would that even work?
0x1.fffffep+127 is (roughly)
1.99999999999999999999998 times 2^127. It's a floating point number, with an exponent, in hexadecimal.
0x = hex notation1 = integer part of the number.fffffe = fractional part of the numberp+127 = scientific notation for "times two to the 127th power"MAXFLOAT is required for UNIX conformance:
MAXFLOAT
[XSI] Value of maximum non-infinite single-precision floating-point number.
0x1.fffffep+127f is precisely that value, represented as a standard C hexadecimal floating-point literal.
The C standard requires that FLT_MAX be defined in <float.h>, and it has the same value ("maximum representable finite floating-point number", per §5.2.4.2.2). FLT_MAX is the more portable choice, as it is required by the language standard.