• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP gmp_div函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: div

 /**
  * Divide numbers
  *
  * @param mixed $number
  * @access public
  * @return self
  */
 public function div($number)
 {
     $result = gmp_div($this->getRawValue(), static::upgradeParam($number)->getRawValue(), GMP_ROUND_ZERO);
     return static::factory($result);
 }
开发者ID:lamannapov,项目名称:mathematician,代码行数:12,代码来源:Gmp.php


示例17: gmp_shiftr

function gmp_shiftr($x, $n)
{
    return gmp_div($x, gmp_pow(2, $n));
}
开发者ID:captincook,项目名称:Pony,代码行数:4,代码来源:misc.php


示例18: readFiletime

 /**
  * Read Windows FileTime and convert to Unix timestamp
  * Filetime = 64-bit value with the number of 100-nsec intervals since Jan 1, 1601 (UTC)
  * Based on http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/
  * @return Unix timestamp, or -1 on error
  */
 private function readFiletime()
 {
     // Unix epoch (1970-01-01) - Windows epoch (1601-01-01) in 100ns units
     $EPOCHDIFF = '116444735995904000';
     $UINT32MAX = '4294967296';
     $USEC2SEC = 1000000;
     $lo = $this->readInt32();
     $hi = $this->readInt32();
     // check for 64-bit platform
     if (PHP_INT_SIZE >= 8) {
         // use native math
         if ($lo < 0) {
             $lo += 1 << 32;
         }
         $date = ($hi << 32) + $lo;
         $this->debugLog(sprintf('PAK CreationDate source: %016x', $date));
         if ($date == 0) {
             return -1;
         }
         // convert to Unix timestamp in usec
         $stamp = ($date - (int) $EPOCHDIFF) / 10;
         $this->debugLog(sprintf('PAK CreationDate 64-bit: %u.%06u', $stamp / $USEC2SEC, $stamp % $USEC2SEC));
         return (int) ($stamp / $USEC2SEC);
         // check for 32-bit platform
     } elseif (PHP_INT_SIZE >= 4) {
         $this->debugLog(sprintf('PAK CreationDate source: %08x%08x', $hi, $lo));
         if ($lo == 0 && $hi == 0) {
             return -1;
         }
         // workaround signed/unsigned braindamage on x32
         $lo = sprintf('%u', $lo);
         $hi = sprintf('%u', $hi);
         // try and use GMP
         if (function_exists('gmp_mul')) {
             $date = gmp_add(gmp_mul($hi, $UINT32MAX), $lo);
             // convert to Unix timestamp in usec
             $stamp = gmp_div(gmp_sub($date, $EPOCHDIFF), 10);
             $stamp = gmp_div_qr($stamp, $USEC2SEC);
             $this->debugLog(sprintf('PAK CreationDate GNU MP: %u.%06u', gmp_strval($stamp[0]), gmp_strval($stamp[1])));
             return (int) gmp_strval($stamp[0]);
         }
         // try and use BC Math
         if (function_exists('bcmul')) {
             $date = bcadd(bcmul($hi, $UINT32MAX), $lo);
             // convert to Unix timestamp in usec
             $stamp = bcdiv(bcsub($date, $EPOCHDIFF), 10, 0);
             $this->debugLog(sprintf('PAK CreationDate BCMath: %u.%06u', bcdiv($stamp, $USEC2SEC), bcmod($stamp, $USEC2SEC)));
             return (int) bcdiv($stamp, $USEC2SEC);
         }
         // compute everything manually
         $a = substr($hi, 0, -5);
         $b = substr($hi, -5);
         // hope that float precision is enough
         $ac = $a * 42949;
         $bd = $b * 67296;
         $adbc = $a * 67296 + $b * 42949;
         $r4 = substr($bd, -5) + substr($lo, -5);
         $r3 = substr($bd, 0, -5) + substr($adbc, -5) + substr($lo, 0, -5);
         $r2 = substr($adbc, 0, -5) + substr($ac, -5);
         $r1 = substr($ac, 0, -5);
         while ($r4 >= 100000) {
             $r4 -= 100000;
             $r3++;
         }
         while ($r3 >= 100000) {
             $r3 -= 100000;
             $r2++;
         }
         while ($r2 >= 100000) {
             $r2 -= 100000;
             $r1++;
         }
         $date = ltrim(sprintf('%d%05d%05d%05d', $r1, $r2, $r3, $r4), '0');
         // convert to Unix timestamp in usec
         $r3 = substr($date, -6) - substr($EPOCHDIFF, -6);
         $r2 = substr($date, -12, 6) - substr($EPOCHDIFF, -12, 6);
         $r1 = substr($date, -18, 6) - substr($EPOCHDIFF, -18, 6);
         if ($r3 < 0) {
             $r3 += 1000000;
             $r2--;
         }
         if ($r2 < 0) {
             $r2 += 1000000;
             $r1--;
         }
         $stamp = substr(sprintf('%d%06d%06d', $r1, $r2, $r3), 0, -1);
         $this->debugLog(sprintf('PAK CreationDate manual: %s.%s', substr($stamp, 0, -6), substr($stamp, -6)));
         return (int) substr($stamp, 0, -6);
     } else {
         return -1;
     }
 }
