What is the gmp_rootrem() method in PHP?

Overview

The gmp_rootrem() function in PHP is used to find the nthn^{th} root of a given number.

Syntax

gmp_rootrem(GMP|int|string $num, int $nth): array

Parameters

  • num: This is a GMP object, integer, or a string whose nth root has to be calculated.
  • nth: This is the positive root.

Return value

This method returns an array of two elements:

  • The first element refers to the integer component of the nthn^{th} root.

  • The second element refers to the remainder of the nthn^{th} root.

Example

<?php
$nthroot1 = gmp_rootrem(64,2);
$nthroot2 = gmp_rootrem(64,5);
print_r("The square root of 64 is:\n\n");
print_r($nthroot1);
echo "-----------------------------------\n";
print_r("The fifth root of 64 is:\n\n");
print_r($nthroot2);
?>

Explanation

  • Line 2: We declare and initialize the variable $nthroot1 to store the result of the 2nd2^{nd} root (also known as the square root) of 64.

  • Line 3: We declare and initialize the variable $nthroot2 to store the result of the 5th5^{th} root of 64.

  • Line 6: We print the array stored in $nthroot1.

  • Line 9: We print the array stored in $nthroot2.

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved