Commit 9d7733f
committed
Fix ZeroDivisionError on zero operands in least_common_multiple
least_common_multiple_slow raised ZeroDivisionError for a zero operand (0 % n in the loop guard), e.g. least_common_multiple_slow(0, 5), and least_common_multiple_fast raised it for (0, 0) via floor-division by gcd(0, 0) == 0. The least common multiple is 0 whenever an operand is 0 (consistent with math.lcm), so both functions return 0 in that case. Adds doctests covering the zero inputs.1 parent e3b01ec commit 9d7733f
1 file changed
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
17 | 23 | | |
| 24 | + | |
| 25 | + | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
| |||
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
33 | 47 | | |
| 48 | + | |
| 49 | + | |
34 | 50 | | |
35 | 51 | | |
36 | 52 | | |
| |||
0 commit comments