* numeric.c (fix2str): improve r54092 like rb_int2big().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9749511dfe
commit
fcadcd3e68
@ -1,3 +1,7 @@
|
|||||||
|
Mon Mar 14 13:38:38 2016 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
|
* numeric.c (fix2str): improve r54092 like rb_int2big().
|
||||||
|
|
||||||
Mon Mar 14 10:02:23 2016 Eric Wong <e@80x24.org>
|
Mon Mar 14 10:02:23 2016 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
* ext/openssl/ossl_ssl.c (ossl_sslctx_setup): document as MT-unsafe
|
* ext/openssl/ossl_ssl.c (ossl_sslctx_setup): document as MT-unsafe
|
||||||
|
18
numeric.c
18
numeric.c
@ -2896,6 +2896,7 @@ rb_fix2str(VALUE x, int base)
|
|||||||
{
|
{
|
||||||
char buf[SIZEOF_VALUE*CHAR_BIT + 1], *const e = buf + sizeof buf, *b = e;
|
char buf[SIZEOF_VALUE*CHAR_BIT + 1], *const e = buf + sizeof buf, *b = e;
|
||||||
long val = FIX2LONG(x);
|
long val = FIX2LONG(x);
|
||||||
|
unsigned long u;
|
||||||
int neg = 0;
|
int neg = 0;
|
||||||
|
|
||||||
if (base < 2 || 36 < base) {
|
if (base < 2 || 36 < base) {
|
||||||
@ -2905,20 +2906,15 @@ rb_fix2str(VALUE x, int base)
|
|||||||
return rb_usascii_str_new2("0");
|
return rb_usascii_str_new2("0");
|
||||||
}
|
}
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
if (val == LONG_MIN) {
|
u = 1 + (unsigned long)(-(val + 1)); /* u = -val avoiding overflow */
|
||||||
int last = ((int)((val = LONG_MAX) % base) + 1);
|
|
||||||
*--b = ruby_digitmap[last % base];
|
|
||||||
val /= base;
|
|
||||||
val += last == base; /* carry */
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
val = -val;
|
|
||||||
}
|
|
||||||
neg = 1;
|
neg = 1;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
u = val;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
*--b = ruby_digitmap[(int)(val % base)];
|
*--b = ruby_digitmap[(int)(u % base)];
|
||||||
} while (val /= base);
|
} while (u /= base);
|
||||||
if (neg) {
|
if (neg) {
|
||||||
*--b = '-';
|
*--b = '-';
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user