The gmp_sign() is an in-built function in PHP which checks the sign of a given GMP number (
GNU Multiple Precision: For large numbers).
Syntax:
gmp_sign($num)
Parameters: This function accepts one GMP number
$num as mandatory parameter shown in the above syntax. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number.
Return Value: The function checks the sign of the given number
$num and returns three values depending on the number as described below:
- Returns 1 - $num is positive
- Returns -1 - $num is negative
- Returns 0 - $num is zero
Examples:
Input : $num=9
Output : 1
Input : $num=-8
Output : -1
Input : $num=0
Output : 0
Below programs illustrate the gmp_sign() function:
Program 1: The program below demonstrates the working of gmp_sign() function when GMP number is passed as an argument.
Output:
-1
1
0
Program 2: The program below demonstrates the working of gmp_sign() when numeric string is passed as an argument.
Output:
-1
1
0
Reference:
https://www.php.net/manual/en/function.gmp-sign.php