Project

General

Profile

Bug #141

Rational#power2 loops when the argument is 0

Added by krsh (Gianluigi Spagnuolo) about 12 years ago. Updated about 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
[ruby-core:17226]

Description

=begin
Rational#power2, when passed Rational, loop if the argument is 0.

For example:

Rational.new!(3, 4).power2(Rational.new!(0, 3))
=end

#1

Updated by shyouhei (Shyouhei Urabe) about 12 years ago

=begin
Gianluigi Spagnuolo wrote:

Rational#power2, when passed Rational, loop if the argument is 0.

For example:

Rational.new!(3, 4).power2(Rational.new!(0, 3))

That's because you're using unrecommended new! and undocumented power2,
both are not expected to be used.
Rational(3, 4) ** Rational(0, 3) should return immediately.

Index: lib/mathn.rb
===================================================================
--- lib/mathn.rb (revision 17088)
+++ lib/mathn.rb (working copy)
@@ -186,6 +186,7 @@

def power2(other)
  if other.kind_of?(Rational)
  • other = Rational.reduce(other.numerator, other.denominator) if self < 0 return Complex(self, 0) ** other elsif other == 0

=end

#2

Updated by matz (Yukihiro Matsumoto) about 12 years ago

  • Status changed from Open to Closed
  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Also available in: Atom PDF