diff options
author | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-28 00:41:42 +0000 |
---|---|---|
committer | tadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-28 00:41:42 +0000 |
commit | 0b99ce1fd6276b8a0dd900ac95ac39c625e5448e (patch) | |
tree | 975eebde6d0c4ffcd629ec443303ab117dd0d639 /lib/mathn.rb | |
parent | bde8a01d0a8750f9e0a7728ee9ae3a0fea3001ed (diff) |
* lib/mathn.rb ({Fixnum,Bignum,Float}#**): may produce complex
value.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mathn.rb')
-rw-r--r-- | lib/mathn.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb index 401b162b4c..486d487296 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -61,6 +61,16 @@ class Fixnum remove_method :/ alias / quo + alias power! ** + + def ** (other) + if self < 0 && other.round != other + Complex(self, 0.0) ** other + else + power!(other) + end + end + def_canon *(instance_methods - Object.methods - [:canon]) end @@ -69,6 +79,16 @@ class Bignum remove_method :/ alias / quo + alias power! ** + + def ** (other) + if self < 0 && other.round != other + Complex(self, 0.0) ** other + else + power!(other) + end + end + def_canon *(instance_methods - Object.methods - [:canon]) end @@ -261,4 +281,14 @@ class Float def_canon *(instance_methods - Object.methods - [:canon]) + alias power! ** + + def ** (other) + if self < 0 && other.round != other + Complex(self, 0.0) ** other + else + power!(other) + end + end + end |