Bug #175 [ruby-core:17293]

Rational#power2 raises a NameError or causes infinite loops when passed a Rational

Added by Arthur Schreiber 772 days ago. Updated 755 days ago.

Status :Closed Start :06/17/2008
Priority :Normal Due date :
Assigned to :Yukihiro Matsumoto % Done :

0%

Category :-
Target version :-
ruby -v :


Description

There is propably a typo in the Rational#power2 method, as there is no variable
called "neaed", but there is one called "neard".

Desktop:~ arthur$ irb
irb(main):001:0> require "mathn"
=> true
irb(main):002:0> Rational(1, 4).power2(Rational(1, 2))
NameError: undefined local variable or method `neaed' for 1/4:Rational
	from /usr/local/lib/ruby/1.8/mathn.rb:204:in `power2'
	from /usr/local/lib/ruby/1.8/mathn.rb:202:in `loop'
	from /usr/local/lib/ruby/1.8/mathn.rb:202:in `power2'
	from (irb):2

If you pass a value that is equal to self, it will cause an infinite loop:

Rational(1, 2).power2(Rational(1, 2)) # => Infinite Loop
Rational(1, 4).power2(Rational(1, 4)) # => Infinite Loop

Associated revisions

Revision 17449
Added by matz 770 days ago

History

06/18/2008 01:51 AM - Anonymous

Why is ruby 1.8.7 not using version 1.5.8 from 
http://dev.ctor.org/soap4r? What is the process for including soap4r 
changes? Is it tied to nahi?

Just curious ;-)

eTM

06/20/2008 02:27 AM - Yukihiro Matsumoto

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
Applied in changeset r17449.

06/21/2008 12:55 AM - Arthur Schreiber

Rational#power2 is still not working correctly:

Rational(1, 4).power2(Rational(1, 2)) # => NameError: undefined local variable or method `num' for 1/4:Rational

Rational(1, 4).power2(Rational(1, 4)) # => Infinite Loop
Rational(1, 2).power2(Rational(1, 2)) # => Infinite Loop

06/21/2008 05:04 AM - Yukihiro Matsumoto

  • Status changed from Closed to Assigned
  • Assigned to set to Yukihiro Matsumoto
  • % Done changed from 100 to 0

06/21/2008 05:05 AM - Yukihiro Matsumoto

Hi,

In message "Re: [ruby-core:17354] [Ruby 1.8 - Bug #175] Rational#power2 raises a NameError or causes infinite loops when passed a Rational"
    on Sat, 21 Jun 2008 00:54:00 +0900, Arthur Schreiber <redmine@ruby-lang.org> writes:

|Rational#power2 is still not working correctly:

I'll see.  But note that power2 is not a part of public API of
Rational. 

							matz.

07/04/2008 07:43 PM - Yukihiro Matsumoto

  • Status changed from Assigned to Closed

Also available in: Atom PDF