HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

gmp_sign

Description

The gmp_sign of GMP for PHP sign of a number.

Syntax

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

Parameters

num

Either a GMP object, or a numeric string provided that it is possible to convert the latter to an int.

Return

Returns 1 if num is positive, -1 if num is negative, and 0 if num is zero.

Examples

1 · num · GMP · negative

<?

$num = -10;

$num = gmp_init($num);

$return = gmp_sign($num);

echo $return;
-1

2 · num · GMP · zero

<?

$num = 0;

$num = gmp_init($num);

$return = gmp_sign($num);

echo $return;
0

3 · num · GMP · positive

<?

$num = 10;

$num = gmp_init($num);

$return = gmp_sign($num);

echo $return;
1

4 · num · int · negative

<?

$num = -10;

$return = gmp_sign($num);

echo $return;
-1

5 · num · int · zero

<?

$num = 0;

$return = gmp_sign($num);

echo $return;
0

6 · num · int · positive

<?

$num = 10;

$return = gmp_sign($num);

echo $return;
1

7 · num · string · negative

<?

$num = "-10";

$return = gmp_sign($num);

echo $return;
-1

8 · num · string · zero

<?

$num = "0";

$return = gmp_sign($num);

echo $return;
0

9 · num · string · positive

<?

$num = "10";

$return = gmp_sign($num);

echo $return;
1