Use labs(rand()) instead of abs(rand()) in tommath
Originally by Christos Zoulas.
This commit is contained in:

committed by
Viktor Dukhovni

parent
369945f5bc
commit
352ff15477
@@ -83,7 +83,7 @@ int main(void)
|
|||||||
|
|
||||||
// now test a random reduction
|
// now test a random reduction
|
||||||
for (ix = 0; ix < 100; ix++) {
|
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, &d);
|
||||||
mp_copy(&c, &e);
|
mp_copy(&c, &e);
|
||||||
|
|
||||||
@@ -286,7 +286,7 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
|
|||||||
|
|
||||||
if (!(++cnt & 127))
|
if (!(++cnt & 127))
|
||||||
printf("%9d\r", cnt);
|
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(&a, &d, &b, &e);
|
||||||
mp_div_3(&a, &c, &r2);
|
mp_div_3(&a, &c, &r2);
|
||||||
|
|
||||||
@@ -394,7 +394,7 @@ printf("compare no compare!\n"); exit(EXIT_FAILURE); }
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* randomly clear and re-init one variable, this has the affect of triming the alloc space */
|
/* 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:
|
case 0:
|
||||||
mp_clear(&a);
|
mp_clear(&a);
|
||||||
mp_init(&a);
|
mp_init(&a);
|
||||||
|
@@ -163,7 +163,7 @@ mp_digit prime_digit(void)
|
|||||||
int n;
|
int n;
|
||||||
mp_digit d;
|
mp_digit d;
|
||||||
|
|
||||||
n = labs(rand()) % n_prime;
|
n = abs(rand()) % n_prime;
|
||||||
fseek(primes, n * sizeof(mp_digit), SEEK_SET);
|
fseek(primes, n * sizeof(mp_digit), SEEK_SET);
|
||||||
fread(&d, 1, sizeof(mp_digit), primes);
|
fread(&d, 1, sizeof(mp_digit), primes);
|
||||||
return d;
|
return d;
|
||||||
|
@@ -281,7 +281,7 @@ int main(void)
|
|||||||
printf("%s\n", buf);
|
printf("%s\n", buf);
|
||||||
} else if (n == 13) {
|
} else if (n == 13) {
|
||||||
rand_num2(&a);
|
rand_num2(&a);
|
||||||
tmp = labs(rand()) & THE_MASK;
|
tmp = abs(rand()) & THE_MASK;
|
||||||
mp_add_d(&a, tmp, &b);
|
mp_add_d(&a, tmp, &b);
|
||||||
printf("add_d\n");
|
printf("add_d\n");
|
||||||
mp_to64(&a, buf);
|
mp_to64(&a, buf);
|
||||||
@@ -290,7 +290,7 @@ int main(void)
|
|||||||
printf("%s\n", buf);
|
printf("%s\n", buf);
|
||||||
} else if (n == 14) {
|
} else if (n == 14) {
|
||||||
rand_num2(&a);
|
rand_num2(&a);
|
||||||
tmp = labs(rand()) & THE_MASK;
|
tmp = abs(rand()) & THE_MASK;
|
||||||
mp_sub_d(&a, tmp, &b);
|
mp_sub_d(&a, tmp, &b);
|
||||||
printf("sub_d\n");
|
printf("sub_d\n");
|
||||||
mp_to64(&a, buf);
|
mp_to64(&a, buf);
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
\def\gcd{{\rm gcd}}
|
\def\gcd{{\rm gcd}}
|
||||||
\def\log{{\rm log}}
|
\def\log{{\rm log}}
|
||||||
\def\ord{{\rm ord}}
|
\def\ord{{\rm ord}}
|
||||||
\def\labs{{\mathit labs}}
|
\def\abs{{\mathit abs}}
|
||||||
\def\rep{{\mathit rep}}
|
\def\rep{{\mathit rep}}
|
||||||
\def\mod{{\mathit\ mod\ }}
|
\def\mod{{\mathit\ mod\ }}
|
||||||
\renewcommand{\pmod}[1]{\ ({\rm mod\ }{#1})}
|
\renewcommand{\pmod}[1]{\ ({\rm mod\ }{#1})}
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
\def\log{{\rm log}}
|
\def\log{{\rm log}}
|
||||||
\def\ord{{\rm ord}}
|
\def\ord{{\rm ord}}
|
||||||
\def\labs{{\mathit labs}}
|
\def\labs{{\mathit labs}}
|
||||||
|
\def\abs{{\mathit abs}}
|
||||||
\def\rep{{\mathit rep}}
|
\def\rep{{\mathit rep}}
|
||||||
\def\mod{{\mathit\ mod\ }}
|
\def\mod{{\mathit\ mod\ }}
|
||||||
\renewcommand{\pmod}[1]{\ ({\rm mod\ }{#1})}
|
\renewcommand{\pmod}[1]{\ ({\rm mod\ }{#1})}
|
||||||
|
Reference in New Issue
Block a user