{
  "id": 10670810,
  "title": "Adding Floating-Point Decimals for Fun and Profit",
  "url": "https://urgent.news/2026/09/29/adding-floating-point-decimals-for-fun-and-profit",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-29T03:07:39.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://blog.vero.site/post/float"
  },
  "original_language": "en",
  "account": "Floating-point numbers, such as those used for U.S. dollars and cents, cannot be expressed exactly in most programming languages, leading to rounding errors. For example, in the IEEE double-precision format, 0.1 + 0.2 does not equal 0.3 but rather 0.30000000000000004. Despite these errors, they often do not appear in typical sums involving dollars and cents, as the stakes are usually low and errors can be manually rounded off.\n\nIn the Python REPL, adding decimal numbers like 0.1 and 0.2 still results in a small error, which is rounded when printed. This leads to output such as \"0.30000000000000004\" instead of the exact \"0.3\". The discrepancy arises because the conversion of the final floating-point sum back to a decimal number is not precisely specified by the IEEE standard, allowing for various levels of rounding.\n\nTo understand this better, consider the value of a floating-point number \\(x = \\pm 2^E(1 + F/{2^{52}})\\), where \\(E\\) is the exponent and \\(F\\) is the fraction part. The effective value of the last fraction bit, known as the ulp (unit in the last place), is \\(2^{E-52}\\). This quantity represents the distance between \\(x\\) and its two nearest floating-point neighbors.\n\nWhen adding two decimal numbers \\(a\\) and \\(b\\) using floating-point representation, the result \\(\\text{float}(\\text{float}(a) + \\text{float}(b))\\) may not be exactly equal to the true sum \\(c\\). The difference \\(\\Delta\\) between the computed sum and the true sum can be analyzed in terms of the error function \\(\\text{error}(x) := \\text{float}(x) - x\\). By considering the ulp of the sum and the error terms, one can determine how close the computed sum is to the exact result, bounded by the ulp value.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}