Explain this code in K&R 2-1

后端 未结 3 1661
暗喜
暗喜 2021-01-04 07:36

I\'m trying to determine range of the various floating-point types. When I read this code:

#include 

main()
{
    float fl, fltest, last;
            


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-04 08:14

    The largest value representable in a float is 3.40282e+38. The constant 1111e28 is chosen such that adding that constant to a number in the range of 10^38 still produces a different floating point value, so that the value of fltest will continue to increase as the function runs. It needs to be large enough that it will still be significant at the 10^38 range, and small enough that the result will be accurate.

提交回复
热议问题