Computer >> Computer tutorials >  >> Programming >> PHP

gmp_sign() function in PHP


The gmp_sign() function checks the sign of a given GMP number.

Syntax

gmp_sign(val)

Parameters

  • val: The GMP number. It can be GMP object in PHP version 5.6 and later. Can also be numeric strings

Return

The gmp_sign() function checks the sign of the given val. The return values can be 1 if val is positive, -1 if val is negative, and 0 if val is zero.

Example

The following is an example:

<?php
   $val = 0;
   echo gmp_sign($val);
?>

Output

The following is the output:

0

Example

Let us see another example:

<?php
   $val = -10;
   echo gmp_sign($val);
?>

Output

The following is the output:

-1