public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
added Fixnum multiply,divide, and modulo
dgtized (author)
Tue Apr 22 10:17:41 -0700 2008
commit  a58dfb869990f9999b5488ff186ccd367f896aae
tree    298a8edd33d7cacafe68271513e8b7a1b451726e
parent  21d99b3411295f2887f84bca52549f40273baa14
...
540
541
542
 
 
 
 
 
 
 
 
 
 
 
 
543
544
545
...
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
0
@@ -540,6 +540,18 @@
0
     OBJECT sub(STATE, FIXNUM other) {
0
       return Object::i2n(state, n2i() - other->n2i());
0
     }
0
+
0
+ OBJECT multiply(STATE, FIXNUM other) {
0
+ return Object::i2n(state, n2i() * other->n2i());
0
+ }
0
+
0
+ OBJECT divide(STATE, FIXNUM other) {
0
+ return Object::i2n(state, n2i() / other->n2i());
0
+ }
0
+
0
+ OBJECT modulo(STATE, FIXNUM other) {
0
+ return Object::i2n(state, n2i() % other->n2i());
0
+ }
0
   };
0
 
0
   typedef Fixnum* FIXNUM;
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
...
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -34,5 +34,26 @@
0
     FIXNUM zero = as<Fixnum>(one->sub(state, one));
0
     TS_ASSERT_EQUALS(zero->n2i(), 0);
0
   }
0
+
0
+ void test_multiply() {
0
+ FIXNUM one = as<Fixnum>(Object::i2n(4));
0
+
0
+ FIXNUM two = as<Fixnum>(one->multiply(state, one));
0
+ TS_ASSERT_EQUALS(two->n2i(), 16);
0
+ }
0
+
0
+ void test_divide() {
0
+ FIXNUM one = as<Fixnum>(Object::i2n(4));
0
+
0
+ FIXNUM two = as<Fixnum>(one->divide(state, one));
0
+ TS_ASSERT_EQUALS(two->n2i(), 1);
0
+ }
0
+
0
+ void test_modulo() {
0
+ FIXNUM one = as<Fixnum>(Object::i2n(4));
0
+
0
+ FIXNUM two = as<Fixnum>(one->modulo(state, one));
0
+ TS_ASSERT_EQUALS(two->n2i(), 0);
0
+ }
0
 };

Comments

    No one has commented yet.