Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Math.sqrt
Math.sqrt(x) → float
math.c
View on GitHub ↗
static VALUE
math_sqrt(VALUE unused_obj, VALUE x)
{
return rb_math_sqrt(x);
}
Returns the principal (non-negative) square root of x.
-
Domain:
[0, INFINITY]. -
Range:
[0, INFINITY].
Examples:
Example
sqrt(0.0) # => 0.0 sqrt(0.5) # => 0.7071067811865476 sqrt(1.0) # => 1.0 sqrt(2.0) # => 1.4142135623730951 sqrt(4.0) # => 2.0 sqrt(9.0) # => 3.0 sqrt(INFINITY) # => Infinity