The gmp_rootrem() is a built-in function in PHP which is used to calculate the nth root of a GMP number (GNU Multiple Precision : For large numbers) and returns the integer component of the nth root and its remainder .
Syntax :
gmp_rootrem($num,$n)
Parameters : This function accepts two mandatory parameters as shown in the above syntax. They are specified below :
- $num : The parameter can be a GMP object in PHP version 5.6 and later, or we can also pass a numeric string provided that it is possible to convert that string to a number.
- $n : The positive root to be calculated of $num.
Examples :
Input : $num = "8" $n = 2
Output : Array (
[0] => GMP Object ( [num] => 2 )
[1] => GMP Object ( [num] => 4 )
)
Input : $num = "9" $n = 2
Output : Array (
[0] => GMP Object ( [num] => 3 )
[1] => GMP Object ( [num] => 0 )
)
Return Value : This function returns a two element array , both the elements being GMP numbers.
- The first element of the array is the integer component of the nth root of $num.
- The second element is the remainder.
Below programs will illustrate the use of gmp_rootrem() function in PHP :
Program 1 : The below program illustrates the use of the function with GMP number passed as argument.
<?php // PHP program to calculate the // integer part and remainder // of nth root of a gmp number // GMP number as arguments $num = gmp_init(8); $n = 3; $rootrem = gmp_rootrem($num, $n); //Display the array elements echo print_r($rootrem); ?> |
Output
Array
(
[0] => GMP Object ( [num] => 2 )
[1] => GMP Object ( [num] => 0 )
)
Program 2 : The below program illustrates the use of the function with numeric string passed as argument.
<?php // PHP program to calculate the // integer part and remainder // of nth root of a gmp number // Numeric string as argument $num = "178924890"; $n = 3; $rootrem = gmp_rootrem($num, $n); //Display the array elements echo print_r($rootrem); ?> |
Output
Array ( [0] => GMP Object ( [num] => 563 ) [1] => GMP Object ( [num] => 471343 ) )
Reference : http://php.net/manual/en/function.gmp-rootrem.php
Recommended Posts:
- How to Check a Function is a Generator Function or not using JavaScript ?
- 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 last() Function
- p5.js | int() function
- PHP | Ds\Map map() Function
- CSS min() Function
- D3.js zip() Function
- PHP | Ds\Set last() Function
- p5.js | mag() Function
- PHP | Ds\Set first() Function
- D3.js | d3.map.set() Function
- p5.js | hex() function
- PHP | Ds\Map get() Function
- PHP Ds\Map sum() Function
- p5.js | str() function
- PHP | Ds\Map first() Function
- D3.js | d3.hsl() Function
- PHP | pi( ) 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.

