Open In App
Related Articles

PHP | gmp_com() Function

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
The gmp_com() is an inbuilt function in PHP which is used to calculate the one’s complement of a GMP number(GNU Multiple Precision : For large numbers). Syntax:
gmp_com($num)
Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax. This parameter can be a GMP object in PHP version 5.6 and later, or we are also allowed to pass a numeric string provided that it is possible to convert that string to a number. Return Value: This function returns a GMP number which is the one’s complement of a GMP number passed to it as parameter. Examples:
Input : gmp_com("1235")
Output : -1236

Input : gmp_com("1234")
Output : -1235
Below programs illustrate the gmp_com() function in PHP : Program 1: Program to calculate the one’s complement of a GMP number when numeric strings as GMP numbers are passed as arguments.
<?php
// PHP program to calculate the one's complement
// of a GMP number passed as arguments 
  
// strings as GMP numbers 
$num = "1345";
  
// calculate the one's complement of a GMP number
$res = gmp_com($num);
  
echo $res;
  
?>

                    
Output:
-1346
Program 2: Program to calculate the one’s complement of a GMP number when GMP number is passed as argument.
<?php
// PHP program to calculate the one's complement
// of a GMP number passed as arguments 
  
// creating GMP numbers using gmp_init()
$num = gmp_init(132);
  
// calculate the one's complement of a GMP number
$res = gmp_com($num);
  
echo $res;
  
?>

                    
Output:
-133
Reference: http://php.net/manual/en/function.gmp-com.php

Last Updated : 14 Apr, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads