Skip to content

Commit 4034280

Browse files
committed
explicit operator precedence
1 parent 146becb commit 4034280

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

demo/test.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ static int64_t rand_int64(void)
4343

4444
static uint32_t uabs32(int32_t x)
4545
{
46-
return x > 0 ? (uint32_t)x : -(uint32_t)x;
46+
return (x > 0) ? (uint32_t)x : -(uint32_t)x;
4747
}
4848

4949
static uint64_t uabs64(int64_t x)
5050
{
51-
return x > 0 ? (uint64_t)x : -(uint64_t)x;
51+
return (x > 0) ? (uint64_t)x : -(uint64_t)x;
5252
}
5353

5454
/* This function prototype is needed
@@ -292,7 +292,7 @@ static int test_mp_rand(void)
292292
LBL_ERR:
293293
mp_rand_source(s_mp_rand_jenkins);
294294
mp_clear_multi(&a, &b, NULL);
295-
return e == MP_OKAY ? EXIT_SUCCESS : EXIT_FAILURE;
295+
return (e == MP_OKAY) ? EXIT_SUCCESS : EXIT_FAILURE;
296296
}
297297

298298
static int test_mp_kronecker(void)
@@ -1092,7 +1092,7 @@ static int test_mp_montgomery_reduce(void)
10921092

10931093
/* now test a random reduction */
10941094
for (ix = 0; ix < 100; ix++) {
1095-
DO(mp_rand(&c, 1 + abs(rand_int()) % (2*i)));
1095+
DO(mp_rand(&c, 1 + (abs(rand_int()) % (2*i))));
10961096
DO(mp_copy(&c, &d));
10971097
DO(mp_copy(&c, &e));
10981098

@@ -1223,7 +1223,7 @@ static int test_mp_reduce_2k(void)
12231223
printf(".");
12241224
fflush(stdout);
12251225
}
1226-
DO(mp_rand(&b, (cnt / MP_DIGIT_BIT + 1) * 2));
1226+
DO(mp_rand(&b, ((cnt / MP_DIGIT_BIT) + 1) * 2));
12271227
DO(mp_copy(&c, &b));
12281228
DO(mp_mod(&c, &a, &c));
12291229
DO(mp_reduce_2k(&b, &a, 2u));
@@ -1257,7 +1257,7 @@ static int test_mp_div_3(void)
12571257
printf("\r %9d", cnt);
12581258
fflush(stdout);
12591259
}
1260-
DO(mp_rand(&a, abs(rand_int()) % 128 + 1));
1260+
DO(mp_rand(&a, (abs(rand_int()) % 128) + 1));
12611261
DO(mp_div(&a, &d, &b, &e));
12621262
DO(mp_div_3(&a, &c, &r2));
12631263

@@ -1903,7 +1903,7 @@ static int test_s_mp_mul_karatsuba(void)
19031903
int size;
19041904

19051905
DOR(mp_init_multi(&a, &b, &c, &d, NULL));
1906-
for (size = MP_MUL_KARATSUBA_CUTOFF; size < MP_MUL_KARATSUBA_CUTOFF + 20; size++) {
1906+
for (size = MP_MUL_KARATSUBA_CUTOFF; size < (MP_MUL_KARATSUBA_CUTOFF + 20); size++) {
19071907
DO(mp_rand(&a, size));
19081908
DO(mp_rand(&b, size));
19091909
DO(s_mp_mul_karatsuba(&a, &b, &c));
@@ -1927,7 +1927,7 @@ static int test_s_mp_sqr_karatsuba(void)
19271927
int size;
19281928

19291929
DOR(mp_init_multi(&a, &b, &c, NULL));
1930-
for (size = MP_SQR_KARATSUBA_CUTOFF; size < MP_SQR_KARATSUBA_CUTOFF + 20; size++) {
1930+
for (size = MP_SQR_KARATSUBA_CUTOFF; size < (MP_SQR_KARATSUBA_CUTOFF + 20); size++) {
19311931
DO(mp_rand(&a, size));
19321932
DO(s_mp_sqr_karatsuba(&a, &b));
19331933
DO(s_mp_sqr(&a, &c));
@@ -1976,7 +1976,7 @@ static int test_s_mp_mul_toom(void)
19761976
}
19771977
#endif
19781978

1979-
for (size = MP_MUL_TOOM_CUTOFF; size < MP_MUL_TOOM_CUTOFF + 20; size++) {
1979+
for (size = MP_MUL_TOOM_CUTOFF; size < (MP_MUL_TOOM_CUTOFF + 20); size++) {
19801980
DO(mp_rand(&a, size));
19811981
DO(mp_rand(&b, size));
19821982
DO(s_mp_mul_toom(&a, &b, &c));
@@ -2000,7 +2000,7 @@ static int test_s_mp_sqr_toom(void)
20002000
int size;
20012001

20022002
DOR(mp_init_multi(&a, &b, &c, NULL));
2003-
for (size = MP_SQR_TOOM_CUTOFF; size < MP_SQR_TOOM_CUTOFF + 20; size++) {
2003+
for (size = MP_SQR_TOOM_CUTOFF; size < (MP_SQR_TOOM_CUTOFF + 20); size++) {
20042004
DO(mp_rand(&a, size));
20052005
DO(s_mp_sqr_toom(&a, &b));
20062006
DO(s_mp_sqr(&a, &c));
@@ -2075,7 +2075,7 @@ static int test_s_mp_div_recursive(void)
20752075

20762076
DOR(mp_init_multi(&a, &b, &c_q, &c_r, &d_q, &d_r, NULL));
20772077

2078-
for (size = MP_MUL_KARATSUBA_CUTOFF; size < 3 * MP_MUL_KARATSUBA_CUTOFF; size += 10) {
2078+
for (size = MP_MUL_KARATSUBA_CUTOFF; size < (3 * MP_MUL_KARATSUBA_CUTOFF); size += 10) {
20792079
printf("\rsizes = %d / %d", 10 * size, size);
20802080
/* Relation 10:1 */
20812081
DO(mp_rand(&a, 10 * size));
@@ -2289,7 +2289,7 @@ static int unit_tests(int argc, char **argv)
22892289
} test[] = {
22902290
#define T0(n) { #n, test_##n }
22912291
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
2292-
#define T2(n, o1, o2) { #n, MP_HAS(o1) && MP_HAS(o2) ? test_##n : NULL }
2292+
#define T2(n, o1, o2) { #n, (MP_HAS(o1) && MP_HAS(o2)) ? test_##n : NULL }
22932293
T0(feature_detection),
22942294
T0(trivial_stuff),
22952295
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
@@ -2351,7 +2351,7 @@ static int unit_tests(int argc, char **argv)
23512351
s_mp_rand_jenkins_init(t);
23522352
mp_rand_source(s_mp_rand_jenkins);
23532353

2354-
for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
2354+
for (i = 0; i < (sizeof(test) / sizeof(test[0])); ++i) {
23552355
if (argc > 1) {
23562356
for (j = 1; j < argc; ++j) {
23572357
if (strstr(test[i].name, argv[j]) != NULL) {

0 commit comments

Comments
 (0)