# PHP gmp_div_qr()函数用法详细介绍

2021年3月13日16:39:02 发表评论 618 次浏览

gmp_div_qr()函数是PHP中的内置函数, 可在两个GMP编号之间执行除法运算

(GNU多重精度：适用于大数)

``gmp_div_qr(\$num1, \$num2)``

• 首先是商师。
• 第二个是余师。

``````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 ) )``````

``````<?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 )
)``````

``````<?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 )
)``````