1
--- ruby-1.8.5/bignum.c 7 Oct 2006 15:48:44 -0000 1.100.2.24
2
+++ ruby-1.8.5/bignum.c 30 Oct 2006 10:31:01 -0000 1.100.2.28
5
const char ruby_digitmap[] = "0123456789abcdefghijklmnopqrstuvwxyz";
8
+rb_big2str0(x, base, trim)
21
return rb_fix2str(x, base);
26
- j = j * 647L / 1024;
27
+ j = j * 53L / 84 + 1;
29
case 4: case 5: case 6: case 7:
34
case 10: case 11: case 12: case 13: case 14: case 15:
36
+ j = j * 28L / 93 + 1;
38
case 16: case 17: case 18: case 19: case 20: case 21:
39
case 22: case 23: case 24: case 25: case 26: case 27:
41
rb_raise(rb_eArgError, "illegal radix %d", base);
45
+ j++; /* space for sign */
48
#if SIZEOF_BDIGITS > 2
53
- ss = rb_str_new(0, j);
54
+ ss = rb_str_new(0, j+1);
57
s[0] = RBIGNUM(x)->sign ? '+' : '-';
59
+ while (i && j > 1) {
64
ds[k] = (BDIGIT)(num / hbase);
67
- if (ds[i-1] == 0) i--;
68
+ if (trim && ds[i-1] == 0) i--;
71
- c = (char)(num % base);
72
- s[--j] = ruby_digitmap[(int)c];
73
+ s[--j] = ruby_digitmap[num % base];
75
- if (i == 0 && num == 0) break;
76
+ if (!trim && j < 1) break;
77
+ if (trim && i == 0 && num == 0) break;
80
- while (s[j] == '0') j++;
81
- RSTRING(ss)->len -= RBIGNUM(x)->sign?j:j-1;
82
- memmove(RBIGNUM(x)->sign?s:s+1, s+j, RSTRING(ss)->len);
83
+ if (trim) {while (s[j] == '0') j++;}
84
+ i = RSTRING(ss)->len - j;
85
+ if (RBIGNUM(x)->sign) {
87
+ RSTRING(ss)->len = i-1;
90
+ memmove(s+1, s+j, i);
91
+ RSTRING(ss)->len = i;
93
s[RSTRING(ss)->len] = '\0';
99
+rb_big2str(VALUE x, int base)
101
+ return rb_big2str0(x, base, Qtrue);
106
* big.to_s(base=10) => string
107
--- ruby-1.8.5/intern.h 14 Sep 2006 07:25:54 -0000 1.139.2.20
108
+++ ruby-1.8.5/intern.h 30 Oct 2006 02:24:08 -0000 1.139.2.21
110
VALUE rb_cstr2inum _((const char*, int));
111
VALUE rb_str2inum _((VALUE, int));
112
VALUE rb_big2str _((VALUE, int));
113
+VALUE rb_big2str0 _((VALUE, int, int));
114
long rb_big2long _((VALUE));
115
#define rb_big2int(x) rb_big2long(x)
116
unsigned long rb_big2ulong _((VALUE));
117
--- ruby-1.8.5/sprintf.c 28 Jul 2006 16:27:42 -0000 1.34.2.19
118
+++ ruby-1.8.5/sprintf.c 30 Oct 2006 02:24:08 -0000 1.34.2.20
120
val = rb_big_clone(val);
123
- tmp1 = tmp = rb_big2str(val, base);
124
+ tmp1 = tmp = rb_big2str0(val, base, RBIGNUM(val)->sign);
125
s = RSTRING(tmp)->ptr;