Flowdock
sqrt(a) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/mathn.rb, line 233
  def sqrt(a)
    if a.kind_of?(Complex)
      abs = sqrt(a.real*a.real + a.image*a.image)
#      if not abs.kind_of?(Rational)
#       return a**Rational(1,2)
#      end
      x = sqrt((a.real + abs)/Rational(2))
      y = sqrt((-a.real + abs)/Rational(2))
#      if !(x.kind_of?(Rational) and y.kind_of?(Rational))
#       return a**Rational(1,2)
#      end
      if a.image >= 0 
        Complex(x, y)
      else
        Complex(x, -y)
      end
    elsif a >= 0
      rsqrt(a)
    else
      Complex(0,rsqrt(-a))
    end
  end
Register or log in to add new notes.