本文整理汇总了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));
}
示例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');
}
示例3: getResult
public function getResult($num)
{
// init
$prime = 1;
for ($i = 0; $i < $num; $i++) {
$prime = gmp_nextprime($prime);
}
return gmp_intval($prime);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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());
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}