• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP gmp_div_q函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __construct

 public function __construct($cipher, $key, $taglen)
 {
     $logging = \Plop\Plop::getInstance();
     $this->cipher = mcrypt_module_open($cipher, null, 'ecb', null);
     mcrypt_generic_init($this->cipher, $key, str_repeat("", 16));
     $this->taglen = $taglen;
     $logging->debug('Pre-computing GCM table');
     $H = gmp_init(bin2hex(mcrypt_generic($this->cipher, str_repeat("", 16))), 16);
     $H = str_pad(gmp_strval($H, 2), 128, '0', STR_PAD_LEFT);
     $R = gmp_init('E1000000000000000000000000000000', 16);
     $this->table = array();
     for ($i = 0; $i < 16; $i++) {
         $this->table[$i] = array();
         for ($j = 0; $j < 256; $j++) {
             $V = gmp_init(dechex($j) . str_repeat("00", $i), 16);
             $Z = gmp_init(0);
             for ($k = 0; $k < 128; $k++) {
                 // Compute Z_n+1
                 if ($H[$k]) {
                     $Z = gmp_xor($Z, $V);
                 }
                 // Compute V_n+1
                 $odd = gmp_testbit($V, 0);
                 $V = gmp_div_q($V, 2);
                 if ($odd) {
                     $V = gmp_xor($V, $R);
                 }
             }
             $this->table[$i][$j] = pack('H*', str_pad(gmp_strval($Z, 16), 32, 0, STR_PAD_LEFT));
         }
     }
     $logging->debug('Done pre-computing GCM table');
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:33,代码来源:GCM.php


示例2: packLong

 /**
  * Pack a long.
  *
  * If it is a 32bit PHP we suppose that this log is treated by bcmath
  * TODO 32bit
  *
  * @param int|string $value
  *
  * @return string the packed long
  */
 public static function packLong($value)
 {
     if (PHP_INT_SIZE > 4) {
         $value = (int) $value;
         $binaryString = chr($value >> 56 & 0xff) . chr($value >> 48 & 0xff) . chr($value >> 40 & 0xff) . chr($value >> 32 & 0xff) . chr($value >> 24 & 0xff) . chr($value >> 16 & 0xff) . chr($value >> 8 & 0xff) . chr($value & 0xff);
     } else {
         /*
          * To get the two's complement of a binary number,
          * the bits are inverted, or "flipped",
          * by using the bitwise NOT operation;
          * the value of 1 is then added to the resulting value
          */
         $bitString = '';
         $isNegative = $value[0] == '-';
         if (function_exists("bcmod")) {
             //add 1 for the two's complement
             if ($isNegative) {
                 $value = bcadd($value, '1');
             }
             while ($value !== '0') {
                 $bitString = (string) abs((int) bcmod($value, '2')) . $bitString;
                 $value = bcdiv($value, '2');
             }
         } elseif (function_exists("gmp_mod")) {
             //add 1 for the two's complement
             if ($isNegative) {
                 $value = gmp_strval(gmp_add($value, '1'));
             }
             while ($value !== '0') {
                 $bitString = gmp_strval(gmp_abs(gmp_mod($value, '2'))) . $bitString;
                 $value = gmp_strval(gmp_div_q($value, '2'));
             }
         } else {
             while ($value != 0) {
                 list($value, $remainder) = self::str2bin((string) $value);
                 $bitString = $remainder . $bitString;
             }
         }
         //Now do the logical not for the two's complement last phase
         if ($isNegative) {
             $len = strlen($bitString);
             for ($x = 0; $x < $len; $x++) {
                 $bitString[$x] = $bitString[$x] == '1' ? '0' : '1';
             }
         }
         //pad to have 64 bit
         if ($bitString != '' && $isNegative) {
             $bitString = str_pad($bitString, 64, '1', STR_PAD_LEFT);
         } else {
             $bitString = str_pad($bitString, 64, '0', STR_PAD_LEFT);
         }
         $hi = substr($bitString, 0, 32);
         $lo = substr($bitString, 32, 32);
         $hiBin = pack('H*', str_pad(base_convert($hi, 2, 16), 8, 0, STR_PAD_LEFT));
         $loBin = pack('H*', str_pad(base_convert($lo, 2, 16), 8, 0, STR_PAD_LEFT));
         $binaryString = $hiBin . $loBin;
     }
     return $binaryString;
 }
开发者ID:emman-ok,项目名称:PhpOrient,代码行数:69,代码来源:Writer.php


示例3: digit

function digit($n1, $n2, $d)
{
    global $u, $v;
    $u = gmp_div_q($n1, $d);
    $v = gmp_div_q($n2, $d);
    if (gmp_cmp($u, $v) == 0) {
        return $u;
    }
    return false;
}
开发者ID:neoedmund,项目名称:benchmarksgame,代码行数:10,代码来源:pidigits.php-3.php


示例4: 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


示例5: xrecover

 public function xrecover($y)
 {
     $xx = gmp_mul(gmp_sub(gmp_mul($y, $y), 1), $this->inv(gmp_add(gmp_mul(gmp_mul($this->params['d'], $y), $y), 1)));
     $x = gmp_powm($xx, gmp_div_q(gmp_add($this->params['q'], 3), 8), $this->params['q']);
     $t = gmp_mod(gmp_sub(gmp_mul($x, $x), $xx), $this->params['q']);
     if (gmp_cmp($t, 0)) {
         $x = gmp_mod(gmp_mul($x, $this->params['I']), $this->params['q']);
     }
     if (gmp_cmp(gmp_mod($x, 2), 0)) {
         $x = gmp_sub($this->params['q'], $x);
     }
     return $x;
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:13,代码来源:ED25519.php


示例6: number62_encode

/**
 * Назначение: Основные пользовательские функции
 */
function number62_encode($number)
{
    if (preg_match('#^[0-9]+$#iu', $number) == 0) {
        return "";
    }
    $out = "";
    $string = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    do {
        $key = gmp_mod($number, 62);
        $out = $string[$key] . $out;
        $number = gmp_strval(gmp_div_q($number, 62, GMP_ROUND_ZERO));
    } while (gmp_cmp($number, 0) > 0);
    return $out;
}
开发者ID:AlexanderGrom,项目名称:knee,代码行数:17,代码来源:main.php


示例7: 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


示例8: fatorar_raiz_quadrada

function fatorar_raiz_quadrada($numOrig)
{
    $result = '';
    $fatoracao = fatoracao_numeros_primos($numOrig);
    if (is_array($fatoracao) && count($fatoracao) > 0) {
        $resultFatNumero = 0;
        $resultFatRaiz = array();
        foreach ($fatoracao as $fator => $qtd) {
            if ($qtd > 1) {
                $agrupamentoPares = gmp_div_q($qtd, 2);
                // divide por dois, simples, retorna inteiro
                $resultPares = $fator * gmp_strval($agrupamentoPares);
                // os pares são tirados da raiz quadrada, portanto numeros normais no resultado;
                $resultFatNumero = $resultFatNumero > 0 ? $resultFatNumero * $resultPares : $resultPares;
                $restoImpar = gmp_div_r($qtd, 2);
                if ($restoImpar > 0) {
                    $resultFatRaiz[] = "raiz quadrada(" . gmp_strval($fator) . ")";
                }
            } else {
                $resultFatRaiz[] = "raiz quadrada({$fator})";
            }
        }
        if ($resultFatNumero > 0) {
            $result = $resultFatNumero;
        }
        if (count($resultFatRaiz) > 0) {
            $resultFatRaiz = implode(' * ', $resultFatRaiz);
            if ($result != '') {
                // caso exista numerico, multiplicar por este
                $result .= ' * ';
            }
            $result .= $resultFatRaiz;
        }
    } else {
        $result = "<b>{$fatoracao}<b><br>";
    }
    return $result;
}
开发者ID:eduardoabach,项目名称:tools-postgresql,代码行数:38,代码来源:fatoracao_beta.php


示例9: gmp_cmp

$cmp3 = gmp_cmp("1234", "1234");
// equal to
echo "{$cmp1} {$cmp2} {$cmp3}" . "\n";
// gmp_com
$com = gmp_com("1234");
echo gmp_strval($com) . "\n";
// gmp_div_q
$div1 = gmp_div_q("100", "5");
echo gmp_strval($div1) . "\n";
$div2 = gmp_div_q("1", "3");
echo gmp_strval($div2) . "\n";
$div3 = gmp_div_q("1", "3", GMP_ROUND_PLUSINF);
echo gmp_strval($div3) . "\n";
$div4 = gmp_div_q("-1", "4", GMP_ROUND_PLUSINF);
echo gmp_strval($div4) . "\n";
$div5 = gmp_div_q("-1", "4", GMP_ROUND_MINUSINF);
echo gmp_strval($div5) . "\n";
// gmp_div_qr
$a = gmp_init("0x41682179fbf5");
$res = gmp_div_qr($a, "0xDEFE75");
var_dump($res);
printf("Result is: q - %s, r - %s" . PHP_EOL, gmp_strval($res[0]), gmp_strval($res[1]));
// gmp_div_r
$div = gmp_div_r("105", "20");
echo gmp_strval($div) . "\n";
// gmp_div
$div1 = gmp_div("100", "5");
echo gmp_strval($div1) . "\n";
// gmp_divexact
$div1 = gmp_divexact("10", "2");
echo gmp_strval($div1) . "\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php


示例10: getPubKeyWithRS

 public function getPubKeyWithRS($flag, $R, $S, $hash)
 {
     $isCompressed = false;
     if ($flag < 27 || $flag >= 35) {
         return false;
     }
     if ($flag >= 31) {
         $isCompressed = true;
         $flag -= 4;
     }
     $recid = $flag - 27;
     //step 1.1
     $x = null;
     $x = gmp_add(gmp_init($R, 16), gmp_mul($this->n, gmp_div_q(gmp_init($recid, 10), gmp_init(2, 10))));
     //step 1.3
     $y = null;
     if (1 == $flag % 2) {
         $gmpY = $this->calculateYWithX(gmp_strval($x, 16), '02');
         if (null != $gmpY) {
             $y = gmp_init($gmpY, 16);
         }
     } else {
         $gmpY = $this->calculateYWithX(gmp_strval($x, 16), '03');
         if (null != $gmpY) {
             $y = gmp_init($gmpY, 16);
         }
     }
     if (null == $y) {
         return null;
     }
     $Rpt = array('x' => $x, 'y' => $y);
     //step 1.6.1
     //calculate r^-1 (S*Rpt - eG)
     $eG = $this->mulPoint($hash, $this->G);
     $eG['y'] = gmp_mod(gmp_neg($eG['y']), $this->p);
     $SR = $this->mulPoint($S, $Rpt);
     $pubKey = $this->mulPoint(gmp_strval(gmp_invert(gmp_init($R, 16), $this->n), 16), $this->addPoints($SR, $eG));
     $pubKey['x'] = gmp_strval($pubKey['x'], 16);
     $pubKey['y'] = gmp_strval($pubKey['y'], 16);
     while (strlen($pubKey['x']) < 64) {
         $pubKey['x'] = '0' . $pubKey['x'];
     }
     while (strlen($pubKey['y']) < 64) {
         $pubKey['y'] = '0' . $pubKey['y'];
     }
     $derPubKey = $this->getDerPubKeyWithPubKeyPoints($pubKey, $isCompressed);
     if ($this->checkSignaturePoints($derPubKey, $R, $S, $hash)) {
         return $derPubKey;
     } else {
         return false;
     }
 }
开发者ID:hartmantam,项目名称:php-license-system,代码行数:52,代码来源:ECDSA.php


示例11: Div

 public function Div($left, $right)
 {
     return $this->string(gmp_div_q($left, $right));
 }
开发者ID:zae,项目名称:bigmath,代码行数:4,代码来源:Gmp.php


示例12: div

 /**
  * Divides two numbers.
  *
  * @param resource $a The first number
  * @param resource $b The second number
  * @return resource
  */
 public function div($a, $b)
 {
     return gmp_div_q($a, $b);
 }
开发者ID:jordanmanning,项目名称:ezpublish,代码行数:11,代码来源:gmp_library.php


示例13: primeFactors

 /**
  * Return all prime factors of this number
  *
  * The keys (prime factors) will be strings
  * The values (exponents will be integers
  *
  * Adapted from http://www.thatsgeeky.com/2011/03/prime-factoring-with-php/
  *
  * @return array [primeFactor => exponent,...]
  */
 public function primeFactors()
 {
     $number = $this->cloneValue();
     $divisor = 2;
     $zero = gmp_init(0);
     $one = gmp_init(1);
     $dmax = gmp_sqrt($number);
     $factors = array();
     $sieve = array_fill(1, intval(gmp_strval($dmax)), 1);
     do {
         $rFlag = false;
         while (gmp_cmp(gmp_mod($number, $divisor), $zero) == 0) {
             $factors[$divisor] = isset($factors[$divisor]) ? $factors[$divisor] + 1 : 1;
             $number = gmp_div_q($number, $divisor);
             $rFlag = true;
         }
         if ($rFlag) {
             $dmax = gmp_sqrt($number);
         }
         if (gmp_cmp($number, $one) > 0) {
             for ($i = $divisor; gmp_cmp($i, $dmax) <= 0; $i += $divisor) {
                 $sieve[$i] = 0;
             }
             do {
                 $divisor++;
             } while (gmp_cmp($divisor, $dmax) < 0 && $sieve[$divisor] != 1);
             if (gmp_cmp($divisor, $dmax) > 0) {
                 $key = gmp_strval($number);
                 $factors[$key] = isset($factors[$key]) ? $factors[$key] + 1 : 1;
             }
         }
     } while (gmp_cmp($number, $one) > 0 && gmp_cmp($divisor, $dmax) <= 0);
     return $factors;
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:44,代码来源:GMPIntType.php


示例14: import

 public function import()
 {
     /*{{{*/
     if (extension_loaded('xhprof')) {
         // xhprof slows things down
         xhprof_disable();
     }
     if (!extension_loaded('gmp')) {
         throw new Exception('The blockchain importer requires the PHP GMP module to be installed and enabled');
     }
     echo "\nTodo:\n\n* add Output_Key join table to support multisig, convert data, then re-import all multisig transactions\n* detect if PHP is 64-bit, if not, check if GMP is installed, otherwise us BCMath\n  - ACTUALLY, just move to PHPSECLIB: http://phpseclib.sourceforge.net/math/intro.html \n* move RPC calls into separate class\n* move bitcoin specific utils into separate class\n* move conversion from satoshis to floats into view model\n* fix trailing decimal point on whole numbers in block and blockchain views\n\nMaybe:\n\n* move entities to model binder?\n";
     sleep(1);
     // this can take a long time
     set_time_limit(0);
     $client = new \Zend\Json\Server\Client($this->bitcoindServerUrl);
     $client->getHttpClient()->setOptions(array('timeout' => 30));
     $blockcount = $client->call('getblockcount');
     // Get the last block in the DB
     $query = $this->objectManager->createQuery('SELECT b FROM Blockchain\\Entity\\Block b WHERE b.id = (SELECT MAX(bm.id) FROM Blockchain\\Entity\\Block bm)');
     $result = $query->getResult();
     if (count($result) == 1) {
         $blockEntity = $result[0];
         $blockId = $blockEntity->getId();
         $blockhash = $blockEntity->getBlockhash();
         $blockNumber = $blockEntity->getBlockNumber();
         $block = $this->getBlockFromServer($blockhash);
         // remove last block and all associated transactions in case it wasn't loaded full or there was no "nextblockhash"
         $connection = $this->objectManager->getConnection();
         if ($connection->getDatabasePlatform()->getName() == 'mysql') {
             // The input and output tables have cyclical foreign keys, so rows can't be deleted
             $connection->query('SET FOREIGN_KEY_CHECKS=0');
         }
         $this->objectManager->remove($blockEntity);
         $this->objectManager->flush();
         if ($connection->getDatabasePlatform()->getName() == 'mysql') {
             $connection->query('SET FOREIGN_KEY_CHECKS=1');
         }
         $coinbaseExp = floor($blockNumber / 210000);
         $gmp_coinbaseValue = gmp_div_q(gmp_init("5000000000"), gmp_pow(gmp_init("2"), $coinbaseExp));
     } else {
         $blockNumber = 0;
         $blockhash = $client->call('getblockhash', array($blockNumber));
         $gmp_coinbaseValue = gmp_init("5000000000");
     }
     $batchSize = 25;
     $count = 0;
     // Start importing
     $lastTime = 0;
     $currTime = 0;
     $avgTime = 0;
     $blockCount = 0;
     while ($blockhash) {
         $currTime = microtime(true);
         if ($lastTime) {
             $diff = $currTime - $lastTime;
             // update average time between blocks
             $avgTime = ($avgTime * ($blockCount - 1) + $diff) / $blockCount;
             $blocksLeft = $blockcount - $blockNumber;
             $estimatedCompletion = $blocksLeft * $avgTime;
             echo sprintf("\n\nEstimated completion: %s (blocks left: %d, average block time: %s seconds\n", self::secondsToString($estimatedCompletion), $blocksLeft, number_format($avgTime, 2));
         }
         if ($blockNumber % 210000 == 0) {
             // only calculate this when necessary instead of every loop
             $coinbaseExp = floor($blockNumber / 210000);
             $gmp_coinbaseValue = gmp_div_q(gmp_init("5000000000"), gmp_pow(gmp_init("2"), $coinbaseExp));
         }
         echo "\nBlock {$blockNumber}, Transactions: ";
         $gmp_totalBlockValue = gmp_init("0");
         $block = $this->getBlockFromServer($blockhash);
         $blockEntity = new \Blockchain\Entity\Block();
         $blockEntity->setBlockNumber($blockNumber);
         $blockEntity->setBlockhash($block['hash']);
         $blockEntity->setSize($block['size']);
         $blockEntity->setHeight($block['height']);
         $blockEntity->setVersion($block['version']);
         $blockEntity->setMerkleroot($block['merkleroot']);
         $blockEntity->setTime(new \DateTime('@' . $block['time']));
         $blockEntity->setNonce($block['nonce']);
         $blockEntity->setBits($block['bits']);
         $blockEntity->setDifficulty($block['difficulty']);
         if (isset($block['nextblockhash'])) {
             $blockEntity->setNextblockhash($block['nextblockhash']);
         }
         if (isset($block['previousblockhash'])) {
             $blockEntity->setPreviousblockhash($block['previousblockhash']);
         }
         $this->objectManager->persist($blockEntity);
         $count++;
         $gmp_offeredFees = gmp_init("0");
         $gmp_takenFees = gmp_init("0");
         // First block is unique
         if ($blockNumber > 0) {
             $seenTxids = array();
             $seenAddresses = array();
             $txCount = 0;
             foreach ($block['tx'] as $txid) {
                 $txCount++;
                 if ($txCount > 1) {
                     echo ', ';
                 }
//.........这里部分代码省略.........
开发者ID:newmight2015,项目名称:zf2-blockchain-browser,代码行数:101,代码来源:Blockchain.php


示例15: reduce

 /**
  *
  * Reduce this number to it's lowest form
  */
 protected function reduce()
 {
     $gcd = gmp_gcd($this->value['num']->gmp(), $this->value['den']->gmp());
     if (gmp_cmp($gcd, 1) > 0) {
         $this->value['num']->set(gmp_div_q($this->value['num']->gmp(), $gcd));
         $this->value['den']->set(gmp_div_q($this->value['den']->gmp(), $gcd));
     }
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:12,代码来源:GMPRationalType.php


示例16: bitwise_rightShift

 public function bitwise_rightShift($shift)
 {
     $temp = new Math_BigInteger();
     switch (MATH_BIGINTEGER_MODE) {
         case MATH_BIGINTEGER_MODE_GMP:
             static $two;
             if (!isset($two)) {
                 $two = gmp_init('2');
             }
             $temp->value = gmp_div_q($this->value, gmp_pow($two, $shift));
             break;
         case MATH_BIGINTEGER_MODE_BCMATH:
             $temp->value = bcdiv($this->value, bcpow('2', $shift, 0), 0);
             break;
         default:
             $temp->value = $this->value;
             $temp->_rshift($shift);
     }
     return $this->_normalize($temp);
 }
开发者ID:fkssei,项目名称:pigcms10,代码行数:20,代码来源:Math_BigInteger.php


示例17: divide

 /**
  * This method returns the result of dividing the specified value against this object's
  * value.
  *
  * @access public
  * @static
  * @param IInteger\Type $x                                  the left operand
  * @param IInteger\Type $y                                  the right operand
  * @return IInteger\Type                                    the result
  */
 public static function divide(IInteger\Type $x, IInteger\Type $y) : IInteger\Type
 {
     return IInteger\Type::box(gmp_strval(gmp_div_q($x->unbox(), $y->unbox())));
 }
开发者ID:bluesnowman,项目名称:fphp-saber,代码行数:14,代码来源:Module.php


示例18: bmdiv

/**
 * Create a big math division function
 * @param string $l
 * @param string $r
 * @param int $z
 * @return string
 * @url http://www.icosaedro.it/bigint Inspired by
 */
function bmdiv($l, $r, $z = 0)
{
    if (function_exists('bcdiv')) {
        return $z == 0 ? bcdiv($l, $r) : bcmod($l, $r);
    }
    global $profile;
    if ($profile['use_gmp']) {
        return gmp_strval($z == 0 ? gmp_div_q($l, $r) : gmp_mod($l, $r));
    }
    $l = strval($l);
    $r = strval($r);
    $v = '0';
    while (true) {
        if (bmcomp($l, $r) < 0) {
            break;
        }
        $delta = strlen($l) - strlen($r);
        if ($delta >= 1) {
            $zeroes = str_repeat("0", $delta);
            $r2 = $r . $zeroes;
            if (strcmp($l, $r2) >= 0) {
                $v = bmadd($v, "1" . $zeroes);
                $l = bmsub($l, $r2);
            } else {
                $zeroes = str_repeat("0", $delta - 1);
                $v = bmadd($v, "1" . $zeroes);
                $l = bmsub($l, $r . $zeroes);
            }
        } else {
            $l = bmsub($l, $r);
            $v = bmadd($v, "1");
        }
    }
    return $z == 0 ? $v : $l;
}
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:43,代码来源:phpmyid.php


示例19: divide

 /**
  * {@inheritdoc}
  */
 public function divide($amount, $divisor)
 {
     $divisor = Number::fromString((string) $divisor);
     if ($divisor->isDecimal()) {
         $decimalPlaces = strlen($divisor->getFractionalPart());
         if ($divisor->getIntegerPart()) {
             $divisor = Number::fromString($divisor->getIntegerPart() . $divisor->getFractionalPart());
         } else {
             $divisor = Number::fromString(ltrim($divisor->getFractionalPart(), '0'));
         }
         $amount = gmp_strval(gmp_mul(gmp_init($amount), gmp_init('1' . str_pad('', $decimalPlaces, '0'))));
     }
     list($integer, $remainder) = gmp_div_qr(gmp_init($amount), gmp_init((string) $divisor));
     if (gmp_cmp($remainder, '0') === 0) {
         return gmp_strval($integer);
     }
     $divisionOfRemainder = gmp_strval(gmp_div_q(gmp_mul($remainder, gmp_init('1' . str_pad('', $this->scale, '0'))), gmp_init((string) $divisor), GMP_ROUND_MINUSINF));
     return gmp_strval($integer) . '.' . str_pad($divisionOfRemainder, $this->scale, '0', STR_PAD_LEFT);
 }
开发者ID:squigg,项目名称:money,代码行数:22,代码来源:GmpCalculator.php


示例20: ob_implicit_flush

   port from pidigits.lua-5.lua (Mike Pall, Wim Couwenberg)
   modified by Craig Russell
*/
$N = (int) $argv[1];
ob_implicit_flush(1);
ob_start(NULL, 4096);
$w = gmp_init(0);
$k = 1;
$n1 = gmp_init(4);
$n2 = gmp_init(3);
$d = gmp_init(1);
$i = 0;
while (true) {
    //digit
    $u = gmp_div_q($n1, $d);
    $v = gmp_div_q($n2, $d);
    if (gmp_cmp($u, $v) == 0) {
        echo gmp_strval($u);
        ++$i;
        if ($i % 10 == 0) {
            echo "\t:", $i, "\n";
        }
        if ($i == $N) {
            break;
        }
        //extract
        $u = gmp_mul($d, gmp_mul(-10, $u));
        $n1 = gmp_mul($n1, 10);
        $n1 = gmp_add($n1, $u);
        $n2 = gmp_mul($n2, 10);
        $n2 = gmp_add($n2, $u);
开发者ID:bennett000,项目名称:benchmarksgame,代码行数:31,代码来源:pidigits.php-5.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP gmp_div_qr函数代码示例发布时间:2022-05-15
下一篇:
PHP gmp_div函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap