diff options
author | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-22 12:40:45 +0000 |
---|---|---|
committer | ser <ser@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-22 12:40:45 +0000 |
commit | 8b53e39a2e6110cf13827c88673a3ef2667991cf (patch) | |
tree | eb1fa37c2a675b75c295285b5c313ba05801c2b8 /lib/mathn.rb | |
parent | f36a3f0ea57aa05a72cb58937c7a737455a98a38 (diff) | |
download | ruby-8b53e39a2e6110cf13827c88673a3ef2667991cf.tar.gz |
Second merge from trunk.rexml_adds_tests
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/rexml_adds_tests@19455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mathn.rb')
-rw-r--r-- | lib/mathn.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb index 2af2b83da3..e918608b0d 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -9,11 +9,15 @@ # # -require "complex.rb" -require "rational.rb" +require "cmath.rb" require "matrix.rb" require "prime.rb" +unless defined?(Math.exp!) + Object.instance_eval{remove_const :Math} + Math = CMath +end + class Fixnum remove_method :/ alias / quo @@ -33,7 +37,7 @@ class Rational if other.kind_of?(Rational) other2 = other if self < 0 - return Complex.__send__(:new!, self, 0) ** other + return Complex(self, 0.0) ** other elsif other == 0 return Rational(1,1) elsif self == 0 @@ -95,7 +99,7 @@ module Math remove_method(:sqrt) def sqrt(a) if a.kind_of?(Complex) - abs = sqrt(a.real*a.real + a.image*a.image) + abs = sqrt(a.real*a.real + a.imag*a.imag) # if not abs.kind_of?(Rational) # return a**Rational(1,2) # end @@ -104,7 +108,7 @@ module Math # if !(x.kind_of?(Rational) and y.kind_of?(Rational)) # return a**Rational(1,2) # end - if a.image >= 0 + if a.imag >= 0 Complex(x, y) else Complex(x, -y) |