"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why Does Double Precision Appear to Have More Decimal Places Than Its Advertised 15?

Why Does Double Precision Appear to Have More Decimal Places Than Its Advertised 15?

Published on 2024-12-24
Browse:322

Why Does Double Precision Appear to Have More Decimal Places Than Its Advertised 15?

Double Precision and Decimal Place Accuracy

In computer programming, the double precision data type is often assumed to have an approximate precision of 15 decimal places. However, certain number representations, such as 1.0/7.0, seem to have more precision when represented internally within the variable. This article will explore why this occurs and why the precision is often described as around 15 decimal places.

Internal Representation

An IEEE double has 53 significant bits, approximately equaling 15.95 decimal digits. To account for rounding, the implementation sets the precision (DBL_DIG) to 15. This provides nearly an extra decimal digit of precision beyond what's implied by DBL_DIG.

Output Precision

When displaying a double, compilers usually round the value based on the precision. For example, 1.0/7.0, when displayed with "%.17g," has 17 digit accuracy. However, if "%.64g" is used, no significant digits appear beyond the expected 15-digit precision.

Conclusion

Double precision numbers have an internal representation that allows for around 15.95 decimal digits of precision. However, due to rounding, the displayed precision is typically set to 15 decimal places. This explanation helps clarify why certain exact numbers, like 1.0/7.0, appear to have more precision internally but still conform to the estimated 15-digit precision when displayed.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3