aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-12 14:13:46 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-12 14:13:46 +0000
commit6967900fd910a767bbe7804ec4f21b027cedd735 (patch)
tree30b7be7a49a2c78b48488a0ceb58fd1530000ce5 /lib
parenta395aca709c9a9ffa73b7f69071a540672005973 (diff)
downloadruby-6967900fd910a767bbe7804ec4f21b027cedd735.tar.gz
math.c: Complex sqrt
* math.c (rb_math_sqrt): [EXPERIMENTAL] move Complex sqrt support from mathn.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55646 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/mathn.rb9
1 files changed, 1 insertions, 8 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb
index d6f2da0210..9cb9401e37 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -103,14 +103,7 @@ module Math
def sqrt(a)
if a.kind_of?(Complex)
- abs = sqrt(a.real*a.real + a.imag*a.imag)
- x = sqrt((a.real + abs)/Rational(2))
- y = sqrt((-a.real + abs)/Rational(2))
- if a.imag >= 0
- Complex(x, y)
- else
- Complex(x, -y)
- end
+ sqrt!(a)
elsif a.respond_to?(:nan?) and a.nan?
a
elsif a >= 0