diff options
| author | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-24 09:39:53 +0000 |
|---|---|---|
| committer | keiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-10-24 09:39:53 +0000 |
| commit | ebc28c9647fe713126d4d54c5f6274c59380496d (patch) | |
| tree | d64c1a6b51ba73c5a7210379abae39bf0fa6969e /lib/mathn.rb | |
| parent | c55791d03ccb35432fa3e5d1901f615b08df26c4 (diff) | |
| download | ruby-ebc28c9647fe713126d4d54c5f6274c59380496d.tar.gz ruby-ebc28c9647fe713126d4d54c5f6274c59380496d.tar.xz ruby-ebc28c9647fe713126d4d54c5f6274c59380496d.zip | |
* lib/mathn.rb: moved into ext/mathn/rational/rational.c and
ext/mathn/complex/complex.c.
* ext/mathn: new mathn ext-libralies.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@19911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mathn.rb')
| -rw-r--r-- | lib/mathn.rb | 98 |
1 files changed, 3 insertions, 95 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb index 992eae709..48cb99f8c 100644 --- a/lib/mathn.rb +++ b/lib/mathn.rb @@ -13,54 +13,18 @@ require "cmath.rb" require "matrix.rb" require "prime.rb" +require "mathn/rational" +require "mathn/complex" + unless defined?(Math.exp!) Object.instance_eval{remove_const :Math} Math = CMath end -class Object - - def canon - if Rational === self - if denominator == 1 - return numerator - end - elsif Complex === self - if Integer === imag && imag == 0 - return real - end - end - self - end - - private :canon - - class << self - - def def_canon(*ids) - for id in ids - module_eval <<-"end;" - alias_method :__#{id.object_id}__, :#{id.to_s} - private :__#{id.object_id}__ - def #{id.to_s}(*args, &block) - __#{id.object_id}__(*args, &block).__send__(:canon) - end - end; - end - end - - private :def_canon - - end - -end - class Fixnum remove_method :/ alias / quo - def_canon(*(instance_methods - Object.methods - [:canon])) - alias power! ** unless defined?(0.power!) def ** (other) @@ -77,8 +41,6 @@ class Bignum remove_method :/ alias / quo - def_canon(*(instance_methods - Object.methods - [:canon])) - alias power! ** unless defined?(0.power!) def ** (other) @@ -91,23 +53,7 @@ class Bignum end -alias RationalOrig Rational -private :RationalOrig -def Rational(*args) RationalOrig(*args).__send__(:canon) end - class Rational - Unify = true - - class << self - alias convert_orig convert - private :convert_orig - def convert(*args) convert_orig(*args).__send__(:canon) end - end - - def_canon(*(instance_methods - Object.methods - [:canon])) - - alias power! ** - def ** (other) if other.kind_of?(Rational) other2 = other @@ -244,45 +190,7 @@ module Math module_function :rsqrt end -alias ComplexOrig Complex -private :ComplexOrig -def Complex(*args) ComplexOrig(*args).__send__(:canon) end - -class Complex - Unify = true - - class << self - alias convert_orig convert - private :convert_orig - def convert(*args) convert_orig(*args).__send__(:canon) end - end - - def_canon(*(instance_methods - Object.methods - [:canon])) - -end - -class NilClass - - def_canon :to_r, :to_c - -end - -class Integer - - def_canon :to_r, :to_c - -end - -class String - - def_canon :to_r, :to_c - -end - class Float - - def_canon(*(instance_methods - Object.methods - [:canon])) - alias power! ** def ** (other) |
