array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'gmp.examples.php', 1 => '例', ), 'up' => array ( 0 => 'book.gmp.php', 1 => 'GMP', ), 'prev' => array ( 0 => 'gmp.constants.php', 1 => '定義済み定数', ), 'next' => array ( 0 => 'ref.gmp.php', 1 => 'GMP 関数', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/gmp/examples.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
例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 の階乗(非常に大きな数です)を非常に高速に計算します。