📅  最后修改于: 2023-12-03 14:45:16.781000             🧑  作者: Mango
gmp_root()
函数是PHP中的一个gmp扩展函数,它用于计算一个大整数的平方根或算术平均根。
gmp_root ( GMP $a , int $nth )
$a
: 要计算平方根或算术平均根的GMP数。$nth
: 平方根或算术平均根的次数。如果成功,gmp_root()
函数将返回一个GMP数作为计算所得的平方根或算术平均根。
计算一个大整数的平方根。
<?php
$a = gmp_init("9");
$root = gmp_root($a, 2);
echo gmp_strval($root); // 输出: 3
?>
计算一个大整数的3次算术平均根。
<?php
$a = gmp_init("27");
$root = gmp_root($a, 3);
echo gmp_strval($root); // 输出: 3
?>
gmp_root()
函数将返回错误。$nth
参数必须是正整数。$a
参数必须是一个GMP数。如果是一个字符串或浮点数,它会被转换为GMP数。