function afficher_tendance($tendance) { if (gmp_sign($tendance) == 0) { return " ( - place(s) )"; } elseif (gmp_sign($tendance) == 1) { return " (+" . $tendance . " place(s) )"; } else { return " (" . $tendance . " place(s) )"; } }
protected function _encodedContentDER() { $num = gmp_init($this->_number, 10); switch (gmp_sign($num)) { // positive case 1: return self::_encodePositiveInteger($num); // negative // negative case -1: return self::_encodeNegativeInteger($num); } // zero return ""; }
protected function getEncodedValue() { $numericValue = gmp_init($this->value, 10); $contentLength = $this->getContentLength(); if (gmp_sign($numericValue) < 0) { $numericValue = gmp_add($numericValue, gmp_sub(gmp_pow(2, 8 * $contentLength), 1)); $numericValue = gmp_add($numericValue, 1); } $result = ''; for ($shiftLength = ($contentLength - 1) * 8; $shiftLength >= 0; $shiftLength -= 8) { $octet = gmp_strval(gmp_mod($this->rightShift($numericValue, $shiftLength), 256)); $result .= chr($octet); } return $result; }
/** * Divides two BigIntegers. * * Returns an array whose first element contains the quotient and whose second element contains the * "common residue". If the remainder would be positive, the "common residue" and the remainder are the * same. If the remainder would be negative, the "common residue" is equal to the sum of the remainder * and the divisor. * * Here's a quick 'n dirty example: * <code> * <?php * include('Math/BigInteger.php'); * * $a = new Math_BigInteger('10'); * $b = new Math_BigInteger('20'); * * list($quotient,$remainder) = $a->divide($b); * * echo $quotient->toString(); // outputs 0 * echo "\r\n"; * echo $remainder->toString(); // outputs 10 * ?> * </code> * * @param Math_BigInteger $y * @return Array * @access public * @internal This function is based off of {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=9 HAC 14.20} * with a slight variation due to the fact that this script, initially, did not support negative numbers. Now, * it does, but I don't want to change that which already works. */ function divide($y) { switch (MATH_BIGINTEGER_MODE) { case MATH_BIGINTEGER_MODE_GMP: $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); list($quotient->value, $remainder->value) = gmp_div_qr($this->value, $y->value); if (gmp_sign($remainder->value) < 0) { $remainder->value = gmp_add($remainder->value, gmp_abs($y->value)); } return array($quotient, $remainder); case MATH_BIGINTEGER_MODE_BCMATH: $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); $quotient->value = bcdiv($this->value, $y->value); $remainder->value = bcmod($this->value, $y->value); if ($remainder->value[0] == '-') { $remainder->value = bcadd($remainder->value, $y->value[0] == '-' ? substr($y->value, 1) : $y->value); } return array($quotient, $remainder); } $x = $this->_copy(); $y = $y->_copy(); $x_sign = $x->is_negative; $y_sign = $y->is_negative; $x->is_negative = $y->is_negative = false; $diff = $x->compare($y); if (!$diff) { $temp = new Math_BigInteger(); $temp->value = array(1); $temp->is_negative = $x_sign != $y_sign; return array($temp, new Math_BigInteger()); } if ($diff < 0) { // if $x is negative, "add" $y. if ($x_sign) { $x = $y->subtract($x); } return array(new Math_BigInteger(), $x); } // normalize $x and $y as described in HAC 14.23 / 14.24 // (incidently, i haven't been able to find a definitive example showing that this // results in worth-while speedup, but whatever) $msb = $y->value[count($y->value) - 1]; for ($shift = 0; !($msb & 0x2000000); $shift++) { $msb <<= 1; } $x->_lshift($shift); $y->_lshift($shift); $x_max = count($x->value) - 1; $y_max = count($y->value) - 1; $quotient = new Math_BigInteger(); $quotient->value = $this->_array_repeat(0, $x_max - $y_max + 1); // $temp = $y << ($x_max - $y_max-1) in base 2**26 $temp = new Math_BigInteger(); $temp->value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y->value); while ($x->compare($temp) >= 0) { // calculate the "common residue" $quotient->value[$x_max - $y_max]++; $x = $x->subtract($temp); $x_max = count($x->value) - 1; } for ($i = $x_max; $i >= $y_max + 1; $i--) { $x_value = array($x->value[$i], $i > 0 ? $x->value[$i - 1] : 0, $i - 1 > 0 ? $x->value[$i - 2] : 0); $y_value = array($y->value[$y_max], $y_max > 0 ? $y_max - 1 : 0); $q_index = $i - $y_max - 1; if ($x_value[0] == $y_value[0]) { $quotient->value[$q_index] = 0x3ffffff; } else { $quotient->value[$q_index] = floor(($x_value[0] * 0x4000000 + $x_value[1]) / $y_value[0]); } $temp = new Math_BigInteger(); $temp->value = array($y_value[1], $y_value[0]); $lhs = new Math_BigInteger(); $lhs->value = array($quotient->value[$q_index]); $lhs = $lhs->multiply($temp); $rhs = new Math_BigInteger(); $rhs->value = array($x_value[2], $x_value[1], $x_value[0]); while ($lhs->compare($rhs) > 0) { $quotient->value[$q_index]--; $lhs = new Math_BigInteger(); $lhs->value = array($quotient->value[$q_index]); $lhs = $lhs->multiply($temp); } $corrector = new Math_BigInteger(); $temp = new Math_BigInteger(); $corrector->value = $temp->value = $this->_array_repeat(0, $q_index); $temp->value[] = $quotient->value[$q_index]; $temp = $temp->multiply($y); if ($x->compare($temp) < 0) { $corrector->value[] = 1; $x = $x->add($corrector->multiply($y)); $quotient->value[$q_index]--; } $x = $x->subtract($temp); $x_max = count($x->value) - 1; } // unnormalize the remainder $x->_rshift($shift); $quotient->is_negative = $x_sign != $y_sign; // calculate the "common residue", if appropriate if ($x_sign) { $y->_rshift($shift); $x = $y->subtract($x); } return array($quotient->_normalize(), $x); }
/** * Returns the sign of a Math_Integer number * if $i1 > 0, returns +1, * if $i1 == 0, returns +0, * if $i1 < 0, returns -1, * * @param object Math_Integer $int1 * @return mixed and integer on success, PEAR_Error otherwise * @access public */ function &sign(&$int1) { /*{{{*/ if (PEAR::isError($err = Math_IntegerOp::_validInt($int1))) { return $err; } switch (MATH_INTLIB) { /*{{{*/ case 'gmp': return gmp_sign($int1->getValue()); break; case 'bcmath': case 'std': $tmp = $int1->getValue(); if ($tmp > 0) { return 1; } elseif ($tmp < 0) { return -1; } else { // $tmp == 0 return 0; } break; } /*}}}*/ }
$a = gmp_init("0xfd"); echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n"; gmp_setbit($a, 1); // index starts at 0 echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n"; $a = gmp_init("0xff"); echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n"; gmp_setbit($a, 0, false); // clear bit at index 0 echo gmp_strval($a), ' -> 0b', gmp_strval($a, 2), "\n"; // gmp_sign echo gmp_sign("500") . "\n"; // positive echo gmp_sign("-500") . "\n"; // negative echo gmp_sign("0") . "\n"; // zero // gmp_sqrt $sqrt1 = gmp_sqrt("9"); $sqrt2 = gmp_sqrt("7"); $sqrt3 = gmp_sqrt("1524157875019052100"); echo gmp_strval($sqrt1) . "\n"; echo gmp_strval($sqrt2) . "\n"; echo gmp_strval($sqrt3) . "\n"; // gmp_sqrtrem list($sqrt1, $sqrt1rem) = gmp_sqrtrem("9"); list($sqrt2, $sqrt2rem) = gmp_sqrtrem("7"); list($sqrt3, $sqrt3rem) = gmp_sqrtrem("1048576"); echo gmp_strval($sqrt1) . ", " . gmp_strval($sqrt1rem) . "\n"; echo gmp_strval($sqrt2) . ", " . gmp_strval($sqrt2rem) . "\n"; echo gmp_strval($sqrt3) . ", " . gmp_strval($sqrt3rem) . "\n";
<?php $arr = ['0-3 months', '9-12 months', '3-6 months', '6-9 months', '12-18 months', '18-24 months']; print_r($arr); echo "\n\n\n"; usort($arr, function ($e1, $e2) { preg_match('/^(\\d+)-(\\d+)/', $e1, $e1Keys); preg_match('/^(\\d+)-(\\d+)/', $e2, $e2Keys); if ($e1Keys[0] != $e2Keys[0]) { return gmp_sign($e1Keys[1] - $e2Keys[1]); } return gmp_sign($e1Keys[0] - $e2Keys[0]); }); print_r($arr);
<?php var_dump(gmp_sign(-1)); var_dump(gmp_sign(1)); var_dump(gmp_sign(0)); var_dump(gmp_sign("123718235123123")); var_dump(gmp_sign("-34535345345")); var_dump(gmp_sign("+34534573457345")); $n = gmp_init("098909878976786545"); var_dump(gmp_sign($n)); var_dump(gmp_sign($n, $n)); var_dump(gmp_sign(array())); var_dump(gmp_sign()); echo "Done\n";
/** * To be able to paginate results, I have taken out the 'find' call and made it * its own function. It returns an array containing the result set, and the * total number of results, useful for pagination */ public static function find($args = array()) { $default = array('query' => array(), 'fields' => array()); $args = array_merge($default, $args); $args['query'] = static::_convertQuery($args['query']); // Add projection keys for $meta sort entries if (isset($args['sort']) && is_array($args['sort'])) { foreach ($args['sort'] as $fld => $entry) { if (is_array($entry) && isset($entry['$meta'])) { $args['fields'][$fld] = $entry; } } } $cursor = static::getCollection()->find($args['query'], $args['fields']); //$count = $cursor->count(); if (isset($args['sort']) && is_array($args['sort'])) { // Convert 'asc' and 'desc' to 1 and -1 foreach ($args['sort'] as &$val) { // Skip metadata sorting if (is_array($val)) { continue; } $val = strtolower($val); if ($val == 'asc') { $val = 1; } else { if ($val == 'desc') { $val = -1; } else { $val = gmp_sign($val); } } } $cursor->sort($args['sort']); } // Apply pagination if (isset($args['offset']) || isset($args['limit'])) { $offset = @intval($args['offset']); $limit = @intval($args['limit']); if ($offset > 0) { $cursor->skip($offset); } if ($limit > 0) { $cursor->limit($limit); } } // Do not remove the 'result' entry. It is important for the findPaginated function // If removed here, fix findPaginated to have a 'result' array entry $ret = array('result' => array_map(array(get_called_class(), 'map'), iterator_to_array($cursor))); return $ret; }
/** * This method returns whether the operand is a negative number. * * @access public * @static * @param IInteger\Type $x the object to be evaluated * @return IBool\Type whether the operand is a negative * number */ public static function isNegative(IInteger\Type $x) : IBool\Type { return IBool\Type::box(gmp_sign($x->unbox()) == -1); }
/** * Is this number equal to zero? * @return boolean */ public function isZero() { return gmp_sign($this->value['real']->numerator()->gmp()) == 0 && gmp_sign($this->value['imaginary']->numerator()->gmp()) == 0; }
<?php // array_udiff.php require "arrays.php"; $tally = 0; $diff = array_udiff($first, $second, function ($e1, $e2) use(&$tally) { $comparison = gmp_sign($e1["value"] - $e2["value"]); printf('(%d) $e1: %s<br>$e2: %s; comparison: %d<hr>', ++$tally, json_encode($e1), json_encode($e2), $comparison); return $comparison; }); echo "<pre>"; var_dump($diff); echo "</pre>";
/** * return seconds to hh:mm * * @param integer $t seconds * @param string $format * * @return string */ function formatTime($t, $format = 'hh:mm') { if (function_exists('gmp_sign')) { $sign = gmp_sign($t); } else { $sign = $t > 0 ? 1 : $t == 0 ? 0 : -1; } $s = abs($t) % 60; $m = abs($t) / 60 % 60; $h = floor(abs($t) / 3600) * $sign; $d = floor(abs($t) / 3600 / 24); switch ($format) { case 'd hh:mm:ss': $h = floor(abs($t) / 3600) % 24 * $sign; return sprintf("%dд %02d:%02d:%02d", $d, $h, $m, $s); case 'd hh:mm': $h = floor(abs($t) / 3600) % 24 * $sign; return sprintf("%dд %02d:%02d", $d, $h, $m); case 'hh:mm:ss': return sprintf("%02d:%02d:%02d", $h, $m, $s); case 'hh:mm': default: return sprintf("%02d:%02d", $h, $m); } }
/** * Return the sign of this number * -1 if < 0 * 0 if == 0 * 1 if > 0 * * @return int */ public function sign() { return gmp_sign($this->value); }
public function divide($y) { switch (MATH_BIGINTEGER_MODE) { case MATH_BIGINTEGER_MODE_GMP: $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); list($quotient->value, $remainder->value) = gmp_div_qr($this->value, $y->value); if (gmp_sign($remainder->value) < 0) { $remainder->value = gmp_add($remainder->value, gmp_abs($y->value)); } return array($this->_normalize($quotient), $this->_normalize($remainder)); case MATH_BIGINTEGER_MODE_BCMATH: $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); $quotient->value = bcdiv($this->value, $y->value, 0); $remainder->value = bcmod($this->value, $y->value); if ($remainder->value[0] == '-') { $remainder->value = bcadd($remainder->value, $y->value[0] == '-' ? substr($y->value, 1) : $y->value, 0); } return array($this->_normalize($quotient), $this->_normalize($remainder)); } if (count($y->value) == 1) { list($q, $r) = $this->_divide_digit($this->value, $y->value[0]); $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); $quotient->value = $q; $remainder->value = array($r); $quotient->is_negative = $this->is_negative != $y->is_negative; return array($this->_normalize($quotient), $this->_normalize($remainder)); } static $zero; if (!isset($zero)) { $zero = new Math_BigInteger(); } $x = $this->copy(); $y = $y->copy(); $x_sign = $x->is_negative; $y_sign = $y->is_negative; $x->is_negative = $y->is_negative = false; $diff = $x->compare($y); if (!$diff) { $temp = new Math_BigInteger(); $temp->value = array(1); $temp->is_negative = $x_sign != $y_sign; return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger())); } if ($diff < 0) { if ($x_sign) { $x = $y->subtract($x); } return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x)); } $msb = $y->value[count($y->value) - 1]; for ($shift = 0; !($msb & MATH_BIGINTEGER_MSB); ++$shift) { $msb <<= 1; } $x->_lshift($shift); $y->_lshift($shift); $y_value =& $y->value; $x_max = count($x->value) - 1; $y_max = count($y->value) - 1; $quotient = new Math_BigInteger(); $quotient_value =& $quotient->value; $quotient_value = $this->_array_repeat(0, $x_max - $y_max + 1); static $temp; static $lhs; static $rhs; if (!isset($temp)) { $temp = new Math_BigInteger(); $lhs = new Math_BigInteger(); $rhs = new Math_BigInteger(); } $temp_value =& $temp->value; $rhs_value =& $rhs->value; $temp_value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y_value); while (0 <= $x->compare($temp)) { ++$quotient_value[$x_max - $y_max]; $x = $x->subtract($temp); $x_max = count($x->value) - 1; } for ($i = $x_max; $y_max + 1 <= $i; --$i) { $x_value =& $x->value; $x_window = array(isset($x_value[$i]) ? $x_value[$i] : 0, isset($x_value[$i - 1]) ? $x_value[$i - 1] : 0, isset($x_value[$i - 2]) ? $x_value[$i - 2] : 0); $y_window = array($y_value[$y_max], 0 < $y_max ? $y_value[$y_max - 1] : 0); $q_index = $i - $y_max - 1; if ($x_window[0] == $y_window[0]) { $quotient_value[$q_index] = MATH_BIGINTEGER_MAX_DIGIT; } else { $quotient_value[$q_index] = (int) ($x_window[0] * MATH_BIGINTEGER_BASE_FULL + $x_window[1]) / $y_window[0]; } $temp_value = array($y_window[1], $y_window[0]); $lhs->value = array($quotient_value[$q_index]); $lhs = $lhs->multiply($temp); $rhs_value = array($x_window[2], $x_window[1], $x_window[0]); while (0 < $lhs->compare($rhs)) { --$quotient_value[$q_index]; $lhs->value = array($quotient_value[$q_index]); $lhs = $lhs->multiply($temp); } $adjust = $this->_array_repeat(0, $q_index); $temp_value = array($quotient_value[$q_index]); $temp = $temp->multiply($y); $temp_value =& $temp->value; $temp_value = array_merge($adjust, $temp_value); $x = $x->subtract($temp); if ($x->compare($zero) < 0) { $temp_value = array_merge($adjust, $y_value); $x = $x->add($temp); --$quotient_value[$q_index]; } $x_max = count($x_value) - 1; } $x->_rshift($shift); $quotient->is_negative = $x_sign != $y_sign; if ($x_sign) { $y->_rshift($shift); $x = $y->subtract($x); } return array($this->_normalize($quotient), $this->_normalize($x)); }
/** * Arithmetic right shift * @param resource|int|string $g * @param int $shift number of bits to shift right * @return resource $g shifted right $shift bits */ static function shift_right($g, $shift) { if (0 == $shift) { return $g; } if (0 <= gmp_sign($g)) { $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift)); } else { $g = gmp_and($g, self::gmp_0xfs()); $m = gmp_div($g, gmp_pow(self::gmp_2(), $shift)); $m = gmp_and($m, self::gmp_0xfs()); for ($i = 63; $i >= 63 - $shift; $i--) { gmp_setbit($m, $i); } $m = gmp_neg(gmp_add(gmp_and(gmp_com($m), self::gmp_0xfs()), self::gmp_1())); } return $m; }
public function deterministicGenerateK($message, $key) { // key in hex, message as it is // RFC6979 $hash = $message; $k = "0000000000000000000000000000000000000000000000000000000000000000"; $v = "0101010101010101010101010101010101010101010101010101010101010101"; // step D $k = hash_hmac('sha256', hex2bin($v) . hex2bin("00") . hex2bin($key) . hex2bin($hash), hex2bin($k)); // step E $v = hash_hmac('sha256', hex2bin($v), hex2bin($k)); // step F $k = hash_hmac('sha256', hex2bin($v) . hex2bin("01") . hex2bin($key) . hex2bin($hash), hex2bin($k)); // step G $v = hash_hmac('sha256', hex2bin($v), hex2bin($k)); // H2b $h2b = hash_hmac('sha256', hex2bin($v), hex2bin($k)); $tNum = gmp_init($h2b, 16); // step H3 while (gmp_sign($tNum) <= 0 || gmp_cmp($tNum, $this->n) >= 0) { $k = hash_hmac('sha256', hex2bin($v) . hex2bin("00"), hex2bin($k)); $v = hash_hmac('sha256', hex2bin($v), hex2bin($k)); $tNum = gmp_init($v, 16); } return gmp_strval($tNum, 16); }
/** * Divides two BigIntegers. * * Returns an array whose first element contains the quotient and whose second element contains the * "common residue". If the remainder would be positive, the "common residue" and the remainder are the * same. If the remainder would be negative, the "common residue" is equal to the sum of the remainder * and the divisor (basically, the "common residue" is the first positive modulo). * * Here's an example: * <code> * <?php * include 'Math/BigInteger.php'; * * $a = new Math_BigInteger('10'); * $b = new Math_BigInteger('20'); * * list($quotient, $remainder) = $a->divide($b); * * echo $quotient->toString(); // outputs 0 * echo "\r\n"; * echo $remainder->toString(); // outputs 10 * ?> * </code> * * @param Math_BigInteger $y * @return array * @access public * @internal This function is based off of {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=9 HAC 14.20}. */ function divide($y) { switch (MATH_BIGINTEGER_MODE) { case MATH_BIGINTEGER_MODE_GMP: $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); list($quotient->value, $remainder->value) = gmp_div_qr($this->value, $y->value); if (gmp_sign($remainder->value) < 0) { $remainder->value = gmp_add($remainder->value, gmp_abs($y->value)); } return array($this->_normalize($quotient), $this->_normalize($remainder)); case MATH_BIGINTEGER_MODE_BCMATH: $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); $quotient->value = bcdiv($this->value, $y->value, 0); $remainder->value = bcmod($this->value, $y->value); if ($remainder->value[0] == '-') { $remainder->value = bcadd($remainder->value, $y->value[0] == '-' ? substr($y->value, 1) : $y->value, 0); } return array($this->_normalize($quotient), $this->_normalize($remainder)); } if (count($y->value) == 1) { list($q, $r) = $this->_divide_digit($this->value, $y->value[0]); $quotient = new Math_BigInteger(); $remainder = new Math_BigInteger(); $quotient->value = $q; $remainder->value = array($r); $quotient->is_negative = $this->is_negative != $y->is_negative; return array($this->_normalize($quotient), $this->_normalize($remainder)); } static $zero; if (!isset($zero)) { $zero = new Math_BigInteger(); } $x = $this->copy(); $y = $y->copy(); $x_sign = $x->is_negative; $y_sign = $y->is_negative; $x->is_negative = $y->is_negative = false; $diff = $x->compare($y); if (!$diff) { $temp = new Math_BigInteger(); $temp->value = array(1); $temp->is_negative = $x_sign != $y_sign; return array($this->_normalize($temp), $this->_normalize(new Math_BigInteger())); } if ($diff < 0) { // if $x is negative, "add" $y. if ($x_sign) { $x = $y->subtract($x); } return array($this->_normalize(new Math_BigInteger()), $this->_normalize($x)); } // normalize $x and $y as described in HAC 14.23 / 14.24 $msb = $y->value[count($y->value) - 1]; for ($shift = 0; !($msb & MATH_BIGINTEGER_MSB); ++$shift) { $msb <<= 1; } $x->_lshift($shift); $y->_lshift($shift); $y_value =& $y->value; $x_max = count($x->value) - 1; $y_max = count($y->value) - 1; $quotient = new Math_BigInteger(); $quotient_value =& $quotient->value; $quotient_value = $this->_array_repeat(0, $x_max - $y_max + 1); static $temp, $lhs, $rhs; if (!isset($temp)) { $temp = new Math_BigInteger(); $lhs = new Math_BigInteger(); $rhs = new Math_BigInteger(); } $temp_value =& $temp->value; $rhs_value =& $rhs->value; // $temp = $y << ($x_max - $y_max-1) in base 2**26 $temp_value = array_merge($this->_array_repeat(0, $x_max - $y_max), $y_value); while ($x->compare($temp) >= 0) { // calculate the "common residue" ++$quotient_value[$x_max - $y_max]; $x = $x->subtract($temp); $x_max = count($x->value) - 1; } for ($i = $x_max; $i >= $y_max + 1; --$i) { $x_value =& $x->value; $x_window = array(isset($x_value[$i]) ? $x_value[$i] : 0, isset($x_value[$i - 1]) ? $x_value[$i - 1] : 0, isset($x_value[$i - 2]) ? $x_value[$i - 2] : 0); $y_window = array($y_value[$y_max], $y_max > 0 ? $y_value[$y_max - 1] : 0); $q_index = $i - $y_max - 1; if ($x_window[0] == $y_window[0]) { $quotient_value[$q_index] = MATH_BIGINTEGER_MAX_DIGIT; } else { $quotient_value[$q_index] = $this->_safe_divide($x_window[0] * MATH_BIGINTEGER_BASE_FULL + $x_window[1], $y_window[0]); } $temp_value = array($y_window[1], $y_window[0]); $lhs->value = array($quotient_value[$q_index]); $lhs = $lhs->multiply($temp); $rhs_value = array($x_window[2], $x_window[1], $x_window[0]); while ($lhs->compare($rhs) > 0) { --$quotient_value[$q_index]; $lhs->value = array($quotient_value[$q_index]); $lhs = $lhs->multiply($temp); } $adjust = $this->_array_repeat(0, $q_index); $temp_value = array($quotient_value[$q_index]); $temp = $temp->multiply($y); $temp_value =& $temp->value; $temp_value = array_merge($adjust, $temp_value); $x = $x->subtract($temp); if ($x->compare($zero) < 0) { $temp_value = array_merge($adjust, $y_value); $x = $x->add($temp); --$quotient_value[$q_index]; } $x_max = count($x_value) - 1; } // unnormalize the remainder $x->_rshift($shift); $quotient->is_negative = $x_sign != $y_sign; // calculate the "common residue", if appropriate if ($x_sign) { $y->_rshift($shift); $x = $y->subtract($x); } return array($this->_normalize($quotient), $this->_normalize($x)); }
/** * Calcul P2' pour les matchs qui se deroule au plus tard le 16/07/1950 * @param int $p2 * @param int $dbc * @param int $comp * @param int $cmc * @param int $pm * @param int $m1 * @return int */ private static function calculP2PrimeAp16071950($p2, $dbc, $comp, $cmc, $pm, $m1) { $pPrime = $p2 - min(1, ($m1 + 1) / 25) * gmp_sign($dbc) * $comp * $cmc * $pm; return $pPrime; }