Back to the Catalog
javascript
floating-point
ieee-754
numbers
ecmascript
precision

Floating Point: Why Your Money Is Wrong

31 questions

Every answer here is decidable by IEEE 754 and ECMA-262. No opinions, no engine trivia. Binary fractions, the lies toFixed tells, negative zero, the gaps above Number.MAX_SAFE_INTEGER, and why summing the same million numbers in a different order gives you a different total.

Questions

  1. Not answered. What does 0.1 + 0.2 evaluate to in JavaScript?
  2. Not answered. Why can a double hold 0.5 exactly but not 0.1?
  3. Not answered. Which of these strict comparisons evaluates to true?
  4. Not answered. How far apart are 0.1 + 0.2 and 0.3 on the double number line?
  5. Not answered. Why does String(0.1) print "0.1" while String(0.1 + 0.2) prints all 17 digits?
  6. Not answered. What does (0.1).toFixed(20) return?
  7. Not answered. What string does (1.005).toFixed(2) return?
  8. Not answered. Which observation proves toFixed is not using banker's rounding when (1.005).toFixed(2) yields "1.00"?
  9. Not answered. What do these two ways of rounding 1.005 to two decimals print in the same runtime?
  10. Not answered. What does Math.round(1.005 * 100) / 100 evaluate to?
  11. Not answered. Which of these expressions evaluate to true?
  12. Not answered. Which of these expressions produces -0?
  13. Not answered. Why does this trend indicator report a falling trend for a metric that barely moved?
  14. Not answered. What do (-0).toFixed(1) and (-0.04).toFixed(1) return?
  15. Not answered. What is the value of Number.MAX_SAFE_INTEGER?
  16. Not answered. 2 ** 53 is stored exactly, so why is Number.MAX_SAFE_INTEGER one less than it?
  17. Not answered. Which statements about doubles above Number.MAX_SAFE_INTEGER are true?
  18. Not answered. What does JSON.parse('{"id": 1234567890123456789}').id return?
  19. Not answered. Summing the same array forwards and backwards gives two different totals. What are they?
  20. Not answered. Which summation algorithm carries a running compensation term to recover the low-order bits lost at each addition?
  21. Not answered. In Kahan summation, what does c hold after the line c = (t - sum) - y?
  22. Not answered. Which of these are real reasons to store money in NUMERIC/DECIMAL rather than DOUBLE PRECISION?
  23. Not answered. What does Number.EPSILON actually measure?
  24. Not answered. Why does Math.abs(a - b) < Number.EPSILON accept the tenths case but reject the millions case?
  25. Not answered. What is Number.MIN_VALUE?
  26. Not answered. In 32-bit floats, does 0.1 + 0.2 equal 0.3?
  27. Not answered. Which rounding mode does IEEE 754 apply to arithmetic results by default?
  28. Not answered. Which of these NaN expressions evaluate to true?
  29. Not answered. How many iterations does for (let x = 0; x !== 1; x += 0.1) run?
  30. Not answered. What does parseInt(0.0000005) return?
  31. Not answered. Which of these approaches actually make money arithmetic correct in JavaScript?