Practice question · True or false
Because a float stores only finitely many digits, two computations that are mathematically equal can produce values that differ slightly.
Hints
- Each intermediate result is rounded to the nearest representable value.
- Rounding errors from different routes need not cancel.
Show the answer
True
Why
True. Every stored float is rounded, and two different routes to the same mathematical value round at different places, so the tiny errors differ. That is precisely why exact equality tests on floats are unreliable.
Practise Variables, Types, and Expressions
The app has 4 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Variables, Types, and Expressions
- In most languages 0.1 + 0.2 == 0.3 evaluates to false. Why do experienced programmers compare floats with a…
- Match each data type to its defining property.
- Order the evaluation steps of the expression 2 + 3 * (8 - 6) / 2.
- Select every statement that is TRUE.
- In mathematics x = x + 1 is a contradiction with no solution. In most programming languages it is a routine…
- The symbol + adds numbers but joins text. Sort each expression by what + actually does.