Why is FLT_MIN equal to zero?

前端 未结 4 1273
情歌与酒
情歌与酒 2020-12-01 07:47

limits.h specifies limits for non-floating point math types, e.g. INT_MIN and INT_MAX. These values are the most negative and most pos

4条回答
  •  无人及你
    2020-12-01 08:32

    Whenever you will try to print the value of FLT_MIN from standard header file float.h ,you will get 0.000000(as you are seeing in your output screen). That is not actually a error. You are getting this result because the format specifier %f. Generally %f print 6 digits after the decimal point but in this case the signed negative value is so small that you need to print significant amount of digits after the decimal point.

    I have used %.54f(machine dependent) to get the desired- result(0.000000000000000000000000000000000000011754943508222875 for my system).

    //Check this on your system

    #include
    #include
    int main()
    {
        printf("Minimum signed float %.55f\n",FLT_MIN);
        printf("Minimum signed float %e\n",FLT_MIN);
        return 0;
    }
    

    //Output :-

    // Minimum signed float 0.0000000000000000000000000000000000000117549435082228750

    // Minimum signed float 1.175494e-038

    I think now it's clear to you why you are getting 0.000000 for CHAR_MIN and how to get the correct result with the same format specifier.Though you can use %e for better formatted result.

提交回复
热议问题