HomeLanguagesPHP | gmp_add() for adding large numbers

PHP | gmp_add() for adding large numbers

The gmp_add() is a built-in function in PHP which is used to add two GMP numbers (GNU Multiple Precision : For large numbers).

Syntax :

gmp_add ( $num1, $num2 )

Parameters: This function accepts two GMP numbers as mandatory parameters as shown in the above syntax. These can be a GMP object in PHP version 5.6 and later, or a numeric string provided that it is possible to convert the latter to a number. This function adds these two numbers and returns it.

Return Value: This function returns a GMP number which is sum of the two numbers passed as parameter.

Examples:

Input : "123456789", "987654321"
Output : 1111111110

Input : "5628179032615", "7136454221086"
Output : 12764633253701

Below programs illustrate the gmp_add() function in PHP :

Program 1 :




<?php
$sum = gmp_add("5628179032615", "7136454221086");
echo gmp_strval($sum);
  
?>
</div>


Output:

12764633253701

Program 2:




<?php
  
$sum = gmp_add("123456789", "987654321");
  
echo gmp_strval($sum);
  
?>


Output:

1111111110

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

Last Updated :
13 Apr, 2018
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS