PHP | gmp_sqrtrem() Function
The gmp_sqrtrem() is a built-in function in PHP which is used to calculate the square root of a GMP number (GNU Multiple Precision : For large numbers) with remainder. This function also returns only the integral part in the square root of the GMP number as the gmp_sqrt() function. The remainder is basically the difference between the GMP number and the square of the square root value as returned by this function.
Syntax:
gmp_sqrtrem ( $num )
Parameters: This function accepts a GMP number $num as a mandatory parameter as shown in the above syntax whose square root we want to calculate. 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 an array of two GMP numbers. The first element in this array is the integral part in the square root of the GMP number passed to the function as parameter and the second element is the remainder. The remainder is calculated as the difference between the GMP number and the square of first element of this array.
Examples:
Input : "9" Output : 3 Input : "24" Output : 4
Below programs illustrate the gmp_sqrtrem() function in PHP :
Program 1: Program to calculate the square root with remainder of a GMP number when numeric strings as GMP numbers are passed as arguments.
<?php // PHP program to calculate the square root // of a GMP number // passing numeric strings as GMP numbers $num = gmp_init("24"); // calculates the square root of a GMP number // with remainder list($squareRoot, $rem) = gmp_sqrtrem($num); echo $squareRoot." ".$rem; ?> |
Output:
4 8
Program 2: Program to calculate the square root with remainder of a GMP number when GMP numbers are passed as arguments.
<?php // PHP program to calculate the square root // of a GMP number // creating GMP numbers using gmp_init() $num = gmp_init(24, 10); // calculates the square root of a GMP number // with remainder list($squareRoot, $rem) = gmp_sqrtrem($num); echo $squareRoot." ".$rem; ?> |
Output:
4 8
Reference:
http://php.net/manual/en/function.gmp-sqrtrem.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | Ds\Map first() Function
- PHP | end() Function
- p5.js | hex() function
- D3.js | d3.rgb() Function
- PHP | pow( ) Function
- D3.js | d3.hcl() Function
- CSS | hsl() Function
- CSS | var() Function
- PHP | next() Function
- PHP | Ds\Set xor() Function
- p5.js | str() function
- PHP | dir() Function
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.



