Question 6
Back to Exercise
Two computed doubles should be treated as equal. Which condition is appropriate?
- A a == b
- B fabs(a - b) < 1e-9 (or a relative tolerance) Correct
- C (int) a == (int) b
- D a - b == 0
Correct Answer: Option B
Rounding errors make exact equality unreliable (0.1 * 3 != 0.3). Compare the difference with a tolerance – relative to the values' size for large numbers.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!