Lines Matching refs:x

246      * @param int|string|resource $x base-10 number or base-$base number if $base set.
251 function __construct($x = 0, $base = 10) argument
336 case is_resource($x) && get_resource_type($x) == 'GMP integer':
338 case $x instanceof \GMP:
339 $this->value = $x;
353 if (empty($x) && (abs($base) != 256 || $x !== '0')) {
359 if (ord($x[0]) & 0x80) {
360 $x = ~$x;
367 gmp_import($x) :
368 gmp_init('0x' . bin2hex($x));
375 $len = (strlen($x) + 3) & 0xFFFFFFFC;
377 $x = str_pad($x, $len, chr(0), STR_PAD_LEFT);
381 …lue = bcadd($this->value, 0x1000000 * ord($x[$i]) + ((ord($x[$i + 1]) << 16) | (ord($x[$i + 2]) <<…
391 while (strlen($x)) {
392 … $this->value[] = $this->_bytes2int($this->_base256_rshift($x, self::$base));
406 if ($base > 0 && $x[0] == '-') {
408 $x = substr($x, 1);
411 $x = preg_replace('#^(?:0x)?([A-Fa-f0-9]*).*#', '$1', $x);
414 if ($base < 0 && hexdec($x[0]) >= 8) {
416 $x = bin2hex(~pack('H*', $x));
421 $temp = $this->is_negative ? '-0x' . $x : '0x' . $x;
426 $x = (strlen($x) & 1) ? '0' . $x : $x;
427 $temp = new static(pack('H*', $x), 256);
432 $x = (strlen($x) & 1) ? '0' . $x : $x;
433 $temp = new static(pack('H*', $x), 256);
447 $x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x);
448 if (!strlen($x) || $x == '-') {
449 $x = '0';
454 $this->value = gmp_init($x);
459 $this->value = $x === '-' ? '0' : (string) $x;
467 if ($x[0] == '-') {
469 $x = substr($x, 1);
472 …$x = str_pad($x, strlen($x) + ((self::$max10Len - 1) * strlen($x)) % self::$max10Len, 0, STR_PAD_L…
473 while (strlen($x)) {
475 … $temp = $temp->add(new static($this->_int2bytes(substr($x, 0, self::$max10Len)), 256));
476 $x = substr($x, self::$max10Len);
484 if ($base > 0 && $x[0] == '-') {
486 $x = substr($x, 1);
489 $x = preg_replace('#^([01]*).*#', '$1', $x);
490 $x = str_pad($x, strlen($x) + (3 * strlen($x)) % 4, 0, STR_PAD_LEFT);
493 while (strlen($x)) {
494 $part = substr($x, 0, 4);
496 $x = substr($x, 4);
1137 function multiply($x) argument
1142 $temp->value = gmp_mul($this->value, $x->value);
1147 $temp->value = bcmul($this->value, $x->value, 0);
1152 $temp = $this->_multiply($this->value, $this->is_negative, $x->value, $x->is_negative);
1306 * @param array $x
1310 function _square($x = false) argument
1312 return count($x) < 2 * self::KARATSUBA_CUTOFF ?
1313 $this->_trim($this->_baseSquare($x)) :
1314 $this->_trim($this->_karatsubaSquare($x));
1465 $x = $this->copy();
1468 $x_sign = $x->is_negative;
1471 $x->is_negative = $y->is_negative = false;
1473 $diff = $x->compare($y);
1485 $x = $y->subtract($x);
1487 return array($this->_normalize(new static()), $this->_normalize($x));
1495 $x->_lshift($shift);
1499 $x_max = count($x->value) - 1;
1518 while ($x->compare($temp) >= 0) {
1521 $x = $x->subtract($temp);
1522 $x_max = count($x->value) - 1;
1526 $x_value = &$x->value;
1569 $x = $x->subtract($temp);
1571 if ($x->compare($zero) < 0) {
1573 $x = $x->add($temp);
1582 $x->_rshift($shift);
1589 $x = $y->subtract($x);
1592 return array($this->_normalize($quotient), $this->_normalize($x));
1901 * @param array $x
1906 function _reduce($x, $n, $mode) argument
1910 return $this->_montgomery($x, $n);
1912 return $this->_barrett($x, $n);
1915 $lhs->value = $x;
1918 return $x->_mod2($n);
1921 $lhs->value = $x;
1927 return $x;
1938 * @param array $x
1943 function _prepareReduce($x, $n, $mode) argument
1946 return $this->_prepMontgomery($x, $n);
1948 return $this->_reduce($x, $n, $mode);
1956 * @param array $x
1962 function _multiplyReduce($x, $y, $n, $mode) argument
1965 return $this->_montgomeryMultiply($x, $y, $n);
1967 $temp = $this->_multiply($x, false, $y, false);
1976 * @param array $x
1981 function _squareReduce($x, $n, $mode) argument
1984 return $this->_montgomeryMultiply($x, $x, $n);
1986 return $this->_reduce($this->_square($x), $n, $mode);
2124 * @param array $x
2128 function _regularBarrett($x, $n) argument
2137 if (count($x) > 2 * $n_length) {
2140 $lhs->value = $x;
2160 $temp = array_slice($x, $n_length - 1);
2167 $result = array_slice($x, 0, $n_length + 1);
2277 * @param array $x
2281 function _montgomery($x, $n) argument
2290 $cache[self::VARIABLE][] = $x;
2296 $result = array(self::VALUE => $x);
2324 * @param array $x
2329 function _montgomeryMultiply($x, $y, $m) argument
2331 $temp = $this->_multiply($x, false, $y, false);
2350 $n = max(count($x), count($y), count($m));
2351 $x = array_pad($x, $n, 0);
2356 $temp = $a[self::VALUE][0] + $x[$i] * $y[0];
2360 …$temp = $this->_add($this->_regularMultiply(array($x[$i]), $y), false, $this->_regularMultiply(arr…
2376 * @param array $x
2380 function _prepMontgomery($x, $n) argument
2383 $lhs->value = array_merge($this->_array_repeat(0, count($n)), $x);
2414 * @param array $x
2417 function _modInverse67108864($x) // 2**26 == 67,108,864 argument
2419 $x = -$x[0];
2420 $result = $x & 0x3; // x**-1 mod 2**2
2421 $result = ($result * (2 - $x * $result)) & 0xF; // x**-1 mod 2**4
2422 $result = ($result * (2 - ($x & 0xFF) * $result)) & 0xFF; // x**-1 mod 2**8
2423 $result = ($result * ((2 - ($x & 0xFFFF) * $result) & 0xFFFF)) & 0xFFFF; // x**-1 mod 2**16
2424 …$result = fmod($result * (2 - fmod($x * $result, self::$baseFull)), self::$baseFull); // x**-1 mod…
2486 $x = $x->compare($zero) < 0 ? $x->add($n) : $x;
2488 … return $this->compare($zero) < 0 ? $this->_normalize($n->subtract($x)) : $this->_normalize($x);
2567 $x = $this->copy();
2571 while (!(($x->value[0] & 1)|| ($y->value[0] & 1))) {
2572 $x->_rshift(1);
2577 $u = $x->copy();
2593 $b = $b->subtract($x);
2603 $d = $d->subtract($x);
2761 function equals($x) argument
2765 return gmp_cmp($this->value, $x->value) == 0;
2767 return $this->value === $x->value && $this->is_negative == $x->is_negative;
2801 function bitwise_and($x) argument
2806 $temp->value = gmp_and($this->value, $x->value);
2811 $right = $x->toBytes();
2823 $length = min(count($x->value), count($this->value));
2828 $result->value[$i]&= $x->value[$i];
2842 function bitwise_or($x) argument
2847 $temp->value = gmp_or($this->value, $x->value);
2852 $right = $x->toBytes();
2862 $length = max(count($this->value), count($x->value));
2865 $x->value = array_pad($x->value, $length, 0);
2868 $result->value[$i]|= $x->value[$i];
2882 function bitwise_xor($x) argument
2887 $temp->value = gmp_xor(gmp_abs($this->value), gmp_abs($x->value));
2891 $right = $x->toBytes();
2901 $length = max(count($this->value), count($x->value));
2905 $x->value = array_pad($x->value, $length, 0);
2908 $result->value[$i]^= $x->value[$i];
3248 $x = $this->random($min, $max);
3253 $p->value = gmp_nextprime($x->value);
3259 if (!$min->equals($x)) {
3260 $x = $x->subtract($one);
3263 return $x->randomPrime($min, $x);
3266 if ($x->equals($two)) {
3267 return $x;
3270 $x->_make_odd();
3271 if ($x->compare($max) > 0) {
3276 $x = $min->copy();
3277 $x->_make_odd();
3280 $initial_x = $x->copy();
3287 if ($x->isPrime()) {
3288 return $x;
3291 $x = $x->add($two);
3293 if ($x->compare($max) > 0) {
3294 $x = $min->copy();
3295 if ($x->equals($two)) {
3296 return $x;
3298 $x->_make_odd();
3301 if ($x->equals($initial_x)) {
3652 * @param string $x (by reference)
3657 function _base256_lshift(&$x, $shift) argument
3667 for ($i = strlen($x) - 1; $i >= 0; --$i) {
3668 $temp = ord($x[$i]) << $shift | $carry;
3669 $x[$i] = chr($temp);
3673 $x = $carry . $x . str_repeat(chr(0), $num_bytes);
3681 * @param string $x (by referenc)
3686 function _base256_rshift(&$x, $shift) argument
3689 $x = ltrim($x, chr(0));
3698 $start = $num_bytes > strlen($x) ? -strlen($x) : -$num_bytes;
3699 $remainder = substr($x, $start);
3700 $x = substr($x, 0, -$num_bytes);
3705 for ($i = 0; $i < strlen($x); ++$i) {
3706 $temp = (ord($x[$i]) >> $shift) | $carry;
3707 $carry = (ord($x[$i]) << $carry_shift) & 0xFF;
3708 $x[$i] = chr($temp);
3710 $x = ltrim($x, chr(0));
3723 * @param int $x
3727 function _int2bytes($x) argument
3729 return ltrim(pack('N', $x), chr(0));
3735 * @param string $x
3739 function _bytes2int($x) argument
3741 $temp = unpack('Nint', str_pad($x, 4, chr(0), STR_PAD_LEFT));
3774 * @param int $x
3778 function _safe_divide($x, $y) argument
3781 return (int) ($x / $y);
3785 return ($x - ($x % $y)) / $y;