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

Free Resources