gmp_div_r()函數是PHP中的內置函數,該函數在兩個GMP數字之間執行除法運算(GNU多重精度:用於大數),並返回餘數。
用法:
gmp_div_r($num1, $num2)
參數:此函數接受兩個GMP編號$num1和$num2作為強製參數,如上麵的語法所示。這些參數可以是PHP 5.6和更高版本中的GMP對象,或者可以將數字字符串傳遞給函數,前提是可以將這些字符串轉換為數字。
返回值:此函數返回GMP編號,該編號是除法的餘數。
例子:
Input : $num1 = 146, $num2 = 12 Output : 2 Input : $num1 = "189126457831", $num2 = "12098123409" Output : 7654606696
下麵的程序將說明gmp_div_r()函數的用法。
程序1:當GMP數字作為參數傳遞時執行GMP數字除法的程序。
<?php
// PHP program to perform the division of
// GMP numbers
// creating GMP numbers using gmp_init()
$num1 = gmp_init(257);
$num2 = gmp_init(17);
// caluates the remainder when
// $num1 is divided by num2
$res = gmp_div_r($num1, $num2);
// Display the remainder
echo $res;
?>
輸出
2
程序2:將數字字符串作為GMP數字作為參數傳遞時執行GMP數字除法的程序。
<?php
// PHP program to perform the division of
// GMP numbers
// creating GMP number using gmp_init()
$a = gmp_init("7891267541121");
// calculates the remainder when
// $a is divided by 115789034
$res = gmp_div_r($a, 115789034);
// Display the remainder
echo $res;
?>
輸出
13295953
參考:http://php.net/manual/zh/function.gmp-div-r.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_div_r() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。