Skip to content
Browse files

Fix Rational(0,1) with negative exponents

As a byproduct this fixes a Fixnum exponent spec.
  • Loading branch information...
1 parent 155900b commit ccfd06767f7609529628b95df0496f04ad3b1929 @jfirebaugh jfirebaugh committed Oct 22, 2011
Showing with 6 additions and 1 deletion.
  1. +6 −0 kernel/common/rational.rb
  2. +0 −1 spec/tags/19/ruby/core/fixnum/exponent_tags.txt
View
6 kernel/common/rational.rb
@@ -222,8 +222,14 @@ def divide (a)
#
def ** (other)
if other.kind_of?(Rational)
+ if self == 0 && other < 0 && other.denominator == 1
+ raise ZeroDivisionError, "divided by 0"
+ end
Float(self) ** other
elsif other.kind_of?(Integer)
+ if self == 0 && other < 0
+ raise ZeroDivisionError, "divided by 0"
+ end
if other > 0
num = @numerator ** other
den = @denominator ** other
View
1 spec/tags/19/ruby/core/fixnum/exponent_tags.txt
@@ -1,2 +1 @@
-fails:Fixnum#** raises a ZeroDivisionError for 0**-1
fails:Fixnum#** returns a complex number when negative and raised to a fractional power

0 comments on commit ccfd067

Please sign in to comment.
Something went wrong with that request. Please try again.