Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php
squareroot
gmp
communitycreator

What is gmp_sqrt in PHP?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

gmp_sqrt() is a function in PHP that calculates the square root of a GMP number.

Syntax

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

Parameters

The function takes in one parameter, num.

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

Return value

The function returns the integer part of the square root. The value returned is a GMP type number.

Code

<?php
//numeric string as argument
$type1 = "9";
$squareRoot = gmp_sqrt($type1);
echo $squareRoot."\n";
//GMP number as argument
//gmp_init is used to create a GMP number
$type2 = gmp_init(7, 10);;
$squareRoot = gmp_sqrt($type2);
echo $squareRoot."\n";
?>

Expected output

3
2

RELATED TAGS

php
squareroot
gmp
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring