| Conditions | 6 |
| Paths | 7 |
| Total Lines | 18 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 43 | public static function divide2(int $x, int $y): int |
||
| 44 | { |
||
| 45 | if ($x === (1 << 31) && $y === -1) { |
||
| 46 | return (1 << 31) - 1; |
||
| 47 | } |
||
| 48 | $n = 0; |
||
| 49 | [$a, $b] = [abs($x), abs($y)]; |
||
| 50 | while ($a - $b >= 0) { |
||
| 51 | [$t, $i] = [$b, 1]; |
||
| 52 | while ($a - ($t << 1) >= 0) { |
||
| 53 | $t <<= 1; |
||
| 54 | $i <<= 1; |
||
| 55 | } |
||
| 56 | $a -= $t; |
||
| 57 | $n += $i; |
||
| 58 | } |
||
| 59 | |||
| 60 | return ($x > 0) === ($y > 0) ? $n : -$n; |
||
| 61 | } |
||
| 63 |