PHP - gmp_add() Functions
Definition and Usage
The gmp_add() function returns the sum of two numbers.
Description
gmp_add() will add two numbers.
Syntax
gmp_add ( GMP $num1 , GMP $num2 ) : GMP
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
num1 It can a GMP resource number , a gmp object or a numeric string . |
| 2 |
num2 It can a GMP resource number , a gmp object or a numeric string . |
Return Values
PHP gmp_add () function returns sum of two given numbers.
PHP Version
This function will work from PHP Version greater than 5.0.0.
Example 1
Working of gmp_add() −
<?php
$sum = gmp_add("1234567890167675", "76543210987655");
echo "The sum is :".gmp_strval($sum);
?>
This will produce following result −
The sum is :1311111101155330
Example 2
Adding negative numbers −
<?php
$sum = gmp_add("-1234567890167675", "-76543210987655");
echo "The sum is :".gmp_abs($sum);
?>
This will produce following result −
The sum is :1311111101155330
php_function_reference.htm
Advertisements