diff --git a/ChangeLog b/ChangeLog index 5a614f467b..f33887c12e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Sep 24 10:06:19 2009 Marc-Andre Lafortune + + * 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 * eval.c (umethod_bind): Fix bug that disallowed methods from 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