demo: verify that negative number handling in mp_jacobi works
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
diff --git a/demo/demo.c b/demo/demo.c
index 66207d2..b46b7f8 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -145,7 +145,7 @@ int main(void)
unsigned long s, t;
unsigned long long q, r;
mp_digit mp;
- int i, n, err;
+ int i, n, err, should;
#endif
if (mp_init_multi(&a, &b, &c, &d, &e, &f, NULL)!= MP_OKAY)
@@ -206,8 +206,8 @@ int main(void)
mp_set_int(&a, 0);
mp_set_int(&b, 1);
- if ((ix = mp_jacobi(&a, &b, &i)) != MP_OKAY) {
- printf("Failed executing mp_jacobi(0 | 1) %s.\n", mp_error_to_string(ix));
+ if ((err = mp_jacobi(&a, &b, &i)) != MP_OKAY) {
+ printf("Failed executing mp_jacobi(0 | 1) %s.\n", mp_error_to_string(err));
return EXIT_FAILURE;
}
if (i != 1) {
@@ -217,15 +217,19 @@ int main(void)
for (cnt = 0; cnt < (int)(sizeof(jacobi)/sizeof(jacobi[0])); ++cnt) {
mp_set_int(&b, jacobi[cnt].n);
/* only test positive values of a */
-// for (n = -5; n <= 10; ++n) {
- for (n = 0; n <= 10; ++n) {
+ for (n = -5; n <= 10; ++n) {
mp_set_int(&a, abs(n));
- if (n < 0) mp_neg(&a, &a);
- if ((ix = mp_jacobi(&a, &b, &i)) != MP_OKAY) {
- printf("Failed executing mp_jacobi(%d | %lu) %s.\n", n, jacobi[cnt].n, mp_error_to_string(ix));
+ should = MP_OKAY;
+ if (n < 0) {
+ mp_neg(&a, &a);
+ /* Until #44 is fixed the negative a's must fail */
+ should = MP_VAL;
+ }
+ if ((err = mp_jacobi(&a, &b, &i)) != should) {
+ printf("Failed executing mp_jacobi(%d | %lu) %s.\n", n, jacobi[cnt].n, mp_error_to_string(err));
return EXIT_FAILURE;
}
- if (i != jacobi[cnt].c[n + 5]) {
+ if (err == MP_OKAY && i != jacobi[cnt].c[n + 5]) {
printf("Failed trivial mp_jacobi(%d | %lu) %d != %d\n", n, jacobi[cnt].n, i, jacobi[cnt].c[n + 5]);
return EXIT_FAILURE;
}