What is gmp_abs() function in PHP?

gmp_abs is a function of PHP that returns the absolute value of a GMPGNU Multiple Precision Arithmetic Library number which is passed to it as an argument.

Syntax

gmp_abs(GMP|int|string $num): GMP

Parameters

The function takes in one parameter num.

num can be a numeric string, GMP object, or of type int.

Return value

The function returns the absolute value of num. The value returned is of type GMP number.

Code

<?php
$absoluteVal1 = gmp_abs("-16567863358");
$absoluteVal2 = gmp_abs("-1346023511");
echo gmp_strval($absoluteVal1) . "\n";
echo gmp_strval($absoluteVal2) . "\n";
?>

Expected output

16567863358
1346023511
New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources