gmp_sign


gmp apg

CHECKS the sign of a GMP number.





This function returns:

 1 if $num > 0,

-1 if $num < 0

and

 0 if $num = 0.



<?php

int gmp_sign 
GMP|int|string $num )


where,

$num Parameter to be checked

?>
 

$num


Parameter to be checked.



  1 EXERCISE   

<?php

function signtest($a01)
{
    if( 
gmp_sign($a01) == )
    {
        echo 
$a01 ' is positive.<br><br>';
    }
elseif( 
gmp_sign($a01) == -)
    {
        echo 
$a01 ' is negative.<br><br>';
    }
else
{
    echo 
$a01 ' is neither negative nor positive.<br><br>';
}
}    

$a01a 256;

$a01b = -256;

$a01c '256';

$a01d '0';

$a01e 'TEST';

signtest($a01a);

signtest($a01b);

signtest($a01c);

signtest($a01d);


/* 
  Try the next in PHP 7.4.XX and in PHP 8.0.XX
  to see the differences
*/

// signtest($a01e);
 
?> 

 RESULT   

256 is positive.

-256 is negative.

256 is positive.

0 is neither negative nor positive.

TEST -> Warning in PHP 7.4.XX and Fatal error in PHP 8.0.XX