gmp_div_qr()函数是PHP中的一个内置函数,用于执行两个gmp编号之间的除法运算 (GNU多重精度:适用于大数字) 并返回商和余数。 语法:
null
gmp_div_qr($num1, $num2)
参数: 此函数接受两个GMP编号,$num1和$num2作为强制参数,如上述语法所示。这些参数可以是PHP 5.6版及更高版本中的GMP对象,也可以将数字字符串传递给函数,前提是可以将这些字符串转换为数字。
返回值: 此函数返回一个包含两个组件的数组:
- 首先是 商 该部门的负责人。
- 第二个是 余数 该部门的负责人。
例如:
Input : $num1 = 146, $num2 = 12 Output : Quotient = 12, Remainder = 2 Array ( [0] => GMP Object ( [num] => 12 ) [1] => GMP Object ( [num] => 2 ) ) Input : $num1 = 189126457831, $num2 = 12098123409 Output : Quotient = 15, Remainder = 7654606696 Array ( [0] => GMP Object ( [num] => 15) [1] => GMP Object ( [num] => 7654606696 ) )
下面的程序将演示gmp_div_qr()函数的使用。
项目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); // calculates the quotient and remainder // when $num1 is divided by num2 $res = gmp_div_qr( $num1 , $num2 ); // Printing the Array elements, i.e. // the quotient and remainder print_r( $res ); ?> |
输出
Array ( [0] => GMP Object ( [num] => 15 ) [1] => GMP Object ( [num] => 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 quotient when // $a is divided by 115789034 $res = gmp_div_qr( $a , "115789034" ); // Printing the Array elements, i.e. // the quotient and remainder print_r( $res ); ?> |
输出
Array ( [0] => GMP Object ( [num] => 68152 ) [1] => GMP Object ( [num] => 13295953 ) )
参考: http://php.net/manual/en/function.gmp-div-qr.php
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END