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


PHP gmp_intval函数代码示例

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


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

示例1: centsValue

 /**
  * @return integer Or string, if the number is too big.
  */
 public function centsValue()
 {
     if (gmp_cmp(gmp_abs(gmp_init($this->cents, 10)), PHP_INT_MAX) > 0) {
         return $this->cents;
     }
     return gmp_intval(gmp_init($this->cents, 10));
 }
开发者ID:adispartadev,项目名称:money-math-php,代码行数:10,代码来源:Decimal2.php

示例2: sumT

function sumT($n)
{
    if (gmp_intval($n) == 1) {
        return gmp_init(1);
    }
    return gmp_add(gmp_sub(gmp_pow($n, 2), gmp_pow(gmp_init(gmp_intval($n) - 1), 2)), sumT(gmp_init(gmp_intval($n) - 1)));
    //return gmp_mod(gmp_add(gmp_sub(gmp_mod(gmp_pow($n, 2), '1000000007'), gmp_mod(gmp_pow(gmp_init(gmp_intval($n)-1), 2), '1000000007')), sumT(gmp_init(gmp_intval($n)-1))), '1000000007');
}
开发者ID:baotroy,项目名称:chal,代码行数:8,代码来源:index.php

示例3: getResult

 public function getResult($num)
 {
     // init
     $prime = 1;
     for ($i = 0; $i < $num; $i++) {
         $prime = gmp_nextprime($prime);
     }
     return gmp_intval($prime);
 }
开发者ID:alegriaghost,项目名称:project_euler,代码行数:9,代码来源:p007.php

示例4: GetValue

 /**
  * This will return either the integer value of the number or the string value
  * (if the integer value is too large). Use this when you prefer to receive
  * an integer, but you also don't want the number to be rounded down to the
  * maximum integer size if it is too large.
  *
  * @return string || int
  */
 public function GetValue()
 {
     $comparison = gmp_cmp($this->number, $this->int_max);
     if ($comparison > 0) {
         return gmp_strval($this->number);
     } else {
         return gmp_intval($this->number);
     }
 }
开发者ID:drmyersii,项目名称:numbers,代码行数:17,代码来源:NumberW.php

示例5: irand

 function irand($min, $max = null)
 {
     if (is_null($max)) {
         $max = $min;
         $min = 0;
     }
     $this->next();
     return gmp_intval(gmp_mod(gmp_init('0x' . $this->context), gmp_init($max - $min))) + $min;
 }
开发者ID:nyan-cat,项目名称:easyweb,代码行数:9,代码来源:generator.php

示例6: encodeSFixed64

 /**
  * {@inheritdoc}
  */
 public function encodeSFixed64($sFixed64)
 {
     $value = $this->is32Bit ? gmp_and($sFixed64, '0x0ffffffffffffffff') : gmp_init(sprintf('%u', $sFixed64));
     $bytes = '';
     for ($i = 0; $i < 8; ++$i) {
         $bytes .= chr(gmp_intval(gmp_and($value, $this->gmp_xff)));
         $value = gmp_div_q($value, $this->gmp_x100);
     }
     return $bytes;
 }
开发者ID:protobuf-php,项目名称:protobuf,代码行数:13,代码来源:GmpNegativeEncoder.php

示例7: testPutTAGLong

 /**
  * @dataProvider providerTestTAGLong
  */
 public function testPutTAGLong($value)
 {
     $fPtr = fopen($this->vFile->url(), 'wb');
     // 32-bit longs seem to be too long for pack() on 32-bit machines. Split into 4x16-bit instead.
     $quarters[0] = gmp_div(gmp_and($value, '0xFFFF000000000000'), gmp_pow(2, 48));
     $quarters[1] = gmp_div(gmp_and($value, '0x0000FFFF00000000'), gmp_pow(2, 32));
     $quarters[2] = gmp_div(gmp_and($value, '0x00000000FFFF0000'), gmp_pow(2, 16));
     $quarters[3] = gmp_and($value, '0xFFFF');
     $binary = pack('nnnn', gmp_intval($quarters[0]), gmp_intval($quarters[1]), gmp_intval($quarters[2]), gmp_intval($quarters[3]));
     $this->dataHandler->putTAGLong($fPtr, $value);
     $this->assertSame($binary, $this->vFile->getContent());
 }
开发者ID:rickselby,项目名称:nbt,代码行数:15,代码来源:DataHandlerLong32Test.php

示例8: decode

 /**
  * Decode an integer.
  *
  * @param  int $value
  * @return int
  */
 public function decode($value)
 {
     if (!is_numeric($value)) {
         throw new InvalidArgumentException('Argument should be an integer');
     }
     switch (static::$mode) {
         case static::MODE_GMP:
             return gmp_intval(gmp_mul((int) $value ^ $this->xor, $this->inverse)) & static::MAX_INT;
         default:
             return ((int) $value ^ $this->xor) * $this->inverse & static::MAX_INT;
     }
 }
开发者ID:vienis,项目名称:optimus,代码行数:18,代码来源:Optimus.php

示例9: getGCD

 public static function getGCD($numberA, $numberB)
 {
     if (!self::isInteger($numberA) | !self::isInteger($numberB)) {
         throw new \InvalidArgumentException("GCD number must be an integer");
     }
     if (function_exists("gmp_gcd")) {
         return gmp_intval(gmp_gcd($numberA, $numberB));
     }
     if ($numberA == 0 || $numberB == 0) {
         return max(abs($numberA), abs($numberB));
     }
     $r = $numberA % $numberB;
     return $r != 0 ? self::getGCD($numberB, $r) : abs($numberB);
 }
