news.volyx.in

0.30000000000000004 (0.30000000000000004.com)

768 points by beznet · 2508 days ago · 402 comments on HN

Article summary

The article discusses the issue of floating-point math in computers, where certain decimal numbers cannot be represented exactly in binary, leading to small errors in calculations. This is demonstrated by the example of 0.1 + 0.2 not equaling 0.3 in many programming languages. The article explains that this is due to the way computers store decimal numbers in binary format. The issue is not unique to any particular language, but rather a fundamental property of binary floating-point arithmetic.

Main themes

  • Floating-point math
  • Binary representation
  • Decimal accuracy
  • Programming languages
  • Numerical analysis

What commenters say

  • The limitations of floating-point math can be mitigated by using techniques such as sorting numbers before adding them or using specialized libraries for decimal arithmetic. Some programming languages have built-in support for arbitrary-precision arithmetic or decimal numbers, which can help avoid these issues. The use of binary floating-point numbers is a trade-off between precision and range, and is sufficient for most applications. The importance of accurate decimal calculations is often overstated, and the occasional error is not significant in most cases. Decimal floating-point numbers have been standardized, but are not widely adopted due to performance concerns. Fixed-point arithmetic can be used as an alternative to floating-point numbers, but is not always supported by programming languages. The financial industry has specific requirements for decimal calculations, and often relies on specialized systems or languages to ensure accuracy.