本文整理汇总了PHP中gmp_cmp函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_cmp函数的具体用法?PHP gmp_cmp怎么用?PHP gmp_cmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_cmp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testCmp
public function testCmp()
{
$this->assertEquals(gmp_strval(gmp_cmp($this->a, $this->a)), $this->math->cmp($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_cmp($this->b, $this->b)), $this->math->cmp($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_cmp($this->c, $this->c)), $this->math->cmp($this->c, $this->c));
$this->assertEquals(0, $this->math->cmp(1, 1));
}
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:7,代码来源:GmpEngineTest.php
示例2: 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
示例3: show_mini_orderbook_table_row
function show_mini_orderbook_table_row($id, $curr, $price, $have, $want, $this_fiat, $this_btc, $sum_fiat, $sum_btc, $mine)
{
global $minimum_btc_amount, $minimum_fiat_amount;
$this_btc_str = internal_to_numstr($this_btc, BTC_PRECISION);
$this_fiat_str = internal_to_numstr($this_fiat, FIAT_PRECISION);
if (string_is_zero($this_btc_str) || string_is_zero($this_fiat_str) || gmp_cmp($this_btc, $minimum_btc_amount) < 0 || gmp_cmp($this_fiat, $minimum_fiat_amount) < 0) {
return;
}
if ($mine) {
$sum_btc_str = internal_to_numstr($sum_btc, BTC_PRECISION);
$sum_fiat_str = internal_to_numstr($sum_fiat, FIAT_PRECISION);
active_table_row("me", "?page=view_order&orderid={$mine}");
echo "<td class='right'>{$price}</td>\n";
echo "<td class='right'>{$this_btc_str}</td>\n";
echo "<td class='right'>{$this_fiat_str}</td>\n";
echo "<td class='right'>{$sum_btc_str}</td>\n";
echo "<td class='right'>{$sum_fiat_str}</td>\n";
echo "</tr>\n";
} else {
echo "<tr>\n";
echo "<td class='right'>{$price}</td>\n";
show_mini_orderbook_table_cell($id . 't', $curr, $price, $have, $want, $this_fiat, $this_btc);
show_mini_orderbook_table_cell($id . 'c', $curr, $price, $have, $want, $sum_fiat, $sum_btc);
}
echo "</tr>\n";
}
开发者ID:martinkirov,项目名称:intersango,代码行数:26,代码来源:trade.php
示例4: GetAuthID
function GetAuthID($i64friendID)
{
$tmpfriendID = $i64friendID;
$iServer = "1";
if (extension_loaded('bcmath') == 1) {
//decode communityid with bcmath
if (bcmod($i64friendID, "2") == "0") {
$iServer = "0";
}
$tmpfriendID = bcsub($tmpfriendID, $iServer);
if (bccomp("76561197960265728", $tmpfriendID) == -1) {
$tmpfriendID = bcsub($tmpfriendID, "76561197960265728");
}
$tmpfriendID = bcdiv($tmpfriendID, "2");
return "STEAM_0:" . $iServer . ":" . $tmpfriendID;
} else {
if (extension_loaded('gmp') == 1) {
//decode communityid with gmp
if (gmp_mod($i64friendID, "2") == "0") {
$iServer = "0";
}
$tmpfriendID = gmp_sub($tmpfriendID, $iServer);
if (gmp_cmp("76561197960265728", $tmpfriendID) == -1) {
$tmpfriendID = gmp_sub($tmpfriendID, "76561197960265728");
}
$tmpfriendID = gmp_div($tmpfriendID, "2");
return "STEAM_0:" . $iServer . ":" . gmp_strval($tmpfriendID);
}
}
return false;
}
开发者ID:GoeGaming,项目名称:bans.sevenelevenclan.org,代码行数:31,代码来源:steam.inc.php
示例5: computeBaseNLength
private function computeBaseNLength($number, $targetBase)
{
$digits = 0;
while (gmp_cmp($number, gmp_pow($targetBase, $digits)) != -1) {
$digits++;
}
return $digits ?: 1;
}
开发者ID:thunderer,项目名称:numbase,代码行数:8,代码来源:GmpConverter.php
示例6: generate
/**
* {@inheritDoc}
* @see \Mdanter\Ecc\RandomNumberGeneratorInterface::generate()
*/
public function generate($max)
{
$random = gmp_strval(gmp_random());
$small_rand = rand();
while (gmp_cmp($random, $max) > 0) {
$random = gmp_div($random, $small_rand, GMP_ROUND_ZERO);
}
return gmp_strval($random);
}
开发者ID:sbwdlihao,项目名称:phpecc,代码行数:13,代码来源:GmpRandomNumberGenerator.php
示例7: 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
示例8: 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
示例9: getBits
/**
* @param $value
*
* @return string
*/
public static function getBits($value)
{
$bits = [];
for ($i = gmp_init(1); gmp_cmp($value, $i) >= 0; $i = gmp_mul($i, 2)) {
if (static::has($value, $i)) {
$bits[] = gmp_strval($i);
}
}
return $bits;
}
开发者ID:packaged,项目名称:helpers,代码行数:15,代码来源:BitWiseGmp.php
示例10: encodeVarint
/**
* {@inheritdoc}
*/
public function encodeVarint($varint)
{
$bytes = [];
$value = $this->is32Bit ? gmp_and($varint, '0x0ffffffffffffffff') : sprintf('%u', $varint);
while (gmp_cmp($value, $this->gmp_x00) > 0) {
$bytes[] = gmp_intval(gmp_and($value, $this->gmp_x7f)) | 0x80;
$value = gmp_div_q($value, $this->gmp_x80);
}
return $bytes;
}
开发者ID:protobuf-php,项目名称:protobuf,代码行数:13,代码来源:GmpNegativeEncoder.php
示例11: calculateContentLength
protected function calculateContentLength()
{
$nrOfOctets = 1;
// we need at least one octet
$tmpValue = gmp_abs(gmp_init($this->value, 10));
while (gmp_cmp($tmpValue, 127) > 0) {
$tmpValue = $this->rightShift($tmpValue, 8);
$nrOfOctets++;
}
return $nrOfOctets;
}
开发者ID:afk11,项目名称:phpasn1,代码行数:11,代码来源:Integer.php
示例12: testcmp
public function testcmp()
{
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_cmp($a, $a)), $math->cmp($a, $a));
$this->assertEquals(gmp_strval(gmp_cmp($b, $b)), $math->cmp($b, $b));
$this->assertEquals(gmp_strval(gmp_cmp($c, $c)), $math->cmp($c, $c));
$this->assertEquals(0, $math->cmp(1, 1));
}
开发者ID:bitpay,项目名称:php-client,代码行数:11,代码来源:GmpEngineTest.php
示例13: verifies
public function verifies($hash, Signature $signature)
{
if (extension_loaded('gmp') && USE_EXT == 'GMP') {
$G = $this->generator;
$n = $this->generator->getOrder();
$point = $this->point;
$r = $signature->getR();
$s = $signature->getS();
if (gmp_cmp($r, 1) < 0 || gmp_cmp($r, gmp_sub($n, 1)) > 0) {
return false;
}
if (gmp_cmp($s, 1) < 0 || gmp_cmp($s, gmp_sub($n, 1)) > 0) {
return false;
}
$c = NumberTheory::inverse_mod($s, $n);
$u1 = gmp_Utils::gmp_mod2(gmp_mul($hash, $c), $n);
$u2 = gmp_Utils::gmp_mod2(gmp_mul($r, $c), $n);
$xy = Point::add(Point::mul($u1, $G), Point::mul($u2, $point));
$v = gmp_Utils::gmp_mod2($xy->getX(), $n);
if (gmp_cmp($v, $r) == 0) {
return true;
} else {
return false;
}
} else {
if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
$G = $this->generator;
$n = $this->generator->getOrder();
$point = $this->point;
$r = $signature->getR();
$s = $signature->getS();
if (bccomp($r, 1) == -1 || bccomp($r, bcsub($n, 1)) == 1) {
return false;
}
if (bccomp($s, 1) == -1 || bccomp($s, bcsub($n, 1)) == 1) {
return false;
}
$c = NumberTheory::inverse_mod($s, $n);
$u1 = bcmod(bcmul($hash, $c), $n);
$u2 = bcmod(bcmul($r, $c), $n);
$xy = Point::add(Point::mul($u1, $G), Point::mul($u2, $point));
$v = bcmod($xy->getX(), $n);
if (bccomp($v, $r) == 0) {
return true;
} else {
return false;
}
} else {
throw new ErrorException("Please install BCMATH or GMP");
}
}
}
开发者ID:AliceWonderMiscreations,项目名称:ColdAddress,代码行数:52,代码来源:PublicKey.php
示例14: cmp
public static function cmp(CurveFp $cp1, CurveFp $cp2)
{
$same = null;
if (extension_loaded('gmp') && USE_EXT == 'GMP') {
if (gmp_cmp($cp1->a, $cp2->a) == 0 && gmp_cmp($cp1->b, $cp2->b) == 0 && gmp_cmp($cp1->prime, $cp2->prime) == 0) {
return 0;
} else {
return 1;
}
} else {
throw new ErrorException("Please install GMP");
}
}
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:13,代码来源:CurveFp.php
示例15: gmp_random
public static function gmp_random($n)
{
if (extension_loaded('gmp') && USE_EXT == 'GMP') {
$random = gmp_strval(gmp_random());
$small_rand = rand();
while (gmp_cmp($random, $n) > 0) {
$random = gmp_div($random, $small_rand, GMP_ROUND_ZERO);
}
return gmp_strval($random);
} else {
throw new Exception("PLEASE INSTALL GMP");
}
}
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:13,代码来源:gmp_Utils.php
示例16: 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
示例17: 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
示例18: GOST_verifies
public function GOST_verifies($hash, Signature $signature)
{
if (extension_loaded('gmp') && USE_EXT == 'GMP') {
$G = $this->generator;
//P
$n = $this->generator->getOrder();
//q
$point = $this->point;
//Q
$r = $signature->getR();
$s = $signature->getS();
if (gmp_cmp($r, 1) < 0 || gmp_cmp($r, gmp_sub($n, 1)) > 0) {
return false;
}
if (gmp_cmp($s, 1) < 0 || gmp_cmp($s, gmp_sub($n, 1)) > 0) {
return false;
}
//step 3 GOST
$e = gmp_Utils::gmp_mod2($hash, $n);
if (gmp_cmp($e, '0') === 0) {
$e = gmp_init('1');
}
// step 4 GOST
$v = gmp_strval(gmp_invert($e, $n));
// step 5 GOST
$z1 = gmp_Utils::gmp_mod2(gmp_mul($s, $v), $n);
$z2 = gmp_Utils::gmp_mod2(gmp_mul(gmp_neg($r), $v), $n);
// step 6 GOST
$C = Point::add(Point::mul($z1, $G), Point::mul($z2, $point));
$R = gmp_Utils::gmp_mod2($C->getX(), $n);
if (0) {
echo "n - " . $n . "\n";
echo "h - " . $hash . "\n";
echo "e - " . gmp_Utils::gmp_dechex($e) . "\n";
echo "v - " . gmp_Utils::gmp_dechex($v) . "\n";
echo "r - " . $r . "\n";
echo "s - " . $s . "\n";
echo "z1 - " . gmp_Utils::gmp_dechex($z1) . "\nz2 - " . gmp_Utils::gmp_dechex($z2) . "\n";
echo "Q - " . $point . "\nG - " . $G . "\n";
echo "C - " . $C . "\nR - " . $R . "\n";
}
if (gmp_cmp($R, $r) == 0) {
return true;
} else {
return false;
}
} else {
throw new ErrorException("Please install GMP");
}
}
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:50,代码来源:PublicKey.php
示例19: 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
示例20: Pidigit_Next
function Pidigit_Next(&$pd, $times)
{
$digits = '';
$z = $pd[0];
do {
$y = Transformation_Extract($z, 3);
do {
$z = Transformation_Compose($z, Transformation_Next($pd[1]));
$y = Transformation_Extract($z, 3);
} while (0 != gmp_cmp(Transformation_Extract($z, 4), $y));
$z = Transformation_Compose2($y, $z);
$digits .= gmp_strval($y);
} while (--$times);
$pd[0] = $z;
return $digits;
}
开发者ID:michaelprem,项目名称:phc,代码行数:16,代码来源:pidigits.php-2.php
注:本文中的gmp_cmp函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论