diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-12-22 03:22:25 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-12-22 03:22:25 +0000 |
commit | 0e47c138c9bba4396fc7d956b05e5725000012f1 (patch) | |
tree | 54fac5b90c2ce6664e7017d954add4d06e388a09 /bignum.c | |
parent | 31c53aaa7dc3da8bc9ba6b3007c183dcbeeafe11 (diff) |
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -231,7 +231,9 @@ rb_cstr2inum(str, base) } } if (base == 8) { - while (str[0] == '0') str++; + while (*str == '0') str++; + if (!*str) return INT2FIX(0); + while (*str == '_') str++; len = 3*strlen(str)*sizeof(char); } else { /* base == 10, 2 or 16 */ @@ -249,6 +251,7 @@ rb_cstr2inum(str, base) if (len <= (sizeof(VALUE)*CHAR_BIT)) { unsigned long val = strtoul((char*)str, &end, base); + if (*end == '_') goto bigparse; if (badcheck) { if (end == str) goto bad; /* no number */ while (*end && ISSPACE(*end)) end++; @@ -271,7 +274,9 @@ rb_cstr2inum(str, base) return big; } } + bigparse: len = (len/BITSPERDIG)+1; + if (badcheck && *str == '_') goto bad; z = bignew(len, sign); zds = BDIGITS(z); @@ -290,6 +295,8 @@ rb_cstr2inum(str, base) case 'D': case 'E': case 'F': c = c - 'A' + 10; break; + case '_': + continue; default: if (badcheck) { if (ISSPACE(c)) { @@ -317,6 +324,7 @@ rb_cstr2inum(str, base) break; } } + if (badcheck && s+2 < str && str[-2] == '_') goto bad; return bignorm(z); } @@ -1252,7 +1260,7 @@ rb_big_lshift(x, y) } xds = BDIGITS(x); for (i=0; i<len; i++) { - num = num | *xds++<<s2; + num = num | (BDIGIT_DBL)*xds++<<s2; *zds++ = BIGLO(num); num = BIGDN(num); } |