Project

General

Profile

Actions

Bug #175

closed

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

Added by NoKarma (Arthur Schreiber) over 13 years ago. Updated over 10 years ago.

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

Description

=begin
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
=end

Actions

Also available in: Atom PDF