| Total Complexity | 16 |
| Total Lines | 92 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 43 | class Math |
||
| 44 | { |
||
| 45 | public static function cmp(\GMP $first, \GMP $other) : int |
||
| 46 | { |
||
| 47 | return \gmp_cmp($first, $other); |
||
| 48 | } |
||
| 49 | |||
| 50 | public static function equals(\GMP $first, \GMP $other) : bool |
||
| 51 | { |
||
| 52 | return 0 === \gmp_cmp($first, $other); |
||
| 53 | } |
||
| 54 | |||
| 55 | public static function mod(\GMP $number, \GMP $modulus) : \GMP |
||
| 56 | { |
||
| 57 | return \gmp_mod($number, $modulus); |
||
|
1 ignored issue
–
show
|
|||
| 58 | } |
||
| 59 | |||
| 60 | public static function add(\GMP $augend, \GMP $addend) : \GMP |
||
| 61 | { |
||
| 62 | return \gmp_add($augend, $addend); |
||
|
1 ignored issue
–
show
|
|||
| 63 | } |
||
| 64 | |||
| 65 | public static function sub(\GMP $minuend, \GMP $subtrahend) : \GMP |
||
| 66 | { |
||
| 67 | return \gmp_sub($minuend, $subtrahend); |
||
|
1 ignored issue
–
show
|
|||
| 68 | } |
||
| 69 | |||
| 70 | public static function mul(\GMP $multiplier, \GMP $multiplicand) : \GMP |
||
| 71 | { |
||
| 72 | return \gmp_mul($multiplier, $multiplicand); |
||
|
1 ignored issue
–
show
|
|||
| 73 | } |
||
| 74 | |||
| 75 | public static function pow(\GMP $base, int $exponent) : \GMP |
||
| 76 | { |
||
| 77 | return \gmp_pow($base, $exponent); |
||
|
1 ignored issue
–
show
|
|||
| 78 | } |
||
| 79 | |||
| 80 | public static function bitwiseAnd(\GMP $first, \GMP $other) : \GMP |
||
| 81 | { |
||
| 82 | return \gmp_and($first, $other); |
||
|
1 ignored issue
–
show
|
|||
| 83 | } |
||
| 84 | |||
| 85 | public static function bitwiseXor(\GMP $first, \GMP $other) : \GMP |
||
| 88 | } |
||
| 89 | |||
| 90 | public static function toString(\GMP $value) : string |
||
| 91 | { |
||
| 92 | return \gmp_strval($value); |
||
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param \GMP $a |
||
| 97 | * @param \GMP $m |
||
| 98 | * @return \GMP|bool |
||
| 99 | */ |
||
| 100 | public static function inverseMod(\GMP $a, \GMP $m) |
||
| 101 | { |
||
| 102 | return \gmp_invert($a, $m); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @param int|string $number |
||
| 107 | * @param int $from |
||
| 108 | * @param int $to |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | public static function baseConvert($number, int $from, int $to) : string |
||
| 112 | { |
||
| 113 | return \gmp_strval(\gmp_init($number, $from), $to); |
||
| 114 | } |
||
| 115 | |||
| 116 | public static function rightShift(\GMP $number, int $positions) : \GMP |
||
| 117 | { |
||
| 118 | // when using \gmp_div, phpStan says: Method SKien\PNServer\Utils\Math::rightShift() should return GMP but returns resource. ? |
||
| 119 | return \gmp_div_q($number, \gmp_pow(\gmp_init(2, 10), $positions)); |
||
|
1 ignored issue
–
show
|
|||
| 120 | } |
||
| 121 | |||
| 122 | public static function modSub(\GMP $minuend, \GMP $subtrahend, \GMP $modulus) : \GMP |
||
| 123 | { |
||
| 124 | return self::mod(self::sub($minuend, $subtrahend), $modulus); |
||
| 125 | } |
||
| 126 | |||
| 127 | public static function modMul(\GMP $multiplier, \GMP $muliplicand, \GMP $modulus) : \GMP |
||
| 128 | { |
||
| 129 | return self::mod(self::mul($multiplier, $muliplicand), $modulus); |
||
| 130 | } |
||
| 131 | |||
| 132 | public static function modDiv(\GMP $dividend, \GMP $divisor, \GMP $modulus) : \GMP |
||
| 135 | } |
||
| 136 | } |
||
| 137 |