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

gmp_neg

Description

The gmp_neg of GMP for PHP negates a number.

Syntax

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

Parameters

num

A GMP object, an int or a numeric string.

Return

Returns -num, as a GMP number.

Examples

1 · num · GMP · negative

<?

$num = -1;

$num = gmp_init($num);

$return = gmp_neg($num);

var_dump($return);

?>
object(GMP)#2 (1) {
  ["num"]=>
  string(1) "1"
}

2 · num · GMP · positive

<?

$num = 1;

$num = gmp_init($num);

$return = gmp_neg($num);

var_dump($return);

?>
object(GMP)#2 (1) {
  ["num"]=>
  string(2) "-1"
}

3 · num · int · negative

<?

$num = -1;

$return = gmp_neg($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

4 · num · int · positive

<?

$num = 1;

$return = gmp_neg($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(2) "-1"
}

5 · num · string · negative

<?

$num = "-1";

$return = gmp_neg($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(1) "1"
}

6 · num · string · positive

<?

$num = "1";

$return = gmp_neg($num);

var_dump($return);

?>
object(GMP)#1 (1) {
  ["num"]=>
  string(2) "-1"
}
HomeMenu