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


PHP gmp_div函数代码示例

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


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

示例1: testDiv

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

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

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

示例4: generate

 /**
  * {@inheritDoc}
  * @see \Mdanter\Ecc\RandomNumberGeneratorInterface::generate()
  */
 public function generate($max)
 {
     $random = gmp_strval(gmp_random());
     $small_rand = rand();
     while (gmp_cmp($random, $max) > 0) {
         $random = gmp_div($random, $small_rand, GMP_ROUND_ZERO);
     }
     return gmp_strval($random);
 }
开发者ID:sbwdlihao,项目名称:phpecc,代码行数:13,代码来源:GmpRandomNumberGenerator.php

示例5: testdiv

 public function testdiv()
 {
     $a = 1234;
     $b = '1234123412341234123412341234123412412341234213412421341342342';
     $c = '0x1234123412341234123412341234123412412341234213412421341342342';
     $math = new GmpEngine();
     $this->assertEquals(gmp_strval(gmp_div($a, $a)), $math->div($a, $a));
     $this->assertEquals(gmp_strval(gmp_div($b, $b)), $math->div($b, $b));
     $this->assertEquals(gmp_strval(gmp_div($c, $c)), $math->div($c, $c));
     $this->assertEquals(1, $math->div(1, 1));
 }
开发者ID:bitpay,项目名称:php-client,代码行数:11,代码来源:GmpEngineTest.php

示例6: computeBaseNDigits

 private function computeBaseNDigits($number, $targetBase)
 {
     $digits = array();
     $length = $this->computeBaseNLength($number, $targetBase);
     for ($i = 0; $i < $length; $i++) {
         $pow = gmp_pow($targetBase, $length - $i - 1);
         $div = gmp_div($number, $pow, GMP_ROUND_ZERO);
         $number = gmp_sub($number, gmp_mul($div, $pow));
         $digits[] = $div;
     }
     return array_map('gmp_strval', $digits);
 }
开发者ID:thunderer,项目名称:numbase,代码行数:12,代码来源:GmpConverter.php

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

示例8: gmp_random

 public static function gmp_random($n)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         $random = gmp_strval(gmp_random());
         $small_rand = rand();
         while (gmp_cmp($random, $n) > 0) {
             $random = gmp_div($random, $small_rand, GMP_ROUND_ZERO);
         }
         return gmp_strval($random);
     } else {
         throw new Exception("PLEASE INSTALL GMP");
     }
 }
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:13,代码来源:gmp_Utils.php

示例9: encode

 /**
  * @param int $value
  *
  * @return string
  */
 public static function encode($value)
 {
     $value = gmp_init($value, 10);
     $octets = chr(gmp_strval(gmp_and($value, 0x7f), 10));
     $rightShift = function ($number, $positions) {
         return gmp_div($number, gmp_pow(2, $positions));
     };
     $value = $rightShift($value, 7);
     while (gmp_cmp($value, 0) > 0) {
         $octets .= chr(gmp_strval(gmp_or(0x80, gmp_and($value, 0x7f)), 10));
         $value = $rightShift($value, 7);
     }
     return strrev($octets);
 }
开发者ID:afk11,项目名称:phpasn1,代码行数:19,代码来源:Base128.php

示例10: Zend_OpenId_bigNumToBin2

