1 /* mpz_kronecker_ui -- mpz+ulong Kronecker/Jacobi symbol.
3 Copyright 1999-2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of either:
10 * the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 3 of the License, or (at your
12 option) any later version.
16 * the GNU General Public License as published by the Free Software
17 Foundation; either version 2 of the License, or (at your option) any
20 or both in parallel, as here.
22 The GNU MP Library is distributed in the hope that it will be useful, but
23 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
24 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
27 You should have received copies of the GNU General Public License and the
28 GNU Lesser General Public License along with the GNU MP Library. If not,
29 see https://www.gnu.org/licenses/. */
37 mpz_kronecker_ui (mpz_srcptr a
, unsigned long b
)
52 ALLOC(bz
) = numberof (blimbs
);
55 return mpz_kronecker (a
, bz
);
61 result_bit1
= JACOBI_ASGN_SU_BIT1 (a_size
, b
);
65 mp_limb_t a_low
= a_ptr
[0];
69 return JACOBI_LS0 (a_low
, a_size
); /* (a/0) */
72 return 0; /* (even/even)=0 */
74 /* (a/2)=(2/a) for a odd */
75 count_trailing_zeros (twos
, b
);
77 result_bit1
= (JACOBI_TWOS_U_BIT1 (twos
, a_low
)
78 ^ JACOBI_ASGN_SU_BIT1 (a_size
, b
));
82 return JACOBI_BIT1_TO_PN (result_bit1
); /* (a/1)=1 for any a */
86 /* (a/b) = (a mod b / b) */
87 JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1
, a_rem
, a_ptr
, a_size
, b
);
88 return mpn_jacobi_base (a_rem
, (mp_limb_t
) b
, result_bit1
);