Project

General

Profile

Actions

Bug #141

closed

Rational#power2 loops when the argument is 0

Added by krsh (Gianluigi Spagnuolo) over 14 years ago. Updated over 11 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

Actions #1

Updated by shyouhei (Shyouhei Urabe) over 14 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

Actions #2

Updated by matz (Yukihiro Matsumoto) about 14 years ago

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

=begin

=end

Actions

Also available in: Atom PDF