Open In App

PHP GMP Functions Complete Reference

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

The GMP function uses arbitrary-length integers to perform mathematical operations. The GMP function contains the GMP number as an argument. 

Example:  Program to perform the division of GMP numbers when numeric strings as GMP numbers are passed as arguments.

PHP




<?php
// PHP program to perform division of
// GMP numbers passed as arguments
 
// strings as GMP numbers
$num1 = "-6";
$num2 = "2";
 
// calculates the quotient when
// $num1 is divided by $num2
$quo = gmp_div_q($num1, $num2);
     
echo $quo;
?>


Output:

-3

The complete list of GMP functions are given below:

 

PHP GMP Function

Description

gmp_abs() Calculate the absolute value of a GMP number 
gmp_add() It is used to add two GMP numbers.
gmp_clrbit() The gmp_clrbit() function sets the bit at a specified index in a GMP number to 0. 
gmp_cmp() Compare two GMP numbers.
gmp_com() Calculate the one’s complement of a GMP number
gmp_div_q() Perform the division of GMP numbers(
gmp_div_qr() The division operation between two GMP numbers
gmp_div_r() Performs the division operation between two GMP numbers
gmp_divexact() Check whether a GMP number
gmp_export() That exports to a binary string.
gmp_fact() Calculate the factorial of a GMP number
gmp_gcd() Calculate the GCD of 2 GMP numbers 
gmp_gcdext() Calculates the GCD and  and multipliers of a given equation
gmp_hamdist() Find the hamming distance between two GMP numbers 
gmp_import() That imports a GMP numb
gmp_intval() Converts a GMP number to an integer.
gmp_invert() Find the modular inverse of a GMP number
gmp_jacobi() Computes the Jacobi symbol of two GMP numbers
gmp_legendre() Computes the Legendre symbol of two GMP numbers
gmp_mod() Find the modulo of a GMP number(
gmp_mul() It is used to multiply two GMP numb
gmp_neg() Returns the negative of a GMP number
gmp_nextprime() Calculate the prime number just greater than a given GMP number
gmp_perfect_square() Checks if the given GMP number
gmp_popcount() Find the population count of a GMP number 
gmp_pow()  Calculate the power raised to a number of a GMP number and an integer 
gmp_prob_prime() Check how much the possibility of a given GMP number
gmp_random_bits() Generates a random number. 
gmp_random_range()  Generated lies between the range min to max. 
gmp_random_seed() Sets the RNG to see
gmp_root() Returns the integer part of the N-th root of a GMP number
gmp_rootrem() Calculate the nth root of a GMP number (GNU Multiple Precision: For large numbers)
gmp_scan0() Fun It is used to scan “0” in a GMP numb
gmp_scan1() It is used to scan “1” in the GMP number
gmp_setbit() Set the bit index in the given $num.
gmp_sign() Checks the sign of a given GMP number
gmp_sqrt() Calculate the square root of a GMP number
gmp_sqrtrem() Calculate the square root of a GMP number
gmp_strval() Returns the string value of a GMP number.
gmp_sub() Returns the subtraction of the two GMP numbers.
gmp_testbit() Checks if the specified bit of a given GMP number
gmp_xor() Calculate the XOR of 2 GMP numbers
gmp_random() Random numbers will be between zero and the number of bits per limb 


Last Updated : 24 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads