本文整理汇总了PHP中gmp_abs函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_abs函数的具体用法?PHP gmp_abs怎么用?PHP gmp_abs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_abs函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: 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
示例2: deposited_or_withdrawn
function deposited_or_withdrawn($deposit, $withdraw)
{
$net = gmp_sub($deposit, $withdraw);
$abs = gmp_abs($net);
if (gmp_cmp($net, 0) < 0) {
$word = _("withdrawn");
} else {
$word = _("deposited");
}
return array($abs, $word);
}
开发者ID:martinkirov,项目名称:intersango,代码行数:11,代码来源:statement.php
示例3: 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
示例4: _encodeNegativeInteger
/**
* Encode negative integer to DER content.
*
* @param \GMP|resource $num
* @return string
*/
private static function _encodeNegativeInteger($num)
{
$num = gmp_abs($num);
// compute number of bytes required
$width = 1;
if ($num > 128) {
$tmp = $num;
do {
$width++;
$tmp >>= 8;
} while ($tmp > 128);
}
// compute two's complement 2^n - x
$num = gmp_pow("2", 8 * $width) - $num;
$bin = gmp_export($num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
// if first bit is 0, prepend full inverted byte
// to represent negative two's complement
if (!(ord($bin[0]) & 0x80)) {
$bin = chr(0xff) . $bin;
}
return $bin;
}
开发者ID:sop,项目名称:asn1,代码行数:28,代码来源:Integer.php
示例5: abs
/**
* Get the absolute value
*
* @access public
* @return self
*/
public function abs()
{
$result = gmp_abs($this->getRawValue());
return static::factory($result);
}
开发者ID:lamannapov,项目名称:mathematician,代码行数:11,代码来源:Gmp.php
示例6: toBytes
/**
* Converts a BigInteger to a binary string.
*
* @return string
*/
public function toBytes()
{
if (gmp_cmp($this->value, gmp_init(0)) === 0) {
return '';
}
$temp = gmp_strval(gmp_abs($this->value), 16);
$temp = mb_strlen($temp, '8bit') & 1 ? '0' . $temp : $temp;
$temp = hex2bin($temp);
return ltrim($temp, chr(0));
}
开发者ID:spomky-labs,项目名称:jose,代码行数:15,代码来源:BigInteger.php
示例7: div
/**
* Creates a new decimal which is a result of a division of $a by $b.
*
* @param Decimal2 $a
* @param Decimal2 $b
* @return Decimal2
*/
public static function div(Decimal2 $a, Decimal2 $b)
{
$strA = strval($a);
$strB = strval($b);
$sign_a = '-' === $strA[0] ? -1 : 1;
$sign_b = '-' === $strB[0] ? -1 : 1;
$ret = new Decimal2('0');
$ret->cents = gmp_strval(gmp_div_q(gmp_add(gmp_mul(gmp_abs(gmp_init($a->cents, 10)), 100), 50), gmp_abs(gmp_init($b->cents, 10)), GMP_ROUND_ZERO));
if ($sign_a * $sign_b < 0) {
$ret->cents = gmp_strval(gmp_neg(gmp_init($ret->cents, 10)));
}
return $ret;
}
开发者ID:adispartadev,项目名称:money-math-php,代码行数:20,代码来源:Decimal2.php
示例8: abs
/**
* This method returns the absolute value of this object's value.
*
* @access public
* @static
* @param IInteger\Type $x the operand
* @return IInteger\Type the result
*/
public static function abs(IInteger\Type $x) : IInteger\Type
{
return IInteger\Type::box(gmp_strval(gmp_abs($x->unbox())));
}
开发者ID:bluesnowman,项目名称:fphp-saber,代码行数:12,代码来源:Module.php
示例9: abs
/**
* Absolute value.
*
* @access public
* @return \Topxia\Service\Util\Phpsec\Math\BigInteger
*/
public function abs()
{
$temp = new static();
switch (MATH_BIGINTEGER_MODE) {
case self::MODE_GMP:
$temp->value = gmp_abs($this->value);
break;
case self::MODE_BCMATH:
$temp->value = bccomp($this->value, '0', 0) < 0 ? substr($this->value, 1) : $this->value;
break;
default:
$temp->value = $this->value;
}
return $temp;
}
开发者ID:robert-li-2015,项目名称:EduSoho,代码行数:21,代码来源:BigInteger.php
示例10: switch
/**
* Returns the absolute value of a Math_Integer number
*
* @param object Math_Integer $int1
* @return object Math_Integer on success, PEAR_Error otherwise
* @access public
*/
function &abs(&$int1)
{
/*{{{*/
if (PEAR::isError($err = Math_IntegerOp::_validInt($int1))) {
return $err;
}
switch (MATH_INTLIB) {
/*{{{*/
case 'gmp':
$tmp = gmp_strval(gmp_abs($int1->getValue()));
break;
case 'bcmath':
if ($int1->getValue() < 0) {
$tmp = bcmul(-1, $int1->getValue());
} else {
$tmp = $int1->getValue();
}
break;
case 'std':
$tmp = abs($int1->getValue());
break;
}
/*}}}*/
return new Math_Integer($tmp);
}
开发者ID:Esleelkartea,项目名称:kz-adeada-talleres-electricos-,代码行数:32,代码来源:IntegerOp.php
示例11: gmp_abs
开发者ID:catlabinteractive,项目名称:dolumar-engine,代码行数:3,代码来源:gmp.php
示例12: var_dump
<?php
var_dump(gmp_strval(gmp_abs("")));
var_dump(gmp_strval(gmp_abs("0")));
var_dump(gmp_strval(gmp_abs(0)));
var_dump(gmp_strval(gmp_abs(-1.1111111111111111E+20)));
var_dump(gmp_strval(gmp_abs("111111111111111111111")));
var_dump(gmp_strval(gmp_abs("-111111111111111111111")));
var_dump(gmp_strval(gmp_abs("0000")));
var_dump(gmp_strval(gmp_abs("09876543")));
var_dump(gmp_strval(gmp_abs("-099987654")));
var_dump(gmp_abs());
var_dump(gmp_abs(1, 2));
var_dump(gmp_abs(array()));
echo "Done\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:15,代码来源:gmp_abs.php
示例13: abs
/**
* Get absolute value of a big integer
*
* @param string $operand
* @return string
*/
public function abs($operand)
{
$result = gmp_abs($operand);
return gmp_strval($result);
}
开发者ID:tillk,项目名称:vufind,代码行数:11,代码来源:Gmp.php
示例14: abs
/**
* Absolute value.
*
* @return Math_BigInteger
* @access public
*/
public function abs()
{
$temp = new Math_BigInteger();
switch (self::$mode) {
case Math_BigInteger::MODE_GMP:
$temp->value = gmp_abs($this->value);
break;
case Math_BigInteger::MODE_BCMATH:
$temp->value = bccomp($this->value, '0', 0) < 0 ? substr($this->value, 1) : $this->value;
break;
default:
$temp->value = $this->value;
}
return $temp;
}
开发者ID:tomi77,项目名称:sfPEARcaptchaPlugin,代码行数:21,代码来源:BigInteger.php
示例15: abs
/**
* Converts the value to an absolute number.
*
* @return BigInteger
*/
public function abs() : BigInteger
{
$value = gmp_abs($this->value);
return $this->assignValue($value);
}
开发者ID:phpmath,项目名称:biginteger,代码行数:10,代码来源:BigInteger.php
示例16: lcm
/**
* Return Least Common Multiple of two numbers
* @param int $a
* @param int $b
* @return int
*/
private function lcm($a, $b)
{
return gmp_abs(gmp_div_q(gmp_mul($a, $b), gmp_gcd($a, $b)));
}
开发者ID:chippyash,项目名称:strong-type,代码行数:10,代码来源:GMPComplexType.php
示例17: GetInfo
/**
* Get server information
*
* @throws InvalidPacketException
* @throws SocketException
*
* @return array Returns an array with information on success
*/
public function GetInfo()
{
if (!$this->Connected) {
throw new SocketException('Not connected.', SocketException::NOT_CONNECTED);
}
$this->Socket->Write(self::A2S_INFO, "Source Engine Query");
$Buffer = $this->Socket->Read();
$Type = $Buffer->GetByte();
// Old GoldSource protocol, HLTV still uses it
if ($Type === self::S2A_INFO_OLD && $this->Socket->Engine === self::GOLDSOURCE) {
/**
* If we try to read data again, and we get the result with type S2A_INFO (0x49)
* That means this server is running dproto,
* Because it sends answer for both protocols
*/
$Server['Address'] = $Buffer->GetString();
$Server['HostName'] = $Buffer->GetString();
$Server['Map'] = $Buffer->GetString();
$Server['ModDir'] = $Buffer->GetString();
$Server['ModDesc'] = $Buffer->GetString();
$Server['Players'] = $Buffer->GetByte();
$Server['MaxPlayers'] = $Buffer->GetByte();
$Server['Protocol'] = $Buffer->GetByte();
$Server['Dedicated'] = Chr($Buffer->GetByte());
$Server['Os'] = Chr($Buffer->GetByte());
$Server['Password'] = $Buffer->GetByte() === 1;
$Server['IsMod'] = $Buffer->GetByte() === 1;
if ($Server['IsMod']) {
$Mod['Url'] = $Buffer->GetString();
$Mod['Download'] = $Buffer->GetString();
$Buffer->Get(1);
// NULL byte
$Mod['Version'] = $Buffer->GetLong();
$Mod['Size'] = $Buffer->GetLong();
$Mod['ServerSide'] = $Buffer->GetByte() === 1;
$Mod['CustomDLL'] = $Buffer->GetByte() === 1;
}
$Server['Secure'] = $Buffer->GetByte() === 1;
$Server['Bots'] = $Buffer->GetByte();
if (isset($Mod)) {
$Server['Mod'] = $Mod;
}
return $Server;
}
if ($Type !== self::S2A_INFO) {
throw new InvalidPacketException('GetInfo: Packet header mismatch. (0x' . DecHex($Type) . ')', InvalidPacketException::PACKET_HEADER_MISMATCH);
}
$Server['Protocol'] = $Buffer->GetByte();
$Server['HostName'] = $Buffer->GetString();
$Server['Map'] = $Buffer->GetString();
$Server['ModDir'] = $Buffer->GetString();
$Server['ModDesc'] = $Buffer->GetString();
$Server['AppID'] = $Buffer->GetShort();
$Server['Players'] = $Buffer->GetByte();
$Server['MaxPlayers'] = $Buffer->GetByte();
$Server['Bots'] = $Buffer->GetByte();
$Server['Dedicated'] = Chr($Buffer->GetByte());
$Server['Os'] = Chr($Buffer->GetByte());
$Server['Password'] = $Buffer->GetByte() === 1;
$Server['Secure'] = $Buffer->GetByte() === 1;
// The Ship (they violate query protocol spec by modifying the response)
if ($Server['AppID'] === 2400) {
$Server['GameMode'] = $Buffer->GetByte();
$Server['WitnessCount'] = $Buffer->GetByte();
$Server['WitnessTime'] = $Buffer->GetByte();
}
$Server['Version'] = $Buffer->GetString();
// Extra Data Flags
if ($Buffer->Remaining() > 0) {
$Server['ExtraDataFlags'] = $Flags = $Buffer->GetByte();
// The server's game port
if ($Flags & 0x80) {
$Server['GamePort'] = $Buffer->GetShort();
}
// The server's steamid
// Want to play around with this?
// You can use https://github.com/xPaw/SteamID.php
if ($Flags & 0x10) {
$SteamIDLower = $Buffer->GetUnsignedLong();
$SteamIDInstance = $Buffer->GetUnsignedLong();
// This gets shifted by 32 bits, which should be steamid instance
$SteamID = 0;
if (PHP_INT_SIZE === 4) {
if (extension_loaded('gmp')) {
$SteamIDLower = gmp_abs($SteamIDLower);
$SteamIDInstance = gmp_abs($SteamIDInstance);
$SteamID = gmp_strval(gmp_or($SteamIDLower, gmp_mul($SteamIDInstance, gmp_pow(2, 32))));
} else {
throw new \RuntimeException('Either 64-bit PHP installation or "gmp" module is required to correctly parse server\'s steamid.');
}
} else {
$SteamID = $SteamIDLower | $SteamIDInstance << 32;
//.........这里部分代码省略.........
开发者ID:jelakesh,项目名称:PHP-Source-Query,代码行数:101,代码来源:SourceQuery.php
示例18: readTextRecordInner
//.........这里部分代码省略.........
list(, $data2) = unpack('H*', strrev(substr($content, $pos, 2)));
$pos += 2;
list(, $data3) = unpack('H*', strrev(substr($content, $pos, 2)));
$pos += 2;
list(, $data4) = unpack('H*', substr($content, $pos, 2));
$pos += 2;
list(, $data5) = unpack('H*', substr($content, $pos, 6));
$pos += 6;
$record = "{$data1}-{$data2}-{$data3}-{$data4}-{$data5}";
if ($recordType == Constants::RECORD_TYPE_UNIQUEID_TEXT || $recordType == Constants::RECORD_TYPE_UNIQUEID_TEXT_WITH_END_ELEMENT) {
$record = 'urn:uuid:' . $record;
}
return $record;
break;
case Constants::RECORD_TYPE_TIMESPAN_TEXT:
case Constants::RECORD_TYPE_TIMESPAN_TEXT_WITH_END_ELEMENT:
if (!function_exists('gmp_init')) {
throw new DecodingException('Timespan requires GMP extension');
}
$value = '';
for ($i = 0; $i < 8; $i++) {
list(, $byte) = unpack('C*', $content[$pos + $i]);
$value = sprintf('%08b', $byte) . $value;
}
$pos += 8;
$value = gmp_init($value, 2);
$minus = false;
if (gmp_testbit($value, 63)) {
$minus = true;
$mask = gmp_init(str_repeat('1', 64), '2');
$value = gmp_and(gmp_com($value), $mask);
$value = gmp_add($value, 1);
}
$remaining = gmp_abs($value);
list($days, $remaining) = gmp_div_qr($remaining, gmp_init('864000000000'));
list($hours, $remaining) = gmp_div_qr($remaining, gmp_init('36000000000'));
list($mins, $remaining) = gmp_div_qr($remaining, gmp_init('600000000'));
list($secs, $remaining) = gmp_div_qr($remaining, gmp_init('10000000'));
$fracs = $remaining;
$days = gmp_intval($days);
$hours = gmp_intval($hours);
$mins = gmp_intval($mins);
$secs = gmp_intval($secs);
$fracs = gmp_intval($fracs);
$record = $minus ? '-P' : 'P';
if ($days > 0) {
$record .= $days . 'D';
}
if ($hours > 0 || $mins > 0 || $secs > 0 || $fracs > 0) {
$record .= 'T';
if ($hours > 0) {
$record .= $hours . 'H';
}
if ($mins > 0) {
$record .= $mins . 'M';
}
if ($secs > 0 || $fracs > 0) {
$record .= $secs;
if ($fracs > 0) {
$record .= '.' . $fracs;
}
$record .= 'S';
}
}
return $record;
break;
开发者ID:casperbiering,项目名称:dotnet-binary-xml,代码行数:67,代码来源:Decoder.php
示例19: gmp_abs
<?php
// gmp_abs
$abs1 = gmp_abs("274982683358");
$abs2 = gmp_abs("-274982683358");
echo gmp_strval($abs1) . "\n";
echo gmp_strval($abs2) . "\n";
// gmp_add
$sum = gmp_add("123456789012345", "76543210987655");
echo gmp_strval($sum) . "\n";
// gmp_and
$and1 = gmp_and("0xfffffffff4", "0x4");
$and2 = gmp_and("0xfffffffff4", "0x8");
echo gmp_strval($and1) . "\n";
echo gmp_strval($and2) . "\n";
// gmp_clrbit
$clrbit = gmp_init("0xff");
gmp_clrbit($clrbit, 0);
echo gmp_strval($clrbit) . "\n";
// gmp_cmp
$cmp1 = gmp_cmp("1234", "1000");
// greater than
$cmp2 = gmp_cmp("1000", "1234");
// less than
$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
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:mostInOne.php
示例20: abs
/**
* Return the absolute value of the number
*
* @return \Chippyash\Type\Number\GMPIntType
*/
public function abs()
{
return new self(gmp_abs($this->value));
}
开发者ID:chippyash,项目名称:strong-type,代码行数:9,代码来源:GMPIntType.php
注:本文中的gmp_abs函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论