Commit 9c677be
authored
07-cond.md: Close Enough correction (#839)
`print(abs(a - b) < 0.1 * abs(b))` (and preceding Solution 2) leaves out the edge case where `a` is exactly 10% of `b`. This issue comes down to the interpretation of "within" 10%. Does a number within 10% of another number include the 10% value?
Assume `b = 100` and `0.1 * b = 10`, then the value 10 is within 10% by definition since 10 is 10% of 100. Now set `a = 100 + 10 = 110` which is `b` plus 10% of `b`. Then `a - b = b + 0.1 * b - b = 0.1 * b`, which is within 10% of b.
The correct test is `abs(a - b) <= 0.1 * abs(b)` to account for this edge case.1 parent ebe849a commit 9c677be
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
| 316 | + | |
317 | 317 | | |
318 | 318 | | |
319 | 319 | | |
| |||
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
326 | | - | |
| 326 | + | |
327 | 327 | | |
328 | 328 | | |
329 | 329 | | |
| |||
0 commit comments