diff options
author | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-24 01:07:21 +0000 |
---|---|---|
committer | marcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-24 01:07:21 +0000 |
commit | 23c8ba8c465cc41bd3995c59dee2df098fd1d2cc (patch) | |
tree | f4d70659c7d7c843e923b24a4c921517dd95d028 /lib/mathn.rb | |
parent | d09ca418950a6d2b6508682fde1f46e39fc81413 (diff) |
* lib/mathn.rb (Fixnum#**, Float#**, Bignum#**): Allow fractional power for negative numbers when 'mathn' is required [redmine:783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mathn.rb')
-rw-r--r-- | lib/mathn.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb index 482a4f366a..7d16923670 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -108,10 +108,30 @@ end class Fixnum alias / quo + + alias power! ** unless method_defined? :power! + + def ** (other) + if self < 0 && other.round != other + Complex.new(self, 0.0) ** other + else + power!(other) + end + end end class Bignum alias / quo + + alias power! ** unless method_defined? :power! + + def ** (other) + if self < 0 && other.round != other + Complex.new(self, 0.0) ** other + else + power!(other) + end + end end class Rational @@ -306,3 +326,15 @@ class Complex Unify = true end +class Float + alias power! ** + + def ** (other) + if self < 0 && other.round != other + Complex.new(self, 0.0) ** other + else + power!(other) + end + end + +end |