public Method

Math.sqrt(z)

Redefined to handle a Complex argument.

Source Code

# File complex.rb, line 435
def sqrt(z)
  if Complex.generic?(z)
    if z >= 0
      sqrt!(z)
    else
      Complex(0,sqrt!(-z))
    end
  else
    if z.image < 0
      sqrt(z.conjugate).conjugate
    else
      r = z.abs
      x = z.real
      Complex( sqrt!((r+x)/2), sqrt!((r-x)/2) )
    end
  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.