public Method

Math.sqrt(a)

There's no documentation for this item.

Source Code

# File 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
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.