From 7f7cb6f00b12bd8ec660e576e3d34aa609062897 Mon Sep 17 00:00:00 2001 From: tadf Date: Sun, 28 Sep 2008 00:41:42 +0000 Subject: * lib/mathn.rb ({Fixnum,Bignum,Float}#**): may produce complex value. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/mathn.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'lib') diff --git a/lib/mathn.rb b/lib/mathn.rb index 401b162b4..486d48729 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 -- cgit