Method: Math.sqrt
- Defined in:
- math.c
.sqrt(x) ⇒ Float
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]
622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'math.c', line 622
static VALUE
math_sqrt(VALUE obj, VALUE x)
{
double d0, d;
Need_Float(x);
d0 = RFLOAT_VALUE(x);
/* check for domain error */
if (d0 < 0.0) domain_error("sqrt");
if (d0 == 0.0) return DBL2NUM(0.0);
d = sqrt(d0);
return DBL2NUM(d);
}
|