function Zend_OpenId_bigNumToBin2($bn)
{
    if (extension_loaded('gmp')) {
        /*The GMP conversion code in this function was liberally copied 
        	 and adapted from  JanRain's Auth_OpenId_MathLibrary::longToBinary*/
        $cmp = gmp_cmp($bn, 0);
        if ($cmp < 0) {
            throw new Zend_OpenId_Exception('Big integer arithmetic error', Zend_OpenId_Exception::ERROR_LONG_MATH);
        }
        if ($cmp == 0) {
            return "";
        }
        $bytes = array();
        while (gmp_cmp($bn, 0) > 0) {
            array_unshift($bytes, gmp_mod($bn, 256));
            $bn = gmp_div($bn, pow(2, 8));
        }
        if ($bytes && $bytes[0] > 127) {
            array_unshift($bytes, 0);
        }
        $string = '';
        foreach ($bytes as $byte) {
            $string .= pack('C', $byte);
        }
        return $string;
    } 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,代码行数:45,代码来源:bignum_patch.php

示例11: recoverPubKey

function recoverPubKey($r, $s, $e, $recoveryFlags, $G)
{
    $isYEven = ($recoveryFlags & 1) != 0;
    $isSecondKey = ($recoveryFlags & 2) != 0;
    $curve = $G->getCurve();
    $signature = new Signature($r, $s);
    // Precalculate (p + 1) / 4 where p is the field order
    static $p_over_four;
    // XXX just assuming only one curve/prime will be used
    if (!$p_over_four) {
        $p_over_four = gmp_div(gmp_add($curve->getPrime(), 1), 4);
    }
    // 1.1 Compute x
    if (!$isSecondKey) {
        $x = $r;
    } else {
        $x = gmp_add($r, $G->getOrder());
    }
    // 1.3 Convert x to point
    $alpha = gmp_mod(gmp_add(gmp_add(gmp_pow($x, 3), gmp_mul($curve->getA(), $x)), $curve->getB()), $curve->getPrime());
    $beta = NumberTheory::modular_exp($alpha, $p_over_four, $curve->getPrime());
    // If beta is even, but y isn't or vice versa, then convert it,
    // otherwise we're done and y == beta.
    if (isBignumEven($beta) == $isYEven) {
        $y = gmp_sub($curve->getPrime(), $beta);
    } else {
        $y = $beta;
    }
    // 1.4 Check that nR is at infinity (implicitly done in construtor)
    $R = new Point($curve, $x, $y, $G->getOrder());
    $point_negate = function ($p) {
        return new Point($p->curve, $p->x, gmp_neg($p->y), $p->order);
    };
    // 1.6.1 Compute a candidate public key Q = r^-1 (sR - eG)
    $rInv = NumberTheory::inverse_mod($r, $G->getOrder());
    $eGNeg = $point_negate(Point::mul($e, $G));
    $Q = Point::mul($rInv, Point::add(Point::mul($s, $R), $eGNeg));
    // 1.6.2 Test Q as a public key
    $Qk = new PublicKey($G, $Q);
    if ($Qk->verifies($e, $signature)) {
        return $Qk;
    }
    return false;
}
开发者ID:iloveyou416068,项目名称:Server-RPC-Framework,代码行数:44,代码来源:verifymessage.php

示例12: wang_hash64

/**
 * Calculate Wang hash for 64bit unsigned integer using GMP library
 * PHP only supports signed integers even with 64bit version
 *
 * See <code/nel/include/nel/misc/wang_hash.h> on https://bitbucket.org/ryzom/ryzomcore
 *
 * @param string $key
 *
 * @return string hash
 */
function wang_hash64($key)
{
    // force $key to be base 10
    $key = gmp_init($key, 10);
    //$key = (~$key) + ($key << 21);
    $key = gmp_add(gmp_com($key), gmp_mul($key, 1 << 21));
    //$key = $key ^ ($key >> 24);
    $key = gmp_xor($key, gmp_div($key, 1 << 24));
    //$key = $key * 265;
    $key = gmp_mul($key, 265);
    //$key = $key ^ ($key >> 14);
    $key = gmp_xor($key, gmp_div($key, 1 << 14));
    //$key = $key * 21;
    $key = gmp_mul($key, 21);
    //$key = $key ^ ($key >> 28);
    $key = gmp_xor($key, gmp_div($key, 1 << 28));
    //$key = $key + ($key << 31);
    $key = gmp_add($key, gmp_mul($key, gmp_pow(2, 31)));
    // limit to 64bit
    $key = gmp_and($key, "0xFFFFFFFFFFFFFFFF");
    return gmp_strval($key, 10);
}
开发者ID:nimetu,项目名称:ryzom_weather,代码行数:32,代码来源:wang_hash.php

示例13: int_to_string

 public static function int_to_string($x)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         if (gmp_cmp($x, 0) >= 0) {
             if (gmp_cmp($x, 0) == 0) {
                 return chr(0);
             }
             $result = "";
             while (gmp_cmp($x, 0) > 0) {
                 $q = gmp_div($x, 256, 0);
                 $r = gmp_Utils::gmp_mod2($x, 256);
                 $ascii = chr($r);
                 $result = $ascii . $result;
                 $x = $q;
             }
             return $result;
         }
     } else {
         if (extension_loaded('bcmath') && USE_EXT == 'BCMATH') {
             if (bccomp($x, 0) != -1) {
                 if (bccomp($x, 0) == 0) {
                     return chr(0);
                 }
                 $result = "";
                 while (bccomp($x, 0) == 1) {
                     $q = bcdiv($x, 256, 0);
                     $r = bcmod($x, 256);
                     $ascii = chr($r);
                     $result = $ascii . $result;
                     $x = $q;
                 }
                 return $result;
             }
         } else {
             throw new ErrorException("Please install BCMATH or GMP");
         }
     }
 }
开发者ID:keshvenderg,项目名称:cloudshop,代码行数:38,代码来源:PrivateKey.php

示例14: leftmost_bit

 public static function leftmost_bit($x)
 {
     if (extension_loaded('gmp') && USE_EXT == 'GMP') {
         if (gmp_cmp($x, 0) > 0) {
             $result = 1;
             while (gmp_cmp($result, $x) < 0 || gmp_cmp($result, $x) == 0) {
                 $result = gmp_mul(2, $result);
             }
             return gmp_strval(gmp_div($result, 2));
         }
     } else {
         throw new ErrorException("Please install GMP");
     }
 }
开发者ID:blade-runner,项目名称:rutokenweb_php,代码行数:14,代码来源:Point.php

示例15: subint

 /**
  * Returns part of number $num, starting at bit
  * position $start with length $length
  *
  * @param gmp resource $num
  * @param int start
  * @param int length
  * @return gmp resource
  * @access public
  */
 function subint($num, $start, $length)
 {
     $start_byte = intval($start / 8);
     $start_bit = $start % 8;
     $byte_length = intval($length / 8);
     $bit_length = $length % 8;
     if ($bit_length) {
         $byte_length++;
     }
     $num = gmp_div($num, 1 << $start_bit);
     $tmp = _byte_substr($this->int2bin($num), $start_byte, $byte_length);
     $tmp = str_pad($tmp, $byte_length, "");
     $tmp = _byte_substr_replace($tmp, $tmp[$byte_length - 1] & _byte_chr(0xff >> 8 - $bit_length), $byte_length - 1, 1);
     return $this->bin2int($tmp);
 }
开发者ID:KICHIRO20,项目名称:-Myproject_part1-,代码行数:25,代码来源:GMP.php


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