本文整理汇总了PHP中gmp_strval函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_strval函数的具体用法?PHP gmp_strval怎么用?PHP gmp_strval使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_strval函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testBaseConvertDigits
public function testBaseConvertDigits()
{
$converter = new BaseConvertConverter(new Base62Symbols());
$this->assertSame(explode(':', '4:16:12:8:33:15:15:6:34:11:20:0:20:28:32:4:24:0:32:4:12:16:12:28:32'), $converter->convert(gmp_strval(gmp_pow(10, 38), 10), 10, 36));
$this->assertSame(str_split('100000000000', 1), $converter->convert('100000000000', 10, 10));
$this->assertSame(explode(':', '3:18:2:10:0:0:0:0:0'), $converter->convert('100000000000', 10, 20));
}
开发者ID:thunderer,项目名称:numbase,代码行数:7,代码来源:ConverterTest.php
示例2: PMA_pow
/**
* Exponential expression / raise number into power
*
* @param string $base base to raise
* @param string $exp exponent to use
* @param mixed $use_function pow function to use, or false for auto-detect
*
* @return mixed string or float
*/
function PMA_pow($base, $exp, $use_function = false)
{
static $pow_function = null;
if (null == $pow_function) {
$pow_function = PMA_detect_pow();
}
if (!$use_function) {
$use_function = $pow_function;
}
if ($exp < 0 && 'pow' != $use_function) {
return false;
}
switch ($use_function) {
case 'bcpow':
// bcscale() needed for testing PMA_pow() with base values < 1
bcscale(10);
$pow = bcpow($base, $exp);
break;
case 'gmp_pow':
$pow = gmp_strval(gmp_pow($base, $exp));
break;
case 'pow':
$base = (double) $base;
$exp = (int) $exp;
$pow = pow($base, $exp);
break;
default:
$pow = $use_function($base, $exp);
}
return $pow;
}
开发者ID:AmberWish,项目名称:laba_web,代码行数:40,代码来源:common.lib.php
示例3: 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
示例4: 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
示例5: generate
public static function generate($ver = 4, $node = null, $clockSeq = null, $ns = null, $name = null)
{
$uuid = null;
/* Create a new UUID based on provided data. */
switch ((int) $ver) {
case 1:
$uuid = Uuid::uuid1($node, $clockSeq);
break;
case 2:
// Version 2 is not supported
throw new \RuntimeException('UUID version 2 is unsupported.');
case 3:
$uuid = Uuid::uuid3($ns, $name);
break;
case 4:
$uuid = Uuid::uuid4();
break;
case 5:
$uuid = Uuid::uuid5($ns, $name);
break;
default:
throw new \RuntimeException('Selected UUID version is invalid or unsupported.');
}
if (function_exists('gmp_strval')) {
return gmp_strval(gmp_init($uuid->getHex(), 16), 62);
}
return Base62::encode((string) $uuid->getInteger());
}
开发者ID:gponster,项目名称:laravel-url62-uuid,代码行数:28,代码来源:Url62UuidGenerator.php
示例6: _baseConvert
/**
* _baseConvert
*
* Convert values from base-A to base-B with GMP-functions
*
* @param string $value Input value for convert
* @param int $from From base-A value
* @param int $to To base-B value
* @return string Result string
*/
private static function _baseConvert($value, $from, $to)
{
if (!function_exists('gmp_init')) {
throw new \SystemErrorException(array('title' => 'HashHelper error', 'description' => 'Requires the PHP gmp module'));
}
return gmp_strval(gmp_init($value, $from), $to);
}
开发者ID:nsedenkov,项目名称:phpsu,代码行数:17,代码来源:HashHelper.php
示例7: 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
示例8: g
function g($val = null)
{
if (is_string($val)) {
$this->g = gmp_init($val, 16);
}
return gmp_strval($this->g, 16);
}
开发者ID:hjkyoyo,项目名称:php-cryptopals,代码行数:7,代码来源:33-implement-diffie-hellman.php
示例9: Zend_OpenId_bigNumToBin
function Zend_OpenId_bigNumToBin($bn)
{
if (extension_loaded('gmp')) {
$s = gmp_strval($bn, 16);
if (strlen($s) % 2 != 0) {
$s = '0' . $s;
}
return pack("H*", $s);
} else {
if (extension_loaded('bcmath')) {
$cmp = bccomp($bn, 0);
if ($cmp == 0) {
return chr(0);
} else {
if ($cmp < 0) {
throw new Zend_OpenId_Exception('Big integer arithmetic error', Zend_OpenId_Exception::ERROR_LONG_MATH);
}
}
$bin = "";
while (bccomp($bn, 0) > 0) {
$bin = chr(bcmod($bn, 256)) . $bin;
$bn = bcdiv($bn, 256);
}
return $bin;
}
}
throw new Zend_OpenId_Exception('The system doesn\'t have proper big integer extension', Zend_OpenId_Exception::UNSUPPORTED_LONG_MATH);
}
开发者ID:Tony133,项目名称:zf-web,代码行数:28,代码来源:bignum_patch.php
示例10: toInteger
/**
* 与えられた値を整数型に変換して返します。
* @link http://www.hcn.zaq.ne.jp/___/WEB/WebIDL-ja.html#es-integers Web IDL (第2版 — 日本語訳)
* @param boolean|integer|float|string|resource|\GMP|\SplInt $value
* @param string $type byte、octet、short、unsigned short、long、unsigned long、long long、unsigned long long
* @param integer|float $min 浮動小数点型で正確に扱える整数の範囲よりも、整数型で扱える整数の範囲が狭ければ (整数型が32bitである環境なら) 浮動小数点数。
* @param integer|float $max 浮動小数点型で正確に扱える整数の範囲よりも、整数型で扱える整数の範囲が狭ければ (整数型が32bitである環境なら) 浮動小数点数。
* @param integer $bits
* @param booelan $signed
* @param string $extendedAttribute 拡張属性。[EnforceRange] か [Clamp] のいずれか。
* @return integer|float 整数型の範囲を超える場合は浮動小数点数。
* @throws \InvalidArgumentException 配列、NULL が与えられた場合。または、GMP、SplInt 以外のオブジェクトが与えられた場合。
* @throws \DomainException $extendedAttribute が [EnforceRange]、かつ与えられたの値が $min 〜 $max に収まらなかった場合。
*/
private static function toInteger($value, $type, $min, $max, $bits, $signed, $extendedAttribute = null)
{
/** @var string 要求される型。 */
$expectedType = sprintf('%s (an integer in the range of %s to %s)', $type, is_float($min) ? number_format($min, 0, '', '') : $min, is_float($max) ? number_format($max, 0, '', '') : $max);
if (!self::isIntegerCastable($value)) {
throw new \InvalidArgumentException(ErrorMessageCreator::create($value, $expectedType));
}
if ($value instanceof \GMP || is_resource($value) && get_resource_type($value) === 'GMP integer') {
// GMP数であれば、あらかじめ文字列に変換しておく
$value = gmp_strval($value);
}
/** @var integer|float 与えられた値の数値表現。整数型の範囲を超える場合は浮動小数点数。整数値となる場合、小数部があれば0方向へ丸められる。 */
$number = is_float($value) || (double) $value < self::$phpIntMin || (double) $value > PHP_INT_MAX ? (double) $value : (int) $value;
if ($extendedAttribute === '[EnforceRange]') {
/** @var integer|float 与えられた値の整数表現。整数型の範囲を超える場合は浮動小数点数。 */
$integer = self::roundTowardZero($number);
if (!is_finite($number) || $integer < $min || $integer > $max) {
throw new \DomainException(ErrorMessageCreator::create($value, $expectedType));
}
} elseif (!is_nan($number) && $extendedAttribute === '[Clamp]') {
$number = min(max($number, $min), $max);
$integer = is_float($number) ? round($number, 0, PHP_ROUND_HALF_EVEN) : $number;
} elseif (!is_finite($number)) {
$integer = 0;
} else {
$integer = self::modulo(self::roundTowardZero($number), pow(2, $bits));
if ($signed && $integer >= pow(2, $bits - 1)) {
$integer -= pow(2, $bits);
}
}
return is_float($integer) && $integer >= self::$phpIntMin && $integer <= PHP_INT_MAX ? (int) $integer : $integer;
}
开发者ID:esperecyan,项目名称:webidl,代码行数:46,代码来源:IntegerType.php
示例11: powmod
function powmod($base, $exponent, $modulus)
{
if (function_exists('gmp_powm')) {
// fast
return gmp_strval(gmp_powm($base, $exponent, $modulus));
}
if (function_exists('bi_powmod')) {
// not tested
return bi_sto_str(bi_powmod($base, $exponent, $modulus));
}
if (function_exists('bcpowmod')) {
// slow
return bcpowmod($base, $exponent, $modulus);
}
// emulation, slow
$square = bcmod($base, $modulus);
$result = 1;
while (bccomp($exponent, 0) > 0) {
if (bcmod($exponent, 2)) {
$result = bcmod(bcmul($result, $square), $modulus);
}
$square = bcmod(bcmul($square, $square), $modulus);
$exponent = bcdiv($exponent, 2);
}
return $result;
}
开发者ID:yuang1516,项目名称:WebbrowserLock,代码行数:26,代码来源:keygen.php
示例12: num2str
public static function num2str($num)
{
switch (BigInt::support()) {
case 'gmp':
$str = gmp_strval($num, 16);
$len = strlen($str);
if ($len % 2 == 1) {
$str = '0' . $str;
}
return pack("H*", $str);
case 'big_int':
$str = bi_to_str($num, 16);
$len = strlen($str);
if ($len % 2 == 1) {
$str = '0' . $str;
}
return pack("H*", $str);
case 'bcmath':
bcscale(0);
$str = "";
while (bccomp($num, '0') == 1) {
$str = chr(bcmod($num, '256')) . $str;
$num = bcdiv($num, '256');
}
return $str;
case '':
default:
return BigInt::_num2str($num);
}
}
开发者ID:liuyu121,项目名称:myqee,代码行数:30,代码来源:bigint.class.php
示例13: internal_to_numstr
function internal_to_numstr($num, $precision = -1, $round = true)
{
if ($precision == -1) {
$precision = 8;
$tidy = true;
} else {
$tidy = false;
}
if (!is_string($num) && !is_resource($num)) {
throw new Error('Coding error!', "internal_to_numstr argument has type '" . gettype($num) . "'");
}
$repr = gmp_strval($num);
if ($round) {
if ($repr > 0) {
$repr = bcadd($repr, pow(10, 8 - $precision) / 2);
} else {
$repr = bcsub($repr, pow(10, 8 - $precision) / 2);
}
}
$repr = bcdiv($repr, pow(10, 8), $precision);
// now tidy output...
if ($tidy) {
return clean_sql_numstr($repr);
}
return sprintf("%.{$precision}f", $repr);
}
开发者ID:martinkirov,项目名称:intersango,代码行数:26,代码来源:db.php
示例14: pow
/**
* Exponential expression / raise number into power
*
* @param string $base base to raise
* @param string $exp exponent to use
* @param string $use_function pow function to use, or false for auto-detect
*
* @return mixed string or float
*/
public static function pow($base, $exp, $use_function = '')
{
static $pow_function = null;
if ($pow_function == null) {
$pow_function = self::detectPow();
}
if (!$use_function) {
if ($exp < 0) {
$use_function = 'pow';
} else {
$use_function = $pow_function;
}
}
if ($exp < 0 && $use_function != 'pow') {
return false;
}
switch ($use_function) {
case 'bcpow':
// bcscale() needed for testing pow() with base values < 1
bcscale(10);
$pow = bcpow($base, $exp);
break;
case 'gmp_pow':
$pow = gmp_strval(gmp_pow($base, $exp));
break;
case 'pow':
$base = (double) $base;
$exp = (int) $exp;
$pow = pow($base, $exp);
break;
default:
$pow = $use_function($base, $exp);
}
return $pow;
}
开发者ID:altesien,项目名称:FinalProject,代码行数:44,代码来源:Util.class.php
示例15: getCycleWeatherValue
/**
* @param int $cycle weather cycle we in (hours/3)
* @param CWeatherFunction $wf cycle season weather function (weights)
*
* @return WeatherValue
*/
public function getCycleWeatherValue($cycle, CWeatherFunction $wf)
{
$numWS = $wf->getNumWeatherSetups();
if (!$numWS) {
return 0;
}
/* old weather
$noiseValue = $this->rawWeatherProvider($cycle);
// sum all weights, usually adds up to 100
$value = (int)($noiseValue * $wf->getWeatherSetupsTotalWeight());
*/
$noiseValue = \Nel\Misc\wang_hash64($cycle);
// noise is 64bit unsigned, so use GMP library
// value = wangHash64(cycle) % wf.getWeatherSetupsTotalWeight();
$value = gmp_strval(gmp_mod($noiseValue, $wf->getWeatherSetupsTotalWeight()));
$currWeight = 0;
for ($k = 0; $k < $numWS; $k++) {
$weight = $wf->getWeatherSetupWeight($k);
if ($value >= $currWeight && $value < $currWeight + $weight) {
$scaledWeather = ($value - $currWeight) / $weight + $k;
$weather = $scaledWeather / $numWS;
return new WeatherValue($k, $weather, $wf);
}
$currWeight += $weight;
}
return new WeatherValue($numWS, 1, $wf);
}
开发者ID:nimetu,项目名称:ryzom_weather,代码行数:34,代码来源:CPredictWeather.php
示例16: pidigits
function pidigits($N)
{
$k = 1;
$n1 = gmp_init(4);
$n2 = gmp_init(3);
$d = gmp_init(1);
$i = 0;
while ($i < $N) {
$y = digit($n1, $n2, $d);
if ($y !== false) {
echo gmp_strval($y);
$i++;
if ($i % 10 == 0) {
echo "\t:", $i, "\n";
}
extractd($n1, $n2, $d, $y);
} else {
produce($n1, $n2, $d, $k);
$k++;
}
}
if ($i % 10 != 0) {
echo str_repeat(' ', 10 - $N % 10), "\t:", $N, "\n";
}
}
开发者ID:neoedmund,项目名称:benchmarksgame,代码行数:25,代码来源:pidigits.php-3.php
示例17: 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
示例18: 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
示例19: combinations
public static function combinations($num, $repetitions)
{
if ($num >= $repetitions) {
return gmp_strval(gmp_fact($num)) / (gmp_strval(gmp_fact($repetitions)) * gmp_strval(gmp_fact($num - $repetitions)));
} else {
exit('Error you could, not second parameter that is greater than the first one.');
}
}
开发者ID:smoothframework,项目名称:smooth,代码行数:8,代码来源:Math.php
示例20: setIpAttribute
protected function setIpAttribute($key, $value)
{
if (!is_null($value)) {
$value = gmp_strval(gmp_import(inet_pton($value)));
}
$this->attributes[$key] = $value;
return $this;
}
开发者ID:danhunsaker,项目名称:eloquent-mutant-caster,代码行数:8,代码来源:CastIP.php
注:本文中的gmp_strval函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论