本文整理汇总了PHP中gmp_mod函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_mod函数的具体用法?PHP gmp_mod怎么用?PHP gmp_mod使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gmp_mod函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: nextPrime
/**
* Finds next strong pseudoprime number, following after $num
*
* @param gmp resource $num
* @return gmp resource
* @access public
*/
function nextPrime($num)
{
if (!gmp_cmp(gmp_mod($num, 2), 0)) {
$num = gmp_sub($num, 1);
}
do {
$num = gmp_add($num, 2);
} while (!gmp_prob_prime($num));
return $num;
}
示例2: testMod
public function testMod()
{
$this->assertEquals(gmp_strval(gmp_mod($this->a, $this->a)), $this->math->mod($this->a, $this->a));
$this->assertEquals(gmp_strval(gmp_mod($this->b, $this->b)), $this->math->mod($this->b, $this->b));
$this->assertEquals(gmp_strval(gmp_mod($this->c, $this->c)), $this->math->mod($this->c, $this->c));
$this->assertEquals(0, $this->math->mod(1, 1));
}
示例3: main
function main()
{
global $numEpochs;
global $numPatterns;
global $patNum;
global $RMSerror;
// initiate the weights
initWeights();
// load in the data
initData();
// train the network
for ($j = 0; $j <= $numEpochs; $j++) {
for ($i = 0; $i < $numPatterns; $i++) {
//select a pattern at random
//srand();
$patNum = rand(0, $numPatterns - 1);
//calculate the current network output
//and error for this pattern
calcNet();
//change network weights
WeightChangesHO();
WeightChangesIH();
}
//display the overall network error
//after each epoch
calcOverallError();
if (gmp_mod($j, 50) == 0) {
print "epoch = " . $j . " RMS Error = " . $RMSerror . "</br>";
}
}
//training has finished
//display the results
displayResults();
}
示例4: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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);
}
示例9: 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);
}
示例10: testmod
public function testmod()
{
$a = 1234;
$b = '1234123412341234123412341234123412412341234213412421341342342';
$c = '0x1234123412341234123412341234123412412341234213412421341342342';
$math = new GmpEngine();
$this->assertEquals(gmp_strval(gmp_mod($a, $a)), $math->mod($a, $a));
$this->assertEquals(gmp_strval(gmp_mod($b, $b)), $math->mod($b, $b));
$this->assertEquals(gmp_strval(gmp_mod($c, $c)), $math->mod($c, $c));
$this->assertEquals(0, $math->mod(1, 1));
}
示例11: 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']));
}
示例12: nextSeed
private static function nextSeed()
{
// GMP available
if (sjMathRandom::$m_hasGMP) {
sjMathRandom::$m_seed = (int) gmp_mod(gmp_add(gmp_mul(sjMathRandom::$m_seed, sjMathRandom::PARAM_A), sjMathRandom::PARAM_B), sjMathRandom::PARAM_C);
} else {
if (sjMathRandom::$m_hasBCMath) {
sjMathRandom::$m_seed = (int) bcmod(bcadd(bcmul(sjMathRandom::$m_seed, sjMathRandom::PARAM_A), sjMathRandom::PARAM_B), sjMathRandom::PARAM_C);
} else {
die('sjMathRandom: no suported math library available');
}
}
}
示例13: is_pentagonal
function is_pentagonal($num)
{
// we do a sqr with remainder
list($sr, $rem) = gmp_sqrtrem(gmp_add(gmp_mul(24, $num), 1));
// if it's not an exact root don't bother with the rest
if (gmp_strval($rem) == '0') {
$d = gmp_add($sr, 1);
$m = gmp_strval(gmp_mod($d, 6));
if ($m == '0') {
return true;
}
}
return false;
}
示例14: 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;
}
示例15: getEncodedValue
protected function getEncodedValue()
{
$numericValue = gmp_init($this->value, 10);
$contentLength = $this->getContentLength();
if (gmp_sign($numericValue) < 0) {
$numericValue = gmp_add($numericValue, gmp_sub(gmp_pow(2, 8 * $contentLength), 1));
$numericValue = gmp_add($numericValue, 1);
}
$result = '';
for ($shiftLength = ($contentLength - 1) * 8; $shiftLength >= 0; $shiftLength -= 8) {
$octet = gmp_strval(gmp_mod($this->rightShift($numericValue, $shiftLength), 256));
$result .= chr($octet);
}
return $result;
}