How to determine the max precision for double

后端 未结 4 1097
野性不改
野性不改 2020-12-06 16:54

I am trying to determine what the maximum precision for a double is. In the comments for the accepted answer in this link Retain precision with double in Java @PeterLawrey s

4条回答
  •  自闭症患者
    2020-12-06 17:37

    @PeterLawrey states max precision in 15.

    That's actually not what he stated at all. What he stated was:

    double has 15 decimal places of accuracy

    and he is wrong. They have 15 decimal digits of accuracy.

    The number of decimal digits in any number is given by its log to the base 10. 15 is the floor value of log10(253-1), where 53 is the number of bits of mantissa (including the implied bit), as described in the Javadoc and IEEE 754, and 253-1 is therefore the maximum possible mantissa value. The actual value is 15.954589770191003298111788092734 to the limits of the Windows calculator.

    He is quite wrong to describe it as 'decimal places of accuracy'. A double has 15 decimal digits of accuracy if they are all before the decimal point. For numbers with fractional parts you can get many more than 15 digits in the decimal representation, because of the incommensurability of decimal and binary fractions.

提交回复
热议问题