lib/ruby/truffle/stdlib/cmath.rb
##
# Returns the non-negative square root of Complex.
#
#   CMath.sqrt(-1 + 0i) #=> 0.0+1.0i
Returns the non-negative square root of Complex.
Returns the non - negative square root of Complex .
def sqrt(z)
    begin
      if z.real?
        if z < 0
          Complex(0, sqrt!(-z))
        else
          sqrt!(z)
        end
      else
        if z.imag < 0 ||
            (z.imag == 0 && z.imag.to_s[0] == '-')
          sqrt(z.conjugate).conjugate
        else
          r = z.abs
          x = z.real
          Complex(sqrt!((r + x) / 2.0), sqrt!((r - x) / 2.0))
        end
      end
    rescue NoMethodError
      handle_no_method_error
    end
  end
def sqrt ( z ) begin if z . real? if z < 0 Complex ( 0 , sqrt! ( - z ) ) else sqrt! ( z ) end else if z . imag < 0 || ( z . imag == 0 && z . imag . to_s [ 0 ] == '-' ) sqrt ( z . conjugate ) . conjugate else r = z . abs x = z . real Complex ( sqrt! ( ( r + x ) / 2.0 ) , sqrt! ( ( r - x ) / 2.0 ) ) end end rescue NoMethodError handle_no_method_error end end
Returns the non-negative square root of Complex.
Returns the non - negative square root of Complex .
z
<not_specific>