ruby-changes:48894
From: nobu <ko1@a...>
Date: Mon, 4 Dec 2017 19:41:50 +0900 (JST)
Subject: [ruby-changes:48894] nobu:r61012 (trunk): bignum.c: explicit casts
nobu 2017-12-04 19:41:45 +0900 (Mon, 04 Dec 2017) New Revision: 61012 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61012 Log: bignum.c: explicit casts * bignum.c (int_pow_tmp2): explicitly cast to get rid of implicit conversion. Modified files: trunk/bignum.c Index: bignum.c =================================================================== --- bignum.c (revision 61011) +++ bignum.c (revision 61012) @@ -6994,38 +6994,36 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, https://github.com/ruby/ruby/blob/trunk/bignum.c#L6994 #ifdef DLONG DLONG const mmm = mm; long xx = FIX2LONG(x); +# define MUL_MODULO(a, b, c) (long)(((DLONG)(a) * (DLONG)(b)) % (c)) for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) { if (RTEST(rb_int_odd_p(y))) { - tmp = ((DLONG)tmp * (DLONG)xx) % mmm; + tmp = MUL_MODULO(tmp, xx, mmm); } - xx = ((DLONG)xx * (DLONG)xx) % mmm; + xx = MUL_MODULO(xx, xx, mmm); } for (yy = FIX2LONG(y); yy; yy >>= 1L) { if (yy & 1L) { - tmp = ((DLONG)tmp * (DLONG)xx) % mmm; + tmp = MUL_MODULO(tmp, xx, mmm); } - xx = ((DLONG)xx * (DLONG)xx) % mmm; + xx = MUL_MODULO(xx, xx, mmm); } #else VALUE const m = LONG2FIX(mm); VALUE tmp2 = LONG2FIX(tmp); +# define MUL_MODULO(a, b, c) rb_int_modulo(rb_fix_mul_fix((a), (b)), (c)) for (/*NOP*/; ! FIXNUM_P(y); y = rb_funcall(y, idGTGT, 1, LONG2FIX(1L))) { if (RTEST(rb_int_odd_p(y))) { - tmp2 = rb_fix_mul_fix(tmp2, x); - tmp2 = rb_int_modulo(tmp2, m); + tmp2 = MUL_MODULO(tmp2, x, m); } - x = rb_fix_mul_fix(x, x); - x = rb_int_modulo(x, m); + x = MUL_MODULO(x, x, m); } for (yy = FIX2LONG(y); yy; yy >>= 1L) { if (yy & 1L) { - tmp2 = rb_fix_mul_fix(tmp2, x); - tmp2 = rb_int_modulo(tmp2, m); + tmp2 = MUL_MODULO(tmp2, x, m); } - x = rb_fix_mul_fix(x, x); - x = rb_int_modulo(x, m); + x = MUL_MODULO(x, x, m); } tmp = FIX2LONG(tmp2); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/