开发者ID:keverage,项目名称:adminserv,代码行数:98,代码来源:gbxdatafetcher.inc.php


示例19: gmp_dec2base

 public static function gmp_dec2base($dec, $base, $digits = FALSE)
 {
     if (extension_loaded('gmp')) {
         if ($base < 2 or $base > 256) {
             die("Invalid Base: " . $base);
         }
         $value = "";
         if (!$digits) {
             $digits = self::digits($base);
         }
         $dec = gmp_init($dec);
         $base = gmp_init($base);
         while (gmp_cmp($dec, gmp_sub($base, '1')) > 0) {
             $rest = gmp_mod($dec, $base);
             $dec = gmp_div($dec, $base);
             $value = $digits[gmp_intval($rest)] . $value;
         }
         $value = $digits[gmp_intval($dec)] . $value;
         return (string) $value;
     } else {
         throw new ErrorException("Please install GMP");
     }
 }
开发者ID:jgabrielfreitas,项目名称:MultipagosTestesAPP,代码行数:23,代码来源:gmp_Utils.php


示例20: getCombinationCount

 /**
  * Return the number of not ordered, none repetitive combination of size [$combinationSize] existing in [$itemCount] elements
  *
  * If GMP is installed, GMP will be used to compute this value,
  * If libbcmath is installed, bcmath will be used for all mathematics operation.
  *
  * If none of previous library is available, then basic php functions will be used,
  * so the function could result in an error or php can return INF.
  *
  * If GMP is not installed, be aware of the "Maximum function nesting level" value.
  *
  * @param int $itemCount       The number of possible element
  * @param int $combinationSize The size of each combination
  *
  * @return int The number of combination
  *
  * @throws \InvalidArgumentException If [$itemCount] < 0 or [$combinationSize] > [$itemCount]
  */
 public static function getCombinationCount($itemCount, $combinationSize)
 {
     if (function_exists('gmp_mul') && function_exists('gmp_div')) {
         return gmp_strval(gmp_div(self::factorial($itemCount), gmp_mul(self::factorial($combinationSize), self::factorial($itemCount - $combinationSize))));
     } elseif (function_exists('bcmul') && function_exists('bcdiv')) {
         return bcdiv(self::factorial($itemCount), bcmul(self::factorial($combinationSize), self::factorial($itemCount - $combinationSize)));
     }
     return self::factorial($itemCount) / (self::factorial($combinationSize) * self::factorial($itemCount - $combinationSize));
 }
开发者ID:macfja,项目名称:math,代码行数:27,代码来源:CombinationBuilder.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP gmp_div_q函数代码示例发布时间:2022-05-15
下一篇:
PHP gmp_cmp函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap