What is gmp_root in PHP?

gmp_root is a function in PHP that returns the integer part of the nth root.

Syntax

gmp_root(GMP|int|string $num, int $Nth): GMP

Parameters

The function takes in two parameters: num and Nth.

  • num - can be a numeric string, GMPGNU Multiple Precision Arithmetic Library object, or of type int.

  • Nth - The positive root to take of num.

Return value

gmp_root returns the integer part of the Nth root. The value returned is type GMP number.

Code

<?php
// gmp_init is used to create a GMP number
$val1 = gmp_init("1001", 2);
$num = 3;
$val2 = gmp_root($val1, $num);
echo gmp_strval($val2, 2);
?>

Expected output

10

Free Resources