Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
communitycreator

What is gmp_div_qr in PHP?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

gmp_div_qr is a function in PHP that returns the remainder and quotient after dividing the numbers.

Syntax


gmp_div_qr(GMP|int|string $number1, GMP|int|string $number2, int $rounding_mode = GMP_ROUND_ZERO): array

Parameters

  • number1: The number that is going to be divided.

  • number2: The number that number1 is divided by.


    number1 and number2 can be a GMP object, integer, or numeric string.


  • rounding_mode: The resultant rounding is defined by the rounding_mode. This can take the values listed below:

    • GMP_ROUND_ZERO: The result is truncated towards 0.

    • GMP_ROUND_PLUSINF: The result is rounded towards positive infinity.

    • GMP_ROUND_MINUSINF: The result is rounded towards negative infinity.

Return value

The function returns the remainder and quotient after dividing the numbers.

The value returned is of array type. The 1st element of the array will be the quotient, and the 2nd element of the array will be the remainder.

Code

<?php
//gmp_init is used to create GMP number
$val1 = gmp_init(257);
$val2 = gmp_init(17);
$result = gmp_div_qr($val1, $val2);
print_r($result);
?>

Output


Array 
( 
[0] => GMP Object ( [num] => 15 ) 
[1] => GMP Object ( [num] => 2 ) 
)

RELATED TAGS

php
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring