mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/mathn.rb (Fixnum#**, Float#**, Bignum#**): Allow fractional power for negative numbers when 'mathn' is required [redmine:783]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@25068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d09ca41895
commit
23c8ba8c46
2 changed files with 37 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Sep 24 10:06:19 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* lib/mathn.rb (Fixnum#**, Float#**, Bignum#**): Allow fractional
|
||||
power for negative numbers when 'mathn' is required [redmine:783]
|
||||
|
||||
Wed Sep 23 05:36:55 2009 Marc-Andre Lafortune <ruby-core@marc-andre.ca>
|
||||
|
||||
* eval.c (umethod_bind): Fix bug that disallowed methods from
|
||||
|
|
32
lib/mathn.rb
32
lib/mathn.rb
|
@ -108,10 +108,30 @@ end
|
|||
|
||||
class Fixnum
|
||||
alias / quo
|
||||
|
||||
alias power! ** unless method_defined? :power!
|
||||
|
||||
def ** (other)
|
||||
if self < 0 && other.round != other
|
||||
Complex.new(self, 0.0) ** other
|
||||
else
|
||||
power!(other)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Bignum
|
||||
alias / quo
|
||||
|
||||
alias power! ** unless method_defined? :power!
|
||||
|
||||
def ** (other)
|
||||
if self < 0 && other.round != other
|
||||
Complex.new(self, 0.0) ** other
|
||||
else
|
||||
power!(other)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Rational
|
||||
|
@ -306,3 +326,15 @@ class Complex
|
|||
Unify = true
|
||||
end
|
||||
|
||||
class Float
|
||||
alias power! **
|
||||
|
||||
def ** (other)
|
||||
if self < 0 && other.round != other
|
||||
Complex.new(self, 0.0) ** other
|
||||
else
|
||||
power!(other)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue