summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-04 10:41:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-04 10:41:45 +0000
commitb91d5b7958d752f3509ade4bfeaec4700e48c993 (patch)
treef63ef4d63ec3428713814ea7fbe7650d33ab2eb0 /bignum.c
parent4788522fa693cd21b43f6d2d020ae3b3cacfbce8 (diff)
bignum.c: explicit casts
* bignum.c (int_pow_tmp2): explicitly cast to get rid of implicit conversion. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61012 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/bignum.c b/bignum.c
index 4643973e91..a87429aac6 100644
--- a/bignum.c
+++ b/bignum.c
@@ -6994,38 +6994,36 @@ int_pow_tmp2(VALUE x, VALUE y, long mm, int nega_flg)
#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);