当前位置: 首页>>代码示例>>PHP>>正文


PHP gmp_sign函数代码示例

本文整理汇总了PHP中gmp_sign函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_sign函数的具体用法?PHP gmp_sign怎么用?PHP gmp_sign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gmp_sign函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: afficher_tendance

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) )";
    }
}
开发者ID:sbazin1990,项目名称:Prono,代码行数:10,代码来源:classement.php

示例2: _encodedContentDER

 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 "";
 }
开发者ID:sop,项目名称:asn1,代码行数:15,代码来源:Integer.php

示例3: getEncodedValue

 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;
 }
开发者ID:afk11,项目名称:phpasn1,代码行数:15,代码来源:Integer.php

示例4: divide

 /**
  * 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 {
//.........这里部分代码省略.........
开发者ID:thu0ng91,项目名称:jmc,代码行数:101,代码来源:biginteger.php

示例5: switch

 /**
  * 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;
     }
     /*}}}*/
 }
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:36,代码来源:IntegerOp.php

示例6: gmp_init

$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";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php

示例7: print_r

<?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);
开发者ID:JoshuaReneDalley,项目名称:php,代码行数:14,代码来源:usort.php

示例8: var_dump

<?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";
开发者ID:badlamer,项目名称:hhvm,代码行数:14,代码来源:gmp_sign.php

示例9: find

 /**
  * 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;
 }
开发者ID:wthielen,项目名称:zf1e,代码行数:56,代码来源:Mongo.php

示例10: isNegative

 /**
  * 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);
 }
开发者ID:bluesnowman,项目名称:fphp-saber,代码行数:13,代码来源:Module.php

示例11: isZero

 /**
  * 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;
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:8,代码来源:GMPComplexType.php

示例12: array_udiff

<?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>";
开发者ID:JoshuaReneDalley,项目名称:php,代码行数:13,代码来源:array_udiff.php

示例13: formatTime

/**
 * 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);
    }
}
开发者ID:Ailme,项目名称:helper,代码行数:33,代码来源:helper.php

示例14: sign

 /**
  * 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);
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:12,代码来源:GMPIntType.php

示例15: divide

 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);
//.........这里部分代码省略.........
开发者ID:fkssei,项目名称:pigcms10,代码行数:101,代码来源:Math_BigInteger.php


注:本文中的gmp_sign函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。