зеркало из https://github.com/github/ruby.git
* lib/mathn.rb (Rational::power2): removed incomplete method.
see [ruby-dev:35195]. [ruby-core:17293] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17545 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
3f1f29037d
Коммит
473acf0a31
|
@ -1,3 +1,8 @@
|
|||
Mon Jun 23 11:31:41 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* lib/mathn.rb (Rational::power2): removed incomplete method.
|
||||
see [ruby-dev:35195]. [ruby-core:17293]
|
||||
|
||||
Sun Jun 22 14:16:28 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/readline/extconf.rb (have_readline_func): readline on Mac OS X
|
||||
|
|
44
lib/mathn.rb
44
lib/mathn.rb
|
@ -183,50 +183,6 @@ class Rational
|
|||
x ** y
|
||||
end
|
||||
end
|
||||
|
||||
def power2(other)
|
||||
if other.kind_of?(Rational)
|
||||
if self < 0
|
||||
return Complex.__send__(:new!, self, 0) ** other
|
||||
elsif other == 0
|
||||
return Rational(1,1)
|
||||
elsif self == 0
|
||||
return Rational(0,1)
|
||||
elsif self == 1
|
||||
return Rational(1,1)
|
||||
end
|
||||
|
||||
dem = nil
|
||||
x = self.denominator.to_f.to_i
|
||||
neard = self.denominator.to_f ** (1.0/other.denominator.to_f)
|
||||
loop do
|
||||
if (neard**other.denominator == self.denominator)
|
||||
dem = neard
|
||||
break
|
||||
end
|
||||
end
|
||||
nearn = self.numerator.to_f ** (1.0/other.denominator.to_f)
|
||||
Rational(num,den)
|
||||
|
||||
elsif other.kind_of?(Integer)
|
||||
if other > 0
|
||||
num = numerator ** other
|
||||
den = denominator ** other
|
||||
elsif other < 0
|
||||
num = denominator ** -other
|
||||
den = numerator ** -other
|
||||
elsif other == 0
|
||||
num = 1
|
||||
den = 1
|
||||
end
|
||||
Rational(num, den)
|
||||
elsif other.kind_of?(Float)
|
||||
Float(self) ** other
|
||||
else
|
||||
x , y = other.coerce(self)
|
||||
x ** y
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Math
|
||||
|
|
Загрузка…
Ссылка в новой задаче