
PHP gmp_abs() Function
As of my last update in September 2021, the gmp_abs()
function in PHP is used to calculate the absolute value of a GMP (GNU Multiple Precision) number. The absolute value of a number is its magnitude without considering its sign.
Here’s the syntax of the gmp_abs()
function:
GMP gmp_abs ( GMP $num )
Parameters:
$num
: The GMP number for which you want to calculate the absolute value.
Return value:
- The absolute value of the GMP number as a new GMP number.
Example:
$negativeNum = gmp_init('-123');
$positiveNum = gmp_abs($negativeNum);
echo gmp_strval($positiveNum); // Output: 123
In this example, the gmp_abs()
function is used to calculate the absolute value of the GMP number -123
, which results in 123
.
The gmp_abs()
function is helpful when you need to ensure that a number is positive or when you want to ignore the sign of a number while performing calculations.
As with other GMP functions, make sure that the GMP extension is enabled in your PHP configuration to use this function. Additionally, please note that the availability of functions may change in newer PHP versions, so always refer to the PHP manual for the specific version you are using.