gmp_rootrem()是PHP中的内置函数,用于计算GMP数的第n个根(GNU多重精度:对于大数),并返回第n个根及其剩余部分的整数分量。
用法:
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 ) 
              )
返回值:此函数返回一个由两个元素组成的数组,两个元素均为GMP编号。
- 数组的第一个元素是$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/zh/function.gmp-rootrem.php
相关用法
- p5.js sq()用法及代码示例
 - d3.js d3.map.has()用法及代码示例
 - PHP next()用法及代码示例
 - p5.js day()用法及代码示例
 - p5.js pow()用法及代码示例
 - CSS var()用法及代码示例
 - d3.js d3.map.set()用法及代码示例
 - PHP pow( )用法及代码示例
 - PHP pi( )用法及代码示例
 - PHP Ds\Map get()用法及代码示例
 - PHP Ds\Map put()用法及代码示例
 - p5.js str()用法及代码示例
 
注:本文由纯净天空筛选整理自RICHIK BHATTACHARJEE大神的英文原创作品 PHP | gmp_rootrem() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
