php8.5
Home/ Manual/ gmp / functions/ gmp_sqrt

gmp_sqrt

PHP function Edit on GitHub ✎

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

Calculate square root

Description

gmp_sqrt(GMP|int|string $num): GMP

Calculates square root of num.

Parameters

num

Parameter

Return Values

The integer portion of the square root, as a GMP number.

Examples

gmp_sqrt() example

php
<?php
$sqrt1 = gmp_sqrt("9");
$sqrt2 = gmp_sqrt("7");
$sqrt3 = gmp_sqrt("1524157875019052100");

echo gmp_strval($sqrt1) . "\n";
echo gmp_strval($sqrt2) . "\n";
echo gmp_strval($sqrt3) . "\n";
?>

The above example will output:

output
3
2
1234567890

Source: reference/gmp/functions/gmp-sqrt.xml · from the official PHP manual (php/doc-en)