Method: Math#sqrt

Defined in:
math.c

#sqrt(x) ⇒ Float (private)

Returns the non-negative square root of x.

Domain: [0, INFINITY)

Codomain:[0, INFINITY)

0.upto(10) {|x|
  p [x, Math.sqrt(x), Math.sqrt(x)**2]
}
#=> [0, 0.0, 0.0]
#   [1, 1.0, 1.0]
#   [2, 1.4142135623731, 2.0]
#   [3, 1.73205080756888, 3.0]
#   [4, 2.0, 4.0]
#   [5, 2.23606797749979, 5.0]
#   [6, 2.44948974278318, 6.0]
#   [7, 2.64575131106459, 7.0]
#   [8, 2.82842712474619, 8.0]
#   [9, 3.0, 9.0]
#   [10, 3.16227766016838, 10.0]

Returns:



591
592
593
594
595
596
597
598
599
600
601
# File 'math.c', line 591

static VALUE
math_sqrt(VALUE obj, VALUE x)
{
    double d;

    d = Get_Double(x);
    /* check for domain error */
    if (d < 0.0) domain_error("sqrt");
    if (d == 0.0) return DBL2NUM(0.0);
    return DBL2NUM(sqrt(d));
}