ruby-changes:42024
From: naruse <ko1@a...>
Date: Mon, 14 Mar 2016 13:41:21 +0900 (JST)
Subject: [ruby-changes:42024] naruse:r54098 (trunk): * numeric.c (fix2str): improve r54092 like rb_int2big().
naruse 2016-03-14 13:41:16 +0900 (Mon, 14 Mar 2016) New Revision: 54098 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54098 Log: * numeric.c (fix2str): improve r54092 like rb_int2big(). Modified files: trunk/ChangeLog trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 54097) +++ numeric.c (revision 54098) @@ -2896,6 +2896,7 @@ rb_fix2str(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2896 { char buf[SIZEOF_VALUE*CHAR_BIT + 1], *const e = buf + sizeof buf, *b = e; long val = FIX2LONG(x); + unsigned long u; int neg = 0; if (base < 2 || 36 < base) { @@ -2905,20 +2906,15 @@ rb_fix2str(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/numeric.c#L2906 return rb_usascii_str_new2("0"); } if (val < 0) { - if (val == LONG_MIN) { - int last = ((int)((val = LONG_MAX) % base) + 1); - *--b = ruby_digitmap[last % base]; - val /= base; - val += last == base; /* carry */ - } - else { - val = -val; - } + u = 1 + (unsigned long)(-(val + 1)); /* u = -val avoiding overflow */ neg = 1; } + else { + u = val; + } do { - *--b = ruby_digitmap[(int)(val % base)]; - } while (val /= base); + *--b = ruby_digitmap[(int)(u % base)]; + } while (u /= base); if (neg) { *--b = '-'; } Index: ChangeLog =================================================================== --- ChangeLog (revision 54097) +++ ChangeLog (revision 54098) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Mon Mar 14 13:38:38 2016 NARUSE, Yui <naruse@r...> + + * numeric.c (fix2str): improve r54092 like rb_int2big(). + Mon Mar 14 10:02:23 2016 Eric Wong <e@8...> * ext/openssl/ossl_ssl.c (ossl_sslctx_setup): document as MT-unsafe -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/