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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
