public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Updated Complex library to latest version.
NoKarma (author)
Thu May 15 15:43:00 -0700 2008
commit  955443b06ade419a2c1fcdfc75f8eeb7df6f4f59
tree    26df63af3e3b9d28f133a1c0670ca32f6f2acaf1
parent  12dbed4a8ae18476587326447ba72873a34c1007
...
102
103
104
 
 
105
106
107
...
194
195
196
 
 
 
 
197
198
199
...
359
360
361
362
363
364
365
366
 
 
 
 
 
367
368
369
370
371
372
 
 
 
 
 
373
374
375
...
409
410
411
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
 
413
 
414
415
416
...
102
103
104
105
106
107
108
109
...
196
197
198
199
200
201
202
203
204
205
...
365
366
367
 
 
 
 
 
368
369
370
371
372
373
 
 
 
 
 
374
375
376
377
378
379
380
381
...
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
0
@@ -102,6 +102,8 @@ class Complex < Numeric
0
   @RCS_ID='-$Id: complex.rb,v 1.3 1998/07/08 10:05:28 keiju Exp keiju $-'
0
 
0
   undef step
0
+ undef div, divmod
0
+ undef floor, truncate, ceil, round
0
 
0
   def Complex.generic?(other) # :nodoc:
0
     other.kind_of?(Integer) or
0
@@ -194,6 +196,10 @@ class Complex < Numeric
0
     end
0
   end
0
   
0
+ def quo(other)
0
+ Complex(@real.quo(1), @image.quo(1)) / other
0
+ end
0
+
0
   #
0
   # Raise this complex number to the given (real or complex) power.
0
   #
0
@@ -359,17 +365,17 @@ class Complex < Numeric
0
   def to_s
0
     if @real != 0
0
       if defined?(Rational) and @image.kind_of?(Rational) and @image.denominator != 1
0
- if @image >= 0
0
- @real.to_s+"+("+@image.to_s+")i"
0
- else
0
- @real.to_s+"-("+(-@image).to_s+")i"
0
- end
0
+ if @image >= 0
0
+ @real.to_s+"+("+@image.to_s+")i"
0
+ else
0
+ @real.to_s+"-("+(-@image).to_s+")i"
0
+ end
0
       else
0
- if @image >= 0
0
- @real.to_s+"+"+@image.to_s+"i"
0
- else
0
- @real.to_s+"-"+(-@image).to_s+"i"
0
- end
0
+ if @image >= 0
0
+ @real.to_s+"+"+@image.to_s+"i"
0
+ else
0
+ @real.to_s+"-"+(-@image).to_s+"i"
0
+ end
0
       end
0
     else
0
       if defined?(Rational) and @image.kind_of?(Rational) and @image.denominator != 1
0
@@ -409,8 +415,34 @@ class Complex < Numeric
0
   
0
 end
0
 
0
+class Integer
0
+
0
+ unless defined?(1.numerator)
0
+ def numerator() self end
0
+ def denominator() 1 end
0
+
0
+ def gcd(other)
0
+ min = self.abs
0
+ max = other.abs
0
+ while min > 0
0
+ tmp = min
0
+ min = max % min
0
+ max = tmp
0
+ end
0
+ max
0
+ end
0
+
0
+ def lcm(other)
0
+ if self.zero? or other.zero?
0
+ 0
0
+ else
0
+ (self.div(self.gcd(other)) * other).abs
0
+ end
0
+ end
0
 
0
+ end
0
 
0
+end
0
 
0
 module Math
0
   alias sqrt! sqrt

Comments

    No one has commented yet.