gmp_div_q()是PHP中的一個內置函數,用於執行GMP數的除法(GNU多精度:適用於大數)。
用法:
gmp_div_q($num1, $num2)
參數:此函數接受GMP編號$num1和$num2作為強製性參數,如上麵的語法所示。這些參數可以是PHP 5.6及更高版本中的GMP對象,或者也可以傳遞數字字符串,以便可以將這些字符串轉換為數字。
返回值:此函數返回一個GMP數字,該數字是$num1除以$num2時的商。函數根據$num1和$num2的值返回正,負或零。
例子:
Input : gmp_div_q("256", "16") Output : 16 Input : gmp_div_q("188", "4") Output : 47
以下示例程序旨在說明PHP中的gmp_div_q()函數:
程序1:將數字字符串作為GMP數字作為參數傳遞時執行GMP數字除法的程序。
<?php
// PHP program to perform division of
// GMP numbers passed as arguments
// strings as GMP numbers
$num1 = "-6";
$num2 = "2";
// caluates the quotient when
// $num1 is divided by $num2
$quo = gmp_div_q($num1, $num2);
echo $quo;
?>
輸出:
-3
程序2:當GMP數字作為參數傳遞時執行GMP數字除法的程序。
<?php
// PHP program to perform the division of
// GMP numbers
// creating GMP numbers using gmp_init()
$num1 = gmp_init(289);
$num2 = gmp_init(17);
// caluates the quotient when
// $num1 is divided by $num2
$quo = gmp_div_q($num1, $num2);
echo $quo;
?>
輸出:
17
程序3:當GMP數字作為參數傳遞時執行GMP數字除法的程序。
<?php
// PHP program to perform the division of
// GMP numbers
// creating GMP numbers using gmp_init()
$num1 = gmp_init(3);
$num2 = gmp_init(4);
// caluates the quotient when
// $num1 is divided by $num2
$quo = gmp_div_q($num1, $num2);
echo $quo;
?>
輸出:
0
參考:
http://php.net/manual/en/function.gmp-div-q.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()用法及代碼示例
注:本文由純淨天空篩選整理自akash1295大神的英文原創作品 PHP | gmp_div_q() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。