Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
7 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| NumericUtils | |
50.00% |
7 / 14 |
|
0.00% |
0 / 1 |
13.12 | |
0.00% |
0 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| uRightShift | |
50.00% |
7 / 14 |
|
0.00% |
0 / 1 |
10.50 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Utils |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Utils; |
| 16 | |
| 17 | /** |
| 18 | * Array utils. |
| 19 | * |
| 20 | * @package phpOMS\Utils |
| 21 | * @license OMS License 2.0 |
| 22 | * @link https://jingga.app |
| 23 | * @since 1.0.0 |
| 24 | */ |
| 25 | final class NumericUtils |
| 26 | { |
| 27 | /** |
| 28 | * Constructor. |
| 29 | * |
| 30 | * @since 1.0.0 |
| 31 | * @codeCoverageIgnore |
| 32 | */ |
| 33 | private function __construct() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Unsigned right shift |
| 39 | * |
| 40 | * @param int $a Value to shift |
| 41 | * @param int $b Shift by |
| 42 | * |
| 43 | * @return int unsigned int |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | */ |
| 47 | public static function uRightShift(int $a, int $b) : int |
| 48 | { |
| 49 | if ($b >= 32 || $b < -32) { |
| 50 | $m = (int) ($b / 32); |
| 51 | $b -= $m * 32; |
| 52 | } |
| 53 | |
| 54 | if ($b < 0) { |
| 55 | $b = 32 + $b; |
| 56 | } |
| 57 | |
| 58 | if ($b == 0) { |
| 59 | return (($a >> 1) & 0x7fffffff) * 2 + (($a >> $b) & 1); |
| 60 | } |
| 61 | |
| 62 | if ($a < 0) { |
| 63 | $a >>= 1; |
| 64 | $a &= 0x7fffffff; |
| 65 | $a |= 0x40000000; |
| 66 | $a >>= $b - 1; |
| 67 | } else { |
| 68 | $a >>= $b; |
| 69 | } |
| 70 | |
| 71 | return $a; |
| 72 | } |
| 73 | } |