ruby-changes:53518
From: shyouhei <ko1@a...>
Date: Thu, 15 Nov 2018 14:10:45 +0900 (JST)
Subject: [ruby-changes:53518] shyouhei:r65734 (trunk): bignum.c: ee should be signed
shyouhei 2018-11-15 14:10:40 +0900 (Thu, 15 Nov 2018) New Revision: 65734 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65734 Log: bignum.c: ee should be signed In C, signed + unsigned of the same size results in unsigned (cf: ISO/IEC 9899:1990 section 6.2.1.5). However `num` is signed here. Which means the addition must be done in signed. Modified files: trunk/bignum.c Index: bignum.c =================================================================== --- bignum.c (revision 65733) +++ bignum.c (revision 65734) @@ -1511,15 +1511,16 @@ bigdivrem_mulsub(BDIGIT *zds, size_t zn, https://github.com/ruby/ruby/blob/trunk/bignum.c#L1511 i = 0; do { - BDIGIT_DBL ee; + BDIGIT_DBL_SIGNED ee; t2 += (BDIGIT_DBL)yds[i] * x; ee = num - BIGLO(t2); - num = (BDIGIT_DBL)zds[i] + ee; + num = (BDIGIT_DBL_SIGNED)zds[i] + ee; if (ee) zds[i] = BIGLO(num); num = BIGDN(num); t2 = BIGDN(t2); } while (++i < yn); - num += zds[i] - t2; /* borrow from high digit; don't update */ + num -= (BDIGIT_DBL_SIGNED)t2; + num += (BDIGIT_DBL_SIGNED)zds[yn]; /* borrow from high digit; don't update */ return num; } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/