« 定義済み定数
GMP 関数 »

例

例1 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";
?>

この例は、1000 の階乗(非常に大きな数です)を非常に高速に計算します。

関連キーワード:
階乗   定数   strval
関連する関数・ページ:
function.gmp-fact   function.gmp-strval   function.gmp-gcdext   function.strval   function.gmp-setbit   fann.examples