summaryrefslogtreecommitdiffstats
path: root/libtommath/bn_mp_div_3.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-01 20:43:31 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2018-03-01 20:43:31 (GMT)
commit5753c7a42b638962406f9f7f822e48561e7a6253 (patch)
tree65742203dd83d002e9c923ddf96ddf45460e0d05 /libtommath/bn_mp_div_3.c
parent6881a1a27437cae50d56f12227e9cfe10c7a49f2 (diff)
downloadtcl-5753c7a42b638962406f9f7f822e48561e7a6253.zip
tcl-5753c7a42b638962406f9f7f822e48561e7a6253.tar.gz
tcl-5753c7a42b638962406f9f7f822e48561e7a6253.tar.bz2
Lots of code cleanup, mainly [https://github.com/libtom/libtommath/pull/102|Pull request #102]
Diffstat (limited to 'libtommath/bn_mp_div_3.c')
-rw-r--r--libtommath/bn_mp_div_3.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/libtommath/bn_mp_div_3.c b/libtommath/bn_mp_div_3.c
index 9cc8caa..9d41793 100644
--- a/libtommath/bn_mp_div_3.c
+++ b/libtommath/bn_mp_div_3.c
@@ -24,7 +24,7 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
int res, ix;
/* b = 2**DIGIT_BIT / 3 */
- b = (((mp_word)1) << ((mp_word)DIGIT_BIT)) / ((mp_word)3);
+ b = ((mp_word)1 << (mp_word)DIGIT_BIT) / (mp_word)3;
if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
return res;
@@ -34,11 +34,11 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
q.sign = a->sign;
w = 0;
for (ix = a->used - 1; ix >= 0; ix--) {
- w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]);
+ w = (w << (mp_word)DIGIT_BIT) | (mp_word)a->dp[ix];
- if (w >= 3) {
+ if (w >= 3u) {
/* multiply w by [1/3] */
- t = (w * ((mp_word)b)) >> ((mp_word)DIGIT_BIT);
+ t = (w * (mp_word)b) >> (mp_word)DIGIT_BIT;
/* now subtract 3 * [w/3] from w, to get the remainder */
w -= t+t+t;
@@ -46,9 +46,9 @@ int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d)
/* fixup the remainder as required since
* the optimization is not exact.
*/
- while (w >= 3) {
- t += 1;
- w -= 3;
+ while (w >= 3u) {
+ t += 1u;
+ w -= 3u;
}
} else {
t = 0;