I want to directly calculate the minimum value of the float type, and here is my algorithm(Suppose that the encoding of floating-point number confirms to the IEEE 754 standard):
#include <math.h>
#include <limits.h>
#include <float.h>
#include <stdio.h>
float float_min()
{
int exp_bit = CHAR_BIT * sizeof(float) - FLT_MANT_DIG;
float exp = 2 - pow(2, exp_bit - 1);
float m = pow(2, -(FLT_MANT_DIG - 1));
return m * pow(2, exp);
}
int main()
{
printf("%g\n", float_min());
}
The output is 1.4013e-45. However, I find the the value of FLT_MIN in the C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\float.h is 1.175494351e-38F. Who is wrong?