The sqrt()
function in Ruby returns the square root of a non-negative number.
Figure 1 shows the mathematical representation of the sqrt()
function.
sqrt(number)
sqrt()
requires a non-negative number as a parameter. If the number is negative, a DomainError
will be thrown.
sqrt()
returns the square root of the number sent as a parameter.
print "sqrt(4):", Math.sqrt(4), "\n"print "sqrt(0):", Math.sqrt(0), "\n"print "sqrt(25):", Math.sqrt(25), "\n"print "sqrt(4.5):", Math.sqrt(4.5), "\n"