gmp_div_qr()函数是PHP中的内置函数,该函数执行两个GMP数字之间的除法运算(GNU多重精度:用于大数),并返回商和余数。
用法:
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/zh/function.gmp-div-qr.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_qr() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
