X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/0f00dc4c8eb47e67bc0f148c2dd109f73a451e0a..51f5bbe0bfe8a344c3cc1f5a9fddf885fa75d057:/math/mp-jacobi.c diff --git a/math/mp-jacobi.c b/math/mp-jacobi.c index 1a2835b..e318ce3 100644 --- a/math/mp-jacobi.c +++ b/math/mp-jacobi.c @@ -55,7 +55,7 @@ * * %$\jacobi{a}{-1} = 1$% if @a@ is negative, or 1 if * positive; * * %$\jacobi{a}{0} = 0$%; - * * %$\jacobi{a}{2}$ is 0 if @a@ is even, 1 if @a@ is + * * %$\jacobi{a}{2}$ is 0 if @a@ is even, 1 if @a@ is * congruent to 1 or 7 (mod 8), or %$-1$% otherwise. * * If %$n$% is positive and odd, then this is the Jacobi @@ -130,7 +130,7 @@ int mp_jacobi(mp *a, mp *n) goto done; } - /* --- Main case with powers of two --- */ + /* --- Strip out powers of two from %$a$% --- */ a = mp_odd(a, a, &e); nn = n->v[0] & 7; @@ -138,11 +138,11 @@ int mp_jacobi(mp *a, mp *n) s = -s; if (MP_LEN(a) == 1 && a->v[0] == 1) goto done; - if ((nn & 3) == 3 && (a->v[0] & 3) == 3) - s = -s; - /* --- Reduce and swap --- */ + /* --- Reduce and swap, applying quadratic residuosity --- */ + if ((nn & 3) == 3 && (a->v[0] & 3) == 3) + s = -s; mp_div(0, &n, n, a); { mp *t = n; n = a; a = t; } }