gmp_root()是PHP中的内置函数,该函数返回GMP编号的N-th根的整数部分(GNU多精度:适用于大数)。
用法:
gmp_pow( $num, $n )
参数:该函数接受两个强制性参数$num和$n。
- $num -这是GMP编号,其n-th根的整数部分被返回。该参数是PHP 5.6和更高版本中的GMP对象,或者也可以传递数字字符串,只要可以将该字符串转换为数字即可。
 - $n -数字的正n-th根。它是一个整数值。
 
返回值:此函数返回一个正GMP数,它是$num的N-th根的整数部分。
例子:
Input : $num = "20" $n = 2 Output : 4 Input : $num = "9" $n = 2 Output : 2
以下示例程序旨在说明gmp_root()函数:
程序1:下面的程序演示了当GMP编号作为参数传递时gmp_root()函数的工作。
<?php 
// PHP program to calculate the  
// integer part of N-th root of   
// a GMP number  
  
// GMP number as arguments  
$num = gmp_init("1001", 2);  
$n = 3; 
  
// function calculates the pow raised to  
// number modulo mod   
      
//  integer part of cubic root of 9 
$root = gmp_root($num, $n);   
  
// gmp_strval Convert GMP number to string  
// representation in given base(default 10). 
echo gmp_strval($root, 2); 
?>输出:
10
程序2:下面的程序演示了将数字字符串作为参数传递时gmp_root()的工作。
<?php 
// PHP program to calculate the  
// integer part of N-th root of   
// a GMP number  
  
// GMP number as arguments  
$num = "9";  
$n = 3; 
  
// function calculates the pow raised to  
// number modulo mod   
      
// integer part of cubic root of 9 
$root = gmp_root($num, $n);   
  
echo $root; 
?>输出:
2
程序3:程序查找数字平方根的整数部分。
<?php 
// PHP program to calculate the  
// integer part of N-th root of   
// a GMP number  
  
// GMP number as arguments  
$num = "25";  
$n = 2; 
  
// function calculates the pow raised to  
// number modulo mod   
      
// integer part of square root of 25 
$root = gmp_root($num, $n);   
  
echo $root; 
?>输出:
5
参考:
http://php.net/manual/en/function.gmp-root.php
相关用法
- p5.js nfc()用法及代码示例
 - p5.js nfp()用法及代码示例
 - d3.js d3.hcl()用法及代码示例
 - p5.js nfs()用法及代码示例
 - PHP cos( )用法及代码示例
 - PHP sin( )用法及代码示例
 - p5.js nf()用法及代码示例
 - PHP tan( )用法及代码示例
 - PHP pow( )用法及代码示例
 - d3.js d3.map.set()用法及代码示例
 - d3.js d3.set.has()用法及代码示例
 - PHP Ds\Set xor()用法及代码示例
 
注:本文由纯净天空筛选整理自ChetnaAgarwal大神的英文原创作品 PHP | gmp_root() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
