0

This code:

int main(){

    printf("The value of FLT_MAX is %.5f\n", FLT_MAX);
    printf("The value of FLT_MIN is %.5f\n", FLT_MIN);
    printf("A float takes %i bytes\n", sizeof(float));

    float fx = -1.24;
    printf("The value of fx is %f\n", fx);

}

returns:

The value of FLT_MAX is 340282346638528859811704183484516925440.00000
The value of FLT_MIN is 0.00000
A float takes 4 bytes
The value of fx is -1.240000

Is float unsigned or signed? Why is the FLT_MIN 0 but on the other hand I can store a negative value in a float?

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319

1 Answers1

5

The value of FLT_MIN is implementation-defined, it's not zero, but a positive number (to be precise, it's the minimum normalized positive float number). One typical value of it is 1E-37.

The problem in your code is, you are printing it with %.5f, only 5 digits after the decimal point.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
  • Why is that a problem? – Koray Tugay Mar 19 '15 at 14:49
  • @KorayTugay What output do you expect? Even `0.00001` is *much* bigger than `1E-37`. – Yu Hao Mar 19 '15 at 14:50
  • I do not understand. My question is, if it is 1E-37 it is still greater than 0. But I was able to store a negative value in a float. – Koray Tugay Mar 19 '15 at 14:51
  • Ah ok thanks. I see.. How can I print the defined minimal value? – Koray Tugay Mar 19 '15 at 14:53
  • @KorayTugay `FLT_MIN` is the name of the smallest positive normal number. There are more positive float numbers (denormals), and then there is zero, and then there is `-FLT_MAX`, the minimum finite floating-point value, and then there is -inf, which is actually the minimum floating-point value (but is not finite). – Pascal Cuoq Mar 19 '15 at 14:54
  • @YuHao the minimal positive normal value. There are 2^23-1 denormal values between `FLT_MIN` and 0. – Pascal Cuoq Mar 19 '15 at 14:55
  • @PascalCuoq I see, thanks. I missed that.. – Koray Tugay Mar 19 '15 at 14:55
  • @PascalCuoq I was confused because Head First C says this is the lowest value of a float: printf("The value of FLT_MIN is %.50f\n", FLT_MIN); – Koray Tugay Mar 19 '15 at 14:56