mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	* 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
This commit is contained in:
		
							parent
							
								
									9afe0278b3
								
							
						
					
					
						commit
						4f817e2a9d
					
				
					 6 changed files with 3123 additions and 95 deletions
				
			
		|  | @ -1,3 +1,9 @@ | |||
| Fri Oct 24 18:29:00 2008  Keiju Ishitsuka  <keiju@ruby-lang.org> | ||||
| 
 | ||||
| 	* lib/mathn.rb: moved into ext/mathn/rational/rational.c and | ||||
| 	  ext/mathn/complex/complex.c. | ||||
| 	* ext/mathn: new mathn ext-libralies. | ||||
| 
 | ||||
| Fri Oct 24 18:21:31 2008  Yukihiro Matsumoto  <matz@ruby-lang.org> | ||||
| 
 | ||||
| 	* test/ruby/test_array.rb (TestArray#test_join): should restore | ||||
|  |  | |||
							
								
								
									
										1511
									
								
								ext/mathn/complex/complex.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1511
									
								
								ext/mathn/complex/complex.c
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										5
									
								
								ext/mathn/complex/extconf.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								ext/mathn/complex/extconf.rb
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| require "mkmf" | ||||
| 
 | ||||
| $CPPFLAGS = "-DEXT_MATHN -DCANON -DCLCANON " | ||||
| 
 | ||||
| create_makefile "mathn/complex" | ||||
							
								
								
									
										5
									
								
								ext/mathn/rational/extconf.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								ext/mathn/rational/extconf.rb
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| require "mkmf" | ||||
| 
 | ||||
| $CPPFLAGS = "-DEXT_MATHN -DCANON -DCLCANON" | ||||
| 
 | ||||
| create_makefile "mathn/rational" | ||||
							
								
								
									
										1593
									
								
								ext/mathn/rational/rational.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										1593
									
								
								ext/mathn/rational/rational.c
									
										
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
							
								
								
									
										98
									
								
								lib/mathn.rb
									
										
									
									
									
								
							
							
						
						
									
										98
									
								
								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) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 keiju
						keiju