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

PHP gmp_add函数代码示例

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

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



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

示例1: modulus

 /**
  * Return the modulus, also known as absolute value or magnitude of this number
  * = sqrt(r^2 + i^2);
  *
  * @return \Chippyash\Type\Number\Rational\GMPRationalType
  */
 public function modulus()
 {
     if ($this->isReal()) {
         //sqrt(r^2 + 0^2) = sqrt(r^2) = abs(r)
         /** @noinspection PhpUndefinedMethodInspection */
         return $this->value['real']->abs();
     }
     //get r^2 and i^2
     $sqrR = array('n' => gmp_pow($this->value['real']->numerator()->gmp(), 2), 'd' => gmp_pow($this->value['real']->denominator()->gmp(), 2));
     $sqrI = array('n' => gmp_pow($this->value['imaginary']->numerator()->gmp(), 2), 'd' => gmp_pow($this->value['imaginary']->denominator()->gmp(), 2));
     //r^2 + i^2
     $den = $this->lcm($sqrR['d'], $sqrI['d']);
     $numRaw = gmp_strval(gmp_add(gmp_div_q(gmp_mul($sqrR['n'], $den), $sqrR['d']), gmp_div_q(gmp_mul($sqrI['n'], $den), $sqrI['d'])));
     $num = TypeFactory::createInt($numRaw);
     //sqrt(num/den) = sqrt(num)/sqrt(den)
     //now this a fudge - we ought to be able to get a proper square root using
     //factors etc but what we do instead is to do an approximation by converting
     //to intermediate rationals using as much precision as we can i.e.
     // rNum = GMPRationaType(sqrt(num))
     // rDen = GMPRationalType(sqrt(den))
     // mod = rN/1 * 1/rD
     $rNum = RationalTypeFactory::fromFloat(sqrt($num()));
     $rDen = RationalTypeFactory::fromFloat(sqrt(gmp_strval($den)));
     $modN = gmp_mul($rNum->numerator()->gmp(), $rDen->denominator()->gmp());
     $modD = gmp_mul($rNum->denominator()->gmp(), $rDen->numerator()->gmp());
     return RationalTypeFactory::create((int) gmp_strval($modN), (int) gmp_strval($modD));
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:33,代码来源:GMPComplexType.php


示例2: get_funds_graph_data

function get_funds_graph_data()
{
    $btc = array();
    $fiat = array();
    $query = "\n        SELECT\n            req_type, amount, curr_type, " . sql_format_date('timest') . " AS timest2\n        FROM\n            requests\n        WHERE\n            status != 'CANCEL'\n        ORDER BY\n            timest;\n    ";
    $result = do_query($query);
    $btc_sum = 0;
    $fiat_sum = 0;
    while ($row = mysql_fetch_array($result)) {
        $req_type = $row['req_type'];
        $amount = $row['amount'];
        $curr_type = $row['curr_type'];
        $timest = $row['timest2'];
        if ($req_type == 'WITHDR') {
            $amount = gmp_mul(-1, $amount);
        }
        if ($curr_type == 'BTC') {
            $btc_sum = gmp_add($btc_sum, $amount);
            $btc[$timest] = internal_to_numstr($btc_sum);
        } else {
            $fiat_sum = gmp_add($fiat_sum, $amount);
            $fiat[$timest] = internal_to_numstr($fiat_sum);
        }
    }
    return array($btc, $fiat);
}
开发者ID:martinkirov,项目名称:intersango,代码行数:26,代码来源:graph.php


示例3: testGMP

 public function testGMP()
 {
     $math = \Mdanter\Ecc\EccFactory::getAdapter();
     $I_l = "e97a4d6be13f8f5804c0a76080428fc6d51260f74801678c4127045d2640af14";
     $private_key = "142018c66b43a95de58c1cf603446fc0da322bc15fb4df068b844b57c706dd05";
     $n = "115792089237316195423570985008687907852837564279074904382605163141518161494337";
     $gmp_I_l = gmp_init($I_l, 16);
     $gmp_private_key = gmp_init($private_key, 16);
     $gmp_add = gmp_add($gmp_I_l, $gmp_private_key);
     $gmp_add_res = gmp_strval($gmp_add, 10);
     $this->assertEquals("105604983404708440304568772161069255144976878830542744455590282065741265022740", gmp_strval($gmp_I_l));
     $this->assertEquals("9102967069016248707169900673545386030247334423973996501079368232055584775429", gmp_strval($gmp_private_key));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval($gmp_add));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval(gmp_div_r($gmp_add, gmp_init($n))));
     $this->assertEquals("-4", gmp_strval(gmp_cmp(0, gmp_div_r($gmp_add, $n))));
     $this->assertEquals("230500039711040884435309657843302549028061777533591645339274813439315011292506", gmp_strval(gmp_add(gmp_init($n), gmp_div_r($gmp_add, gmp_init($n)))));
     $gmp_mod2 = $math->mod($gmp_add_res, $n);
     $this->assertTrue(is_string($gmp_mod2));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", $gmp_mod2);
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", $gmp_mod2);
     // when no base is provided both a resource and string work
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval(gmp_init($gmp_mod2)));
     $this->assertEquals("114707950473724689011738672834614641175224213254516740956669650297796849798169", gmp_strval($gmp_mod2));
     // when base is provided it fails on HHVM when inputting a string
     $this->assertEquals("fd9a66324c8338b5ea4cc4568386ff87af448cb8a7b64692ccab4fb4ed478c19", gmp_strval(gmp_init($gmp_mod2), 16));
     // $this->assertEquals("fd9a66324c8338b5ea4cc4568386ff87af448cb8a7b64692ccab4fb4ed478c19", gmp_strval($gmp_mod2, 16));
     $this->assertEquals("fd9a66324c8338b5ea4cc4568386ff87af448cb8a7b64692ccab4fb4ed478c19", str_pad(gmp_strval(gmp_init($gmp_mod2), 16), 64, '0', STR_PAD_LEFT));
 }
