编程学问
  • 文章
  • 问题
  • 读书
  • 关于
  • 登录
  • « 预定义常量
  • GMP 函数 »
  • PHP Manual
  • GMP
  • 范例

范例

Example #1 Factorial function using GMP

<?php
function fact($x) 
{
    
$return = 1;
    for (
$i=2; $i <= $x; $i++) {
        
$return = gmp_mul($return, $i);
    }
    return 
$return;
}

echo 
gmp_strval(fact(1000)) . "\n";
?>

This will calculate factorial of 1000 (pretty big number) very fast.

相关文章
php gmp the gmp classphp gmp 函数 divide numbers and get quotient and remainderphp gmp 函数 remainder of the division of numbersphp gmp 函数 别名 gmp div qphp gmp 函数 exact division of numbersphp gmp 函数 export to a binary stringphp gmp 函数 factorialphp gmp 函数 legendre symbolphp gmp 函数 modulo operationphp gmp 函数 multiply numbersphp gmp 函数 negate numberphp gmp 函数 find next prime numberphp gmp 函数 take the integer part of nth rootphp gmp 函数 take the integer part and remainder of nth rootphp gmp 函数 scan for 0php gmp 函数 scan for 1php gmp 函数 set bitphp gmp 预定义常量php gmp 范例php gmp gmp 函数
关注编程学问公众号
编程学问网 湘ICP备20001732号