Last Updated:

Arithmetic functions in PHP

Adding two numbers.


Syntax:
recource gmp_add (resource x, recource y)
Function will return a GMP number equal to the sum of the x and y arguments.

gmp_sub

Subtract two numbers.


Syntax:
recource gmp_sub (resource x, recource y)
Function will return a GMP number equal to the difference between the x and y arguments.

 

gmp_mul

gmp_mul

Multiplication of two numbers.


Syntax:
recource gmp_mul (resource x, recource y)
The function will return a GMP number equal to the product of the x and y arguments.

gmp_div

Dividing two numbers.


Syntax:
recource gmp_div (resource x, recource y [, int round])

The function will return a GMP number equal to dividing the arguments x by y. Depending on the optional round parameter, the result of the division will be rounded as follows:


This function is synonymous with gmp_div_q ().

gmp_div_q

Dividing two numbers.


Syntax:
recource gmp_div_q (resource x, recource y [, int round])


The function will return a GMP number equal to dividing the arguments x by y. Depending on the optional round parameter, the result of the division will be rounded as follows:

This function has a synonym - gmp_div ().

gmp_div_r

Returns the remainder of an integer division.


Syntax:
recource gmp_div_r (resource x, recource y [, int round])

The function returns the remainder of dividing x by y. The character will be inherited from the x argument.

gmp_div_qr

Performs division with the remainder.


Syntax:
array gmp_div_qr (resource x, recource y [, int round])
This function combines the action of the two previous functions gmp_div_q () and gmp_div_r (). It returns an array consisting of two elements:
$x=gmp_init ("0xf3c3b5");
$result=gmp_div_qr ($x, «0xb1»);
echo "Whole: ".gmp[strval($result[0]);
echo "Remainder: ".gmp[strval($result[1]);
gmp_mod

Returns the module of the remainder of the division.


Syntax:
resource gmp_mod (resource x, recource y)
This function is equivalent to gmp_div_r (), except that it returns an absolute value.

gmp_divexact

Performs a non-stop division.


Syntax:
resource gmp_divexact (resource x, recource y)
This function uses an "exact" division algorithm. The result will only be reliable if x is purposefully divisible y.

gmp_cmp

Compares two numbers.


Syntax:
int gmp_cmp (resource x, recource y)
The function will return a positive value if x y; zero, elsi x = y; negative if x < y.