Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

Math.sqrt

Math.sqrt(x) → float

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
See also .sinh .tan .sin .tanh also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0