diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-23 06:22:50 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-01-23 06:22:50 +0000 |
| commit | 308a4b0e83a1482263efc928576008c7b4bf3e8f (patch) | |
| tree | fa8ac7f3dd7ae1d12349e43bc3f4c47510fc907a /lib | |
| parent | 7428771746bf84112a7a3722cb45fe8ea528c401 (diff) | |
| download | ruby-308a4b0e83a1482263efc928576008c7b4bf3e8f.tar.gz ruby-308a4b0e83a1482263efc928576008c7b4bf3e8f.tar.xz ruby-308a4b0e83a1482263efc928576008c7b4bf3e8f.zip | |
* lib/rational.rb: modified to support "quo".
* numeric.c (num_quo): should return most exact quotient value,
i.e. float by default, rational if available.
* numeric.c (num_div): "div" should return x.divmod(x)[0].
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3399 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/mathn.rb | 11 | ||||
| -rw-r--r-- | lib/rational.rb | 43 |
2 files changed, 8 insertions, 46 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb index f3f7a95a4..cd4c6ef9e 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -106,18 +106,11 @@ class Prime end class Fixnum - alias divmod! divmod - alias / rdiv - def divmod(other) - a = self.div(other) - b = self % other - return a,b - end + alias / quo end class Bignum - alias divmod! divmod - alias / rdiv + alias / quo end class Rational diff --git a/lib/rational.rb b/lib/rational.rb index 16ee00890..af4eada07 100644 --- a/lib/rational.rb +++ b/lib/rational.rb @@ -31,8 +31,9 @@ # Integer::to_r # # Fixnum::** +# Fixnum::quo # Bignum::** -# +# Bignum::quo # def Rational(a, b = 1) @@ -312,41 +313,14 @@ class Integer end class Fixnum - alias div! /; - def div(other) - if other.kind_of?(Fixnum) - self.div!(other) - elsif other.kind_of?(Bignum) - x, y = other.coerce(self) - x.div!(y) - else - x, y = other.coerce(self) - x / y - end - end - -# alias divmod! divmod - if not defined? Complex alias power! **; end -# def rdiv(other) -# if other.kind_of?(Fixnum) -# Rational(self, other) -# elsif -# x, y = other.coerce(self) -# if defined?(x.div()) -# x.div(y) -# else -# x / y -# end -# end - # end - - def rdiv(other) + def quo(other) Rational.new!(self,1) / other end + alias rdiv quo def rpower (other) if other >= 0 @@ -362,17 +336,14 @@ class Fixnum end class Bignum - alias div! /; - alias div /; - alias divmod! divmod - if not defined? power! alias power! ** end - def rdiv(other) + def quo(other) Rational.new!(self,1) / other end + alias rdiv quo def rpower (other) if other >= 0 @@ -385,6 +356,4 @@ class Bignum if not defined? Complex alias ** rpower end - end - |
