The constants in <float.h>
for Apple clang version 12.0.0 (clang-1200.0.32.2)
don't seem to make sense.
DBL_MIN_EXP
is -1021
and DBL_MAX_EXP
is 1024
. However, that doesn't match what wikipedia says, "exponents range from −1022 to +1023, ..."
Also DBL_MIN_EXP
seems inconsistent with DBL_MIN
which is 2.2250738585072014e-308
which is equal to 2⁻¹⁰²²
sometimes written as 0x1.0000000000000p-1022
. So, we have an exponent smaller than the minimum -1021
.
Likewise, DBL_MIN_10_EXP
is -307
which doesn't sense given that DBL_MIN
has an exponent of e-308
.
The double DBL_MAX_EXP
value of 1024
overflows when used in real code. For example, ldexp(1.0, 1024)
gives inf
.
Here's my C code:
#include <float.h>
#include <stdio.h>
#include <math.h>
#define SHOW_DOUBLE(s) printf("%.17lg \t%s\n", s, #s);
#define SHOW_INT(s) printf("%d \t%s\n", s, #s);
int
main()
{
SHOW_DOUBLE(DBL_MAX);
SHOW_DOUBLE(DBL_MIN);
SHOW_DOUBLE(DBL_EPSILON);
SHOW_INT(DBL_MAX_EXP);
SHOW_INT(DBL_MAX_10_EXP);
SHOW_INT(DBL_MIN_EXP);
SHOW_INT(DBL_MIN_10_EXP);
SHOW_INT(DBL_DIG);
SHOW_INT(DBL_MANT_DIG);
SHOW_INT(FLT_RADIX);
SHOW_INT(FLT_ROUNDS);
printf("%lf\n", ldexp(1.0, 1024));
return 0;
}
And here is the output:
1.7976931348623157e+308 DBL_MAX
2.2250738585072014e-308 DBL_MIN
2.2204460492503131e-16 DBL_EPSILON
1024 DBL_MAX_EXP
308 DBL_MAX_10_EXP
-1021 DBL_MIN_EXP
-307 DBL_MIN_10_EXP
15 DBL_DIG
53 DBL_MANT_DIG
2 FLT_RADIX
1 FLT_ROUNDS
inf