gmp_sqrtrem()是PHP中的內置函數,用於計算GMP數(GNU倍數精度:對於大數)的平方根和餘數。此函數還僅返回GMP編號平方根中的整數部分作為gmp_sqrt()函數。其餘部分本質上是GMP編號與該函數返回的平方根值的平方之間的差。
用法:
gmp_sqrtrem ( $num )
參數:此函數接受GMP數字$num作為強製參數,如上麵的語法所示,我們要計算其平方根。此參數可以是PHP 5.6和更高版本中的GMP對象,或者也可以傳遞數字字符串,隻要可以將該字符串轉換為數字即可。
返回值:此函數返回兩個GMP編號的數組。此數組中的第一個元素是傳遞給函數的GMP編號平方根的整數部分,第二個元素是餘數。餘數計算為GMP編號與該數組第一個元素的平方之間的差。
例子:
Input : "9" Output : 3 Input : "24" Output : 4
以下示例程序旨在說明PHP中的gmp_sqrtrem()函數:
程序1:當將數字字符串作為GMP數字作為參數傳遞時,程序將計算GMP數字餘數的平方根。
<?php 
// PHP program to calculate the square root  
// of a GMP number 
  
// passing numeric strings as GMP numbers 
$num = gmp_init("24"); 
  
// calculates the square root of a GMP number 
// with remainder 
list($squareRoot, $rem) = gmp_sqrtrem($num); 
  
echo $squareRoot." ".$rem; 
  
?>輸出:
4 8
程序2:當GMP數字作為參數傳遞時,用GMP數字的餘數計算平方根的程序。
<?php 
// PHP program to calculate the square root  
// of a GMP number 
  
// creating GMP numbers using gmp_init() 
$num = gmp_init(24, 10); 
  
// calculates the square root of a GMP number 
// with remainder 
list($squareRoot, $rem) = gmp_sqrtrem($num); 
  
echo $squareRoot." ".$rem; 
  
?>輸出:
4 8
參考:
http://php.net/manual/en/function.gmp-sqrtrem.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()用法及代碼示例
注:本文由純淨天空篩選整理自barykrg大神的英文原創作品 PHP | gmp_sqrtrem() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
