PHP | gmp_neg() Function


The gmp_neg() function is an in-built function in PHP which returns the negative of a GMP number (GNU Multiple Precision).

Syntax :

gmp_neg( $num  )

Parameters : The function accepts only one mandatory parameter $num which can be either a GMP number resource in PHP 5.5 or a GMP object in PHP version 5.6 and later, or numeric strings can be passed to the function provided that it is possible to convert those strings to numbers.

Return Values : This function returns a GMP number (in PHP 5.5 and earlier) or a GMP object (in PHP 5.6 and later) which is negative of the value of $num.

Examples :



Input : $num = 255 
Output : -255

Input : $num = 128 
Output : -128

Below programs will illustrate the gmp_neg() function :

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
//PHP program to illustrate
//gmp_neg() function
  
$num = gmp_init("255");
  
$num1 = gmp_neg($num);
  
echo gmp_strval($num1);
?>

chevron_right


Output:

-255

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
//PHP program to illustrate
//gmp_neg() function
  
$num = gmp_init("314567128");
  
$num1 = gmp_neg($num);
  
echo gmp_strval($num1);
?>

chevron_right


Output:

-314567128

Reference : http://php.net/manual/en/function.gmp-neg.php

My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.