PHP | gmp_div_q()函数

gmp_div_q()是PHP中的一个内置函数,用于对gmp编号进行除法( GNU多重精度:适用于大数字 ).

null

语法:

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

© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享