What is sqrt() in Perl?

The sqrt() function in Perl returns the square root of a non-negative number.

Figure 1 below shows the mathematical representation of the sqrt() function.

Figure 1: Mathematical representation of the sqrt() function

Syntax


sqrt(number)

Parameter

sqrt() requires a non-negative number as a parameter. If the number is negative, an Error will be thrown.

Return value

sqrt() returns the square root of the number sent as a parameter.

Code

The following example shows how to use sqrt() function in Perl.

print "sqrt(4): " .sqrt(4). "\n";
print "sqrt(0): " .sqrt(0). "\n";
print "sqrt(25): " .sqrt(25). "\n";
print "sqrt(4.5): " .sqrt(4.5). "\n";

Free Resources