当前位置: 首页>>代码示例>>PHP>>正文


PHP gmp_pow函数代码示例

本文整理汇总了PHP中gmp_pow函数的典型用法代码示例。如果您正苦于以下问题:PHP gmp_pow函数的具体用法?PHP gmp_pow怎么用?PHP gmp_pow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gmp_pow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPow

 public function testPow()
 {
     $this->assertEquals(gmp_strval(gmp_pow($this->a, $this->a)), $this->math->pow($this->a, $this->a));
     $this->assertEquals(gmp_strval(gmp_pow($this->b, $this->b)), $this->math->pow($this->b, $this->b));
     $this->assertEquals(gmp_strval(gmp_pow($this->c, $this->c)), $this->math->pow($this->c, $this->c));
     $this->assertEquals(1, $this->math->pow(1, 1));
 }
开发者ID:Invision70,项目名称:php-bitpay-client,代码行数:7,代码来源:GmpEngineTest.php

示例2: 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

示例3: 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

示例4: modulus

 /**
  * Return the modulus, also known as absolute value or magnitude of this number
  * = sqrt(r^2 + i^2);
  *
  * @return \Chippyash\Type\Number\Rational\GMPRationalType
  */
 public function modulus()
 {
     if ($this->isReal()) {
         //sqrt(r^2 + 0^2) = sqrt(r^2) = abs(r)
         /** @noinspection PhpUndefinedMethodInspection */
         return $this->value['real']->abs();
     }
     //get r^2 and i^2
     $sqrR = array('n' => gmp_pow($this->value['real']->numerator()->gmp(), 2), 'd' => gmp_pow($this->value['real']->denominator()->gmp(), 2));
     $sqrI = array('n' => gmp_pow($this->value['imaginary']->numerator()->gmp(), 2), 'd' => gmp_pow($this->value['imaginary']->denominator()->gmp(), 2));
     //r^2 + i^2
     $den = $this->lcm($sqrR['d'], $sqrI['d']);
     $numRaw = gmp_strval(gmp_add(gmp_div_q(gmp_mul($sqrR['n'], $den), $sqrR['d']), gmp_div_q(gmp_mul($sqrI['n'], $den), $sqrI['d'])));
     $num = TypeFactory::createInt($numRaw);
     //sqrt(num/den) = sqrt(num)/sqrt(den)
     //now this a fudge - we ought to be able to get a proper square root using
     //factors etc but what we do instead is to do an approximation by converting
     //to intermediate rationals using as much precision as we can i.e.
     // rNum = GMPRationaType(sqrt(num))
     // rDen = GMPRationalType(sqrt(den))
     // mod = rN/1 * 1/rD
     $rNum = RationalTypeFactory::fromFloat(sqrt($num()));
     $rDen = RationalTypeFactory::fromFloat(sqrt(gmp_strval($den)));
     $modN = gmp_mul($rNum->numerator()->gmp(), $rDen->denominator()->gmp());
     $modD = gmp_mul($rNum->denominator()->gmp(), $rDen->numerator()->gmp());
     return RationalTypeFactory::create((int) gmp_strval($modN), (int) gmp_strval($modD));
 }
开发者ID:chippyash,项目名称:strong-type,代码行数:33,代码来源:GMPComplexType.php

示例5: 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

示例6: 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');
}
开发者ID:baotroy,项目名称:chal,代码行数:8,代码来源:index.php

示例7: makeId32

 private function makeId32($timestamp, $machine, $sequence)
 {
     $timestamp = gmp_mul((string) $timestamp, gmp_pow(2, 22));
     $machine = gmp_mul((string) $machine, gmp_pow(2, 12));
     $sequence = gmp_init((string) $sequence, 10);
     $value = gmp_or(gmp_or($timestamp, $machine), $sequence);
     return gmp_strval($value, 10);
 }
开发者ID:AlexanderGrom,项目名称:php-snowflake,代码行数:8,代码来源:snowflake.php

示例8: gmp_shiftr

function gmp_shiftr($x, $n)
{
    if ($x < 0) {
        return gmp_strval(gmp_com(gmp_div(gmp_com($x), gmp_pow(2, $n))));
    } else {
        return gmp_strval(gmp_div($x, gmp_pow(2, $n)));
    }
}
开发者ID:nicefirework,项目名称:Open-Textbooks,代码行数:8,代码来源:math_functions.php

示例9: 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

示例10: 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);
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:9,代码来源:GCM.php

示例11: __construct

 protected function __construct()
 {
     $this->params['q'] = gmp_sub(gmp_pow(2, 255), 19);
     $this->params['l'] = gmp_add(gmp_pow(2, 252), '27742317777372353535851937790883648493');
     $this->params['d'] = gmp_mul(-121665, $this->inv(121666));
     $this->params['I'] = gmp_powm(2, gmp_div_q(gmp_sub($this->params['q'], 1), 4), $this->params['q']);
     $By = gmp_mul(4, $this->inv(5));
     $Bx = $this->xrecover($By);
     $this->params['B'] = array($Bx, $By);
 }
开发者ID:fpoirotte,项目名称:pssht,代码行数:10,代码来源:ED25519.php

示例12: 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());
 }
开发者ID:rickselby,项目名称:nbt,代码行数:15,代码来源:DataHandlerLong32Test.php

示例13: provideNumbase

 public function provideNumbase()
 {
     $symbols = '0123456789' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . 'abcdefghijklmnopqrstuvwxyz';
     $numbases = array(array(Numbase::createDefault()), array(Numbase::createDefault(new StringSymbols($symbols))), array(Numbase::createDefault(new ArraySymbols(str_split($symbols, 1)))));
     $numbers = array(array(gmp_strval(gmp_pow(10, 9), 10), 10, 1000000000, '10'), array(gmp_strval(gmp_pow(10, 1000), 10), 10, 100, '1' . str_pad('', 500, '0', STR_PAD_RIGHT)), array('10000000000000000000000', 10, 100, '100000000000'), array('15', 10, 16, 'F'), array('zz', 62, 10, '3843'), array('3843', 10, 62, 'zz'), array('-3843', 10, 62, '-zz'), array('100000', 10, 62, 'Q0u'), array('3843', 10, 16, 'F03'), array('65', 10, 2, '1000001'), array('1', 10, 10, '1'), array('0', 16, 2, '0'), array('64000', 10, 32000, '20'));
     $result = array();
     foreach ($numbers as $number) {
         foreach ($numbases as $numbase) {
             $result[] = array_merge($numbase, $number);
         }
     }
     return $result;
 }
开发者ID:thunderer,项目名称:numbase,代码行数:13,代码来源:NumbaseTest.php

示例14: number62_decode

function number62_decode($string)
{
    if (preg_match('#^[a-zA-Z0-9]+$#iu', $string) == 0) {
        return 0;
    }
    $out = 0;
    $length = mb_strlen($string);
    $array = array_flip(str_split("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"));
    for ($i = 0; $i < $length; $i++) {
        $out = gmp_add($out, gmp_mul($array[$string[$length - $i - 1]], gmp_pow(62, $i)));
    }
    $out = gmp_strval($out, 10);
    return $out;
}
开发者ID:AlexanderGrom,项目名称:knee,代码行数:14,代码来源:main.php

示例15: contains

 public function contains($x, $y)
 {
     $eq_zero = null;
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $eq_zero = gmp_cmp(gmp_Utils::gmp_mod2(gmp_sub(gmp_pow($y, 2), gmp_add(gmp_add(gmp_pow($x, 3), gmp_mul($this->a, $x)), $this->b)), $this->prime), 0);
         if ($eq_zero == 0) {
             return true;
         } else {
             return false;
         }
     } else {
         throw new ErrorException("Please install GMP");
     }
 }
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:14,代码来源:CurveFp.php


注:本文中的gmp_pow函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。