Use labs(rand()) instead of abs(rand()) in tommath

Originally by Christos Zoulas.
This commit is contained in:
Nicolas Williams
2017-01-31 11:39:55 -06:00
committed by Viktor Dukhovni
parent 369945f5bc
commit 352ff15477
5 changed files with 8 additions and 7 deletions

View File

@@ -83,7 +83,7 @@ int main(void)
// now test a random reduction
for (ix = 0; ix < 100; ix++) {
mp_rand(&c, 1 + labs(rand()) % (2*i));
mp_rand(&c, 1 + abs(rand()) % (2*i));
mp_copy(&c, &d);
mp_copy(&c, &e);
@@ -286,7 +286,7 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
if (!(++cnt & 127))
printf("%9d\r", cnt);
mp_rand(&a, labs(rand()) % 128 + 1);
mp_rand(&a, abs(rand()) % 128 + 1);
mp_div(&a, &d, &b, &e);
mp_div_3(&a, &c, &r2);
@@ -394,7 +394,7 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
for (;;) {
/* randomly clear and re-init one variable, this has the affect of triming the alloc space */
switch (labs(rand()) % 7) {
switch (abs(rand()) % 7) {
case 0:
mp_clear(&a);
mp_init(&a);

View File

@@ -163,7 +163,7 @@ mp_digit prime_digit(void)
int n;
mp_digit d;
n = labs(rand()) % n_prime;
n = abs(rand()) % n_prime;
fseek(primes, n * sizeof(mp_digit), SEEK_SET);
fread(&d, 1, sizeof(mp_digit), primes);
return d;

View File

@@ -281,7 +281,7 @@ int main(void)
printf("%s\n", buf);
} else if (n == 13) {
rand_num2(&a);
tmp = labs(rand()) & THE_MASK;
tmp = abs(rand()) & THE_MASK;
mp_add_d(&a, tmp, &b);
printf("add_d\n");
mp_to64(&a, buf);
@@ -290,7 +290,7 @@ int main(void)
printf("%s\n", buf);
} else if (n == 14) {
rand_num2(&a);
tmp = labs(rand()) & THE_MASK;
tmp = abs(rand()) & THE_MASK;
mp_sub_d(&a, tmp, &b);
printf("sub_d\n");
mp_to64(&a, buf);

View File

@@ -19,7 +19,7 @@
\def\gcd{{\rm gcd}}
\def\log{{\rm log}}
\def\ord{{\rm ord}}
\def\labs{{\mathit labs}}
\def\abs{{\mathit abs}}
\def\rep{{\mathit rep}}
\def\mod{{\mathit\ mod\ }}
\renewcommand{\pmod}[1]{\ ({\rm mod\ }{#1})}

View File

@@ -20,6 +20,7 @@
\def\log{{\rm log}}
\def\ord{{\rm ord}}
\def\labs{{\mathit labs}}
\def\abs{{\mathit abs}}
\def\rep{{\mathit rep}}
\def\mod{{\mathit\ mod\ }}
\renewcommand{\pmod}[1]{\ ({\rm mod\ }{#1})}