What is gmp_neg in PHP?

gmp_neg is a function in PHP that returns the negative of a GMP number.

The following illustration shows the visual representation of the gmp_neg function.

Visual representation of the gmp_neg function.

Syntax

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

Parameters

The function takes in one parameter: num.

num can be a numeric string, GMPGNU Multiple Precision Arithmetic Library object, or of theint type.

Return value

The function returns the negative of a number. The value returned is a GMP type number.

Code

<?php
$val1 = gmp_neg("22");
echo gmp_strval($val1) . "\n";
$val2 = gmp_neg("-12456");
echo gmp_strval($val2) . "\n";
?>

Expected output

-22
12456

Free Resources