Numerical methods
A loop total = 0.0; for _ in range(10): total += 0.1 leaves total == 0.9999999999999999.
AppliedMultiple choice
A loop total = 0.0; for _ in range(10): total += 0.1 leaves total == 0.9999999999999999. Which gives exactly 1.0?
- A
round(total, 20), rounding the error away - B
math.fsum([0.1] * 10) - C
total * 1.0 - D
float(str(total))
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Report an issue with this question
Of the kind reported at
More numerical methods questions
- Double precision can represent every integer up to 2ᵏ exactly, but not every…Applied · Premium
- Where doubles run out of digits, part 2 of 3Applied · Premium
- Computing a variance as 𝔼[X²]−(𝔼[X])² sometimes returns a small negative number. Why?Advanced · Premium
- You sum ten million small positive numbers in float32. What goes wrong and what fixes it?Advanced · Premium
- Where doubles run out of digits, part 3 of 3Advanced · Premium
- What is machine epsilon for IEEE 754 double precision, in units of 10⁻¹⁶, to…Foundation · Premium