Your path to becoming an Ethical Hacker! Hacking Academy Try It Now!

PHP GMP Functions

Learn about PHP GMP functions for handling large numbers. Perform advanced math operations like addition, subtraction, division, and more.
The GMP function in PHP lets you work with very large numbers to do math operations. This function takes a GMP number as an input.

PHP GMP Functions

Here’s an example of a program that divides GMP numbers using numeric strings as inputs.

<?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 Functions 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 (quotient).
gmp_div_qr() The division operation between two GMP numbers (quotient and remainder).
gmp_div_r() Performs the division operation between two GMP numbers (remainder).
gmp_divexact() Check whether a GMP number is exactly divisible by another GMP number.
gmp_export() Exports a GMP number to a binary string.
gmp_fact() Calculate the factorial of a GMP number.
gmp_gcd() Calculate the Greatest Common Divisor (GCD) of 2 GMP numbers.
gmp_gcdext() Calculates the GCD and multipliers of a given equation.
gmp_hamdist() Find the Hamming distance between two GMP numbers (number of differing bits).
gmp_import() Imports a binary string as a GMP number.
gmp_intval() Converts a GMP number to an integer (if possible).
gmp_invert() Find the modular inverse of a GMP number.
gmp_jacobi() Computes the Jacobi symbol of two GMP numbers (advanced mathematical property).
gmp_legendre() Computes the Legendre symbol of two GMP numbers (another advanced mathematical property).
gmp_mod() Find the modulo of a GMP number (remainder after division).
gmp_mul() It is used to multiply two GMP numbers.
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 is a perfect square (a number which can be obtained by squaring an integer).
gmp_popcount() Find the population count of a GMP number (number of set bits).
gmp_pow() Calculate the power raised to a number of a GMP number and an integer.
gmp_prob_prime() Check how probable it is for a given GMP number to be prime.
gmp_random_bits() Generates a random GMP number with a specified number of bits.
gmp_random_range() Generates a random GMP number between a specified minimum and maximum value.
gmp_random_seed() Sets the seed for the random number generator used by GMP functions.
gmp_scan0() Finds the index of the first zero bit in a GMP number.
gmp_scan1() Finds the index of the first one bit in a GMP number.
gmp_setbit() Sets the bit at a specified index in a GMP number to 1.
gmp_sign() Checks the sign of a given GMP number (positive, zero, or negative).
gmp_sqrt() Calculate the square root of a GMP number (exact root).
gmp_sqrtrem() Calculates the square root and remainder of a GMP number.
gmp_strval() Returns the string value of a GMP number (base 10 representation).
gmp_sub() Returns the subtraction of the two GMP numbers.
gmp_testbit() Checks if the specified bit of a given GMP number is set to 1.
gmp_xor() Calculate the bitwise XOR of 2 GMP numbers.

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.