编程学问
  • 文章
  • 问题
  • 读书
  • 关于
  • 登录
  • « 预定义常量
  • 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 函数 add numbersphp gmp 函数 bitwise andphp gmp 函数 calculates binomial coefficientphp gmp 函数 clear bitphp gmp 函数 compare numbersphp gmp 函数 calculates one s complementphp gmp 函数 import from a binary stringphp gmp 函数 create gmp numberphp gmp 函数 convert gmp number to integerphp gmp 函数 inverse by modulophp gmp 函数 jacobi symbolphp gmp 函数 raise number into powerphp gmp 函数 raise number into power with modulophp gmp 函数 check if number is probably prime php gmp 函数 random numberphp gmp 函数 random numberphp gmp 函数 subtract numbersphp gmp 函数 tests if a bit is setphp gmp 函数 bitwise xorphp gmp 简介
关注编程学问公众号
编程学问网 湘ICP备20001732号