开发者ID:NucleusStudios,项目名称:bitcoin-lib-php,代码行数:28,代码来源:BIP32CoreTest.php


示例4: to64Bit

 /**
  * Convert 32-bit SteamID to 64-bit SteamID
  *
  * @param string|int $userId
  *
  * @return string
  * @throws Exception
  */
 public static function to64Bit($userId)
 {
     if (!function_exists('gmp_add')) {
         throw new Exception("GMP Library not installed. Cannot convert SteamIDs.");
     }
     return gmp_strval(gmp_add(gmp_mul(sprintf("%u", bindec(self::STEAM_ID_UPPER_BITS)), "4294967296"), sprintf("%u", $userId)));
 }
开发者ID:sjaakmoes,项目名称:dotapi2,代码行数:15,代码来源:UserId.php


示例5: testAdd

 public function testAdd()
 {
     $this->assertEquals(gmp_strval(gmp_add($this->a, $this->a)), $this->math->add($this->a, $this->a));
     $this->assertEquals(gmp_strval(gmp_add($this->b, $this->b)), $this->math->add($this->b, $this->b));
     $this->assertEquals(gmp_strval(gmp_add($this->c, $this->c)), $this->math->add($this->c, $this->c));
     $this->assertEquals(2, $this->math->add(1, 1));
 }
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:7,代码来源:GmpEngineTest.php


示例6: assetNameToIDHex

 protected function assetNameToIDHex($asset_name)
 {
     if ($asset_name == 'BTC') {
         return '0';
     }
     if ($asset_name == 'XCP') {
         return '1';
     }
     if (substr($asset_name, 0, 1) == 'A') {
         // numerical asset
         // An integer between 26^12 + 1 and 256^8 (inclusive)
         $asset_id = gmp_init(substr($asset_name, 1));
         if ($asset_id < gmp_init(26) ** 12 + 1) {
             throw new Exception("Asset ID was too low", 1);
         }
         if ($asset_id > gmp_init(2) ** 64 - 1) {
             throw new Exception("Asset ID was too high", 1);
         }
         return gmp_strval($asset_id, 16);
     }
     $n = gmp_init(0);
     for ($i = 0; $i < strlen($asset_name); $i++) {
         $n = gmp_mul($n, 26);
         $char = ord(substr($asset_name, $i, 1));
         if ($char < 65 or $char > 90) {
             throw new Exception("Asset name invalid", 1);
         }
         $digit = $char - 65;
         $n = gmp_add($n, $digit);
     }
     return gmp_strval($n, 16);
 }
开发者ID:tokenly,项目名称:counterparty-transaction-composer,代码行数:32,代码来源:OpReturnBuilder.php


示例7: GetFriendID

function GetFriendID($pszAuthID)
{
    $iServer = "0";
    $iAuthID = "0";
    $szAuthID = $pszAuthID;
    $szTmp = strtok($szAuthID, ":");
    while (($szTmp = strtok(":")) !== false) {
        $szTmp2 = strtok(":");
        if ($szTmp2 !== false) {
            $iServer = $szTmp;
            $iAuthID = $szTmp2;
        }
    }
    if ($iAuthID == "0") {
        return false;
    }
    if (extension_loaded('bcmath') == 1) {
        // calc communityid with bcmath
        $i64friendID = bcmul($iAuthID, "2");
        $i64friendID = bcadd($i64friendID, bcadd("76561197960265728", $iServer, 0), 0);
        return $i64friendID;
    } else {
        if (extension_loaded('gmp') == 1) {
            // calc communityid with gmp
            $i64friendID = gmp_mul($iAuthID, "2");
            $i64friendID = gmp_add($i64friendID, gmp_add("76561197960265728", $iServer));
            return gmp_strval($i64friendID);
        } else {
            $i64friendID = Mul(strval($iAuthID), "2");
            $i64friendID = Add(strval($i64friendID), Add("76561197960265728", strval($iServer)));
            return $i64friendID;
        }
    }
    return false;
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:35,代码来源:steam.inc.php


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


示例9: testEncrypt

 /**
  * @dataProvider encryptedWords
  */
 public function testEncrypt($in, $out)
 {
     $primeNumber = Math\Calculator::generateNthPrime(10000);
     $fibonacciSum = Math\Calculator::sumOfFibonacciElements(49);
     $tmp = gmp_strval(gmp_add($primeNumber, $fibonacciSum));
     $key = intval(strrev(substr($tmp, 5, -4)));
     $this->assertEquals($out, self::$cipher->encrypt($in, $key));
 }
开发者ID:campestrini,项目名称:PhpExercise,代码行数:11,代码来源:CipherTest.php


示例10: _bindecGmp

 /**
 * binary decode using gmp extension 
 */
 private static function _bindecGmp($bin)
 {
     $dec = gmp_init(0);
     for ($i = 0; $i < strlen($bin); $i++) {
         $dec = gmp_add(gmp_mul($dec, 256), ord($bin[$i]));
     }
     return $dec;
 }
开发者ID:uwitec,项目名称:outbuying,代码行数:11,代码来源:Dsa.php


示例11: bin2dec

 public function bin2dec($bin)
 {
     $dec = '0';
     for ($i = 0, $len = strlen($bin); $i < $len; $i++) {
         $dec = gmp_add(gmp_mul($dec, 2), $bin[$i]);
     }
     return $dec;
 }
开发者ID:kemoycampbell,项目名称:PHP-RSA,代码行数:8,代码来源:GMP.php


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


示例13: inc

 public static function inc($X, $n)
 {
     $s = gmp_strval($X, 2);
     $s1 = (string) substr($s, 0, -$n);
     $s = gmp_add(gmp_init(substr($s, -$n), 2), 1);
     $s = gmp_mod($s, gmp_pow(2, $n));
     $s2 = str_pad(gmp_strval($s, 2), $n, '0', STR_PAD_LEFT);
     return gmp_init($s1 . $s2, 2);
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:9,代码来源:GCM.php


示例14: generate

 public function generate($serial)
 {
     $mul = gmp_mul(strval($this->mulFactor), strval($serial));
     $add = gmp_add($mul, $this->diffFactor);
     $mod = gmp_mod($add, strval($this->amount));
     $num = gmp_strval($mod);
     //        $num = ($this->mulFactor * $serial + $this->diffFactor) % $this->amount;
     return str_pad($num, $this->length, $this->padding, STR_PAD_LEFT);
 }
开发者ID:qiuqiux,项目名称:serialno,代码行数:9,代码来源:PseudoRandom.php


示例15: extractd

function extractd(&$n1, &$n2, $d, $y)
{
    global $u;
    $u = gmp_mul($d, gmp_mul(-10, $y));
    $n1 = gmp_mul($n1, 10);
    $n1 = gmp_add($n1, $u);
    $n2 = gmp_mul($n2, 10);
    $n2 = gmp_add($n2, $u);
}
开发者ID:neoedmund,项目名称:benchmarksgame,代码行数:9,代码来源:pidigits.php-3.php


示例16: readNumber

function readNumber($fd, $len)
{
    $val = gmp_init(0);
    for ($inx = 0; $inx < $len; $inx++) {
        $data = fread($fd, 1);
        $val = gmp_mul($val, gmp_init(256));
        $val = gmp_add($val, gmp_init(ord($data[0])));
    }
    return $val;
}
开发者ID:patrickz98,项目名称:xavaro,代码行数:10,代码来源:EPGDatabaseDump.php


示例17: edwards

 public function edwards($P, $Q)
 {
     $x1 = $P[0];
     $y1 = $P[1];
     $x2 = $Q[0];
     $y2 = $Q[1];
     $t = gmp_mul($this->params['d'], gmp_mul(gmp_mul($x1, $x2), gmp_mul($y1, $y2)));
     $x3 = gmp_mul(gmp_add(gmp_mul($x1, $y2), gmp_mul($x2, $y1)), $this->inv(gmp_add(1, $t)));
     $y3 = gmp_mul(gmp_add(gmp_mul($y1, $y2), gmp_mul($x1, $x2)), $this->inv(gmp_sub(1, $t)));
     return array(gmp_mod($x3, $this->params['q']), gmp_mod($y3, $this->params['q']));
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:11,代码来源:ED25519.php


示例18: testadd

 public function testadd()
 {
     $a = 1234;
     $b = '1234123412341234123412341234123412412341234213412421341342342';
     $c = '0x1234123412341234123412341234123412412341234213412421341342342';
     $math = new GmpEngine();
     $this->assertEquals(gmp_strval(gmp_add($a, $a)), $math->add($a, $a));
     $this->assertEquals(gmp_strval(gmp_add($b, $b)), $math->add($b, $b));
     $this->assertEquals(gmp_strval(gmp_add($c, $c)), $math->add($c, $c));
     $this->assertEquals(2, $math->add(1, 1));
 }
开发者ID:bitpay,项目名称:php-client,代码行数:11,代码来源:GmpEngineTest.php


示例19: convertToBase10

 private function convertToBase10($source, $sourceBase)
 {
     $int = gmp_init(0, 10);
     $length = mb_strlen($source) - 1;
     for ($i = 0; $i <= $length; $i++) {
         $pow = gmp_pow($sourceBase, $length - $i);
         $mul = gmp_mul($this->symbols->getValue($source[$i]), $pow);
         $int = gmp_add($int, $mul);
     }
     return $int;
 }
开发者ID:thunderer,项目名称:numbase,代码行数:11,代码来源:GmpConverter.php


示例20: gmp_mod2

 public static function gmp_mod2($n, $d)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $res = gmp_div_r($n, $d);
         if (gmp_cmp(0, $res) > 0) {
             $res = gmp_add($d, $res);
         }
         return gmp_strval($res);
     } else {
         throw new Exception("PLEASE INSTALL GMP");
     }
 }
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:12,代码来源:gmp_Utils.php



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
PHP gmp_and函数代码示例发布时间:2022-05-15
下一篇:
PHP gmp_abs函数代码示例发布时间: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