public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Implement Bignum::to_f
dbussink (author)
Sat May 31 20:56:14 -0700 2008
commit  04d35d89b2188cda6ca8730eaa131415f9801c46
tree    80d0ac102cab762d4836e67be9facb66d4c23494
parent  ee56a2ca9427d2cd5af5e2af8626e88fb9a90ea7
...
664
665
666
 
 
 
 
667
668
669
...
664
665
666
667
668
669
670
671
672
673
0
@@ -664,6 +664,10 @@ namespace rubinius {
0
     return Float::coerce(state, this)->le(state, b);
0
   }
0
 
0
+ Float* Bignum::to_f(STATE) {
0
+ return Float::coerce(state, this);
0
+ }
0
+
0
   int Bignum::to_int(STATE) {
0
     if(MP(this)->sign == MP_NEG) {
0
       return -mp_get_int(MP(this));
...
136
137
138
 
 
 
139
140
141
...
136
137
138
139
140
141
142
143
144
0
@@ -136,6 +136,9 @@ namespace rubinius {
0
     // Ruby.primitive! :bignum_le
0
     OBJECT le(STATE, Float* b);
0
 
0
+ // Ruby.primitive :bignum_to_f
0
+ Float* to_f(STATE);
0
+
0
     int to_int(STATE);
0
     int to_i(STATE);
0
     native_int to_nint();
...
24
25
26
27
28
29
30
...
24
25
26
 
27
28
29
0
@@ -24,7 +24,6 @@ namespace rubinius {
0
     static Float* create(STATE, double val);
0
     static Float* coerce(STATE, OBJECT value);
0
     double to_double(STATE) { return val; }
0
- double to_double() { return val; }
0
     void into_string(STATE, char* buf, size_t sz);
0
 
0
     // Ruby.primitive! :float_add
...
420
421
422
 
 
 
 
423
424
425
...
420
421
422
423
424
425
426
427
428
429
0
@@ -420,6 +420,10 @@ class TestBignum : public CxxTest::TestSuite {
0
     TS_ASSERT_EQUALS(Bignum::create(state, -3)->le(state, Float::create(state, -3.1)), Qfalse);
0
   }
0
 
0
+ void test_to_f() {
0
+ check_float(b1->to_f(state), Float::create(state, 2147483647.0));
0
+ }
0
+
0
   void test_from_double() {
0
     OBJECT s = Bignum::from_double(state, 1.0);
0
     TS_ASSERT(s->fixnum_p());

Comments

    No one has commented yet.