ruby-changes:13305
From: marcandre <ko1@a...>
Date: Thu, 24 Sep 2009 10:07:32 +0900 (JST)
Subject: [ruby-changes:13305] Ruby:r25068 (ruby_1_8): * lib/mathn.rb (Fixnum#**, Float#**, Bignum#**): Allow fractional power for negative numbers when 'mathn' is required
marcandre 2009-09-24 10:07:21 +0900 (Thu, 24 Sep 2009) New Revision: 25068 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25068 Log: * lib/mathn.rb (Fixnum#**, Float#**, Bignum#**): Allow fractional power for negative numbers when 'mathn' is required [redmine:783] Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/lib/mathn.rb Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 25067) +++ ruby_1_8/ChangeLog (revision 25068) @@ -1,3 +1,8 @@ +Thu Sep 24 10:06:19 2009 Marc-Andre Lafortune <ruby-core@m...> + + * lib/mathn.rb (Fixnum#**, Float#**, Bignum#**): Allow fractional + power for negative numbers when 'mathn' is required [redmine:783] + Wed Sep 23 05:36:55 2009 Marc-Andre Lafortune <ruby-core@m...> * eval.c (umethod_bind): Fix bug that disallowed methods from Index: ruby_1_8/lib/mathn.rb =================================================================== --- ruby_1_8/lib/mathn.rb (revision 25067) +++ ruby_1_8/lib/mathn.rb (revision 25068) @@ -108,10 +108,30 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/