PHP | gmp_rootrem()函数

gmp_rootrem()是PHP中的一个内置函数,用于计算gmp数的第n个根(GNU Multiple Precision:对于大数),并返回第n个根的整数分量及其余数。

null

语法:

gmp_rootrem($num,$n)

参数: 此函数接受两个必需参数,如上述语法所示。具体如下:

  • $num: 参数可以是PHP 5.6及更高版本中的GMP对象,也可以传递一个数字字符串,前提是可以将该字符串转换为数字。
  • $n: 要计算的正根 $num .

例如:

Input : $num = "8" $n = 2
Output :  Array ( 
                    [0] => GMP Object ( [num] => 2 )
                    [1] => GMP Object ( [num] => 4 )
                   )

Input : $num = "9" $n = 2
Output : Array ( 
                  [0] => GMP Object ( [num] => 3 )
                  [1] => GMP Object ( [num] => 0 ) 
              )

返回值: 此函数返回两个元素的数组,两个元素都是数字。

  • 这个 第一要素 数组中的 整数分量 $num的第n个根。
  • 这个 第二要素 是吗 余数 .

下面的程序将演示如何在PHP中使用gmp_rootrem()函数:

项目1: 下面的程序演示了以GMP编号作为参数传递的函数的用法。

<?php
// PHP program to calculate the
// integer part and remainder
// of nth root of a gmp number
// GMP number as arguments
$num = gmp_init(8);
$n = 3;
$rootrem = gmp_rootrem( $num , $n );
//Display the array elements
echo print_r( $rootrem );
?>


输出

Array
(
    [0] => GMP Object ( [num] => 2 )
    [1] => GMP Object ( [num] => 0 )
)

项目2: 下面的程序演示了将数字字符串作为参数传递的函数的用法。

<?php
// PHP program to calculate the
// integer part and remainder
// of nth root of a gmp number
// Numeric string as argument
$num = "178924890" ;
$n = 3;
$rootrem = gmp_rootrem( $num , $n );
//Display the array elements
echo print_r( $rootrem );
?>


输出

Array (
 [0] => GMP Object ( [num] => 563 ) 
[1] => GMP Object ( [num] => 471343 )  
)

参考: http://php.net/manual/en/function.gmp-rootrem.php

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享