summaryrefslogtreecommitdiff
path: root/lib/mathn.rb
diff options
context:
space:
mode:
authorkeiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-24 09:39:53 +0000
committerkeiju <keiju@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-24 09:39:53 +0000
commit4f817e2a9d8a365b403b1ce7a75c2053b0017ef1 (patch)
treed64c1a6b51ba73c5a7210379abae39bf0fa6969e /lib/mathn.rb
parent9afe0278b31be55ae59e9bb15c0c1fec08b1f328 (diff)
* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@19911 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/mathn.rb')
-rw-r--r--lib/mathn.rb98
1 files changed, 3 insertions, 95 deletions
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 992eae7098..48cb99f8c6 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)