开发者ID:thelia,项目名称:math-tools,代码行数:14,代码来源:GCD.php

示例10: base58_encode

function base58_encode($string)
{
    $table = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
    $long_value = gmp_init(bin2hex($string), 16);
    $result = '';
    while (gmp_cmp($long_value, 58) > 0) {
        list($long_value, $mod) = gmp_div_qr($long_value, 58);
        $result .= $table[gmp_intval($mod)];
    }
    $result .= $table[gmp_intval($long_value)];
    for ($nPad = 0; $string[$nPad] == ""; ++$nPad) {
    }
    return str_repeat($table[0], $nPad) . strrev($result);
}
开发者ID:kkirsche,项目名称:Etcetera,代码行数:14,代码来源:bitcoin.php

示例11: convertFractions

 public function convertFractions(array $number)
 {
     $target = gmp_init($this->target->getRadix());
     $dividend = $this->getDecimal($number);
     $divisor = $this->getDecimal([$this->source->getDigit(1)] + array_fill(1, max(count($number), 1), $this->source->getDigit(0)));
     $digits = $this->getFractionDigitCount(count($number));
     $zero = gmp_init('0');
     $result = [];
     for ($i = 0; $i < $digits && gmp_cmp($dividend, $zero) > 0; $i++) {
         list($digit, $dividend) = gmp_div_qr(gmp_mul($dividend, $target), $divisor);
         $result[] = gmp_intval($digit);
     }
     return $this->target->getDigits(empty($result) ? [0] : $result);
 }
开发者ID:riimu,项目名称:kit-baseconversion,代码行数:14,代码来源:DecimalConverter.php

示例12: totalPages

 public function totalPages()
 {
     $remainder = gmp_div_r(count($this->items_array), $this->items_x_page);
     $quotient = gmp_intval(gmp_div_q(count($this->items_array), $this->items_x_page));
     if ($quotient > 0) {
         if ($remainder > 0) {
             $this->total_pages = $quotient + 1;
         } else {
             $this->total_pages = $quotient;
         }
     } else {
         $this->total_pages = 1;
     }
     return $this->total_pages;
 }
开发者ID:MaikelSC,项目名称:mmelectric-website,代码行数:15,代码来源:Paginate.php

示例13: __construct

 /**
  * @param int $nominator
  * @param int $denominator
  */
 public function __construct($nominator, $denominator = 1)
 {
     if ($nominator == 0) {
         $denominator = 1;
     } else {
         if (function_exists('gmp_gcd')) {
             $gcd = gmp_intval(gmp_gcd((string) $nominator, (string) $denominator));
             $nominator /= $gcd;
             $denominator /= $gcd;
         } else {
             if ($nominator / $denominator == (int) ($nominator / $denominator)) {
                 $nominator = $nominator / $denominator;
                 $denominator = 1;
             }
         }
     }
     $this->denominator = $denominator;
     $this->nominator = $nominator;
 }
开发者ID:groupcash,项目名称:php,代码行数:23,代码来源:Fraction.php

示例14: encodeBase58

 /**
  * Encode a binary string to base58
  *
  * @param $binary
  * @return string
  * @throws \Exception
  */
 protected function encodeBase58($binary_bitcoin_address)
 {
     $size = strlen($binary_bitcoin_address);
     if ($size == 0) {
         return '';
     }
     $orig = $binary_bitcoin_address;
     $decimal = gmp_import($binary_bitcoin_address);
     $return = "";
     while (gmp_cmp($decimal, 0) > 0) {
         list($decimal, $rem) = gmp_div_qr($decimal, 58);
         $return = $return . self::$BASE_58_CHARS[gmp_intval($rem)];
     }
     $return = strrev($return);
     //leading zeros
     for ($i = 0; $i < $size && $orig[$i] == ""; $i++) {
         $return = "1" . $return;
     }
     return $return;
 }
开发者ID:tokenly,项目名称:swapbot-op-return,代码行数:27,代码来源:AddressConverter.php

示例15: testConstructInitializeGmpValues

 public function testConstructInitializeGmpValues()
 {
     $encoder = new GmpNegativeEncoder();
     $gmp_x00 = $this->getPropertyValue($encoder, 'gmp_x00');
     $gmp_x7f = $this->getPropertyValue($encoder, 'gmp_x7f');
     $gmp_x80 = $this->getPropertyValue($encoder, 'gmp_x80');
     $gmp_xff = $this->getPropertyValue($encoder, 'gmp_xff');
     $gmp_x100 = $this->getPropertyValue($encoder, 'gmp_x100');
     $is32Bit = $this->getPropertyValue($encoder, 'is32Bit');
     $this->assertNotNull($gmp_x00);
     $this->assertNotNull($gmp_x7f);
     $this->assertNotNull($gmp_x80);
     $this->assertNotNull($gmp_xff);
     $this->assertNotNull($gmp_x100);
     $this->assertEquals(0, gmp_intval($gmp_x00));
     $this->assertEquals(127, gmp_intval($gmp_x7f));
     $this->assertEquals(128, gmp_intval($gmp_x80));
     $this->assertEquals(255, gmp_intval($gmp_xff));
     $this->assertEquals(256, gmp_intval($gmp_x100));
     $this->assertEquals(BigEndian::is32Bit(), $is32Bit);
 }
开发者ID:protobuf-php,项目名称:protobuf,代码行数:21,代码来源:GmpNegativeEncoderTest.php


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