Annotation of OpenXM_contrib/gmp/mpz/kronzu.c, Revision 1.1.1.1
1.1 maekawa 1: /* mpz_kronecker_ui -- Kronecker/Jacobi symbol. */
2:
3: /*
4: Copyright (C) 1999, 2000 Free Software Foundation, Inc.
5:
6: This file is part of the GNU MP Library.
7:
8: The GNU MP Library is free software; you can redistribute it and/or modify
9: it under the terms of the GNU Lesser General Public License as published by
10: the Free Software Foundation; either version 2.1 of the License, or (at your
11: option) any later version.
12:
13: The GNU MP Library is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16: License for more details.
17:
18: You should have received a copy of the GNU Lesser General Public License
19: along with the GNU MP Library; see the file COPYING.LIB. If not, write to
20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21: MA 02111-1307, USA.
22: */
23:
24: #include "gmp.h"
25: #include "gmp-impl.h"
26: #include "longlong.h"
27:
28:
29: /* This function is expected to be often used with b an odd prime, so the
30: code for odd b is nice and short. */
31:
32: int
33: #if __STDC__
34: mpz_kronecker_ui (mpz_srcptr a, unsigned long b)
35: #else
36: mpz_kronecker_ui (a, b)
37: mpz_srcptr a;
38: unsigned long b;
39: #endif
40: {
41: int twos;
42:
43: if (b & 1)
44: {
45: if (b != 1)
46: return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, 0);
47: else
48: return 1; /* (a/1)=1 for any a */
49: }
50:
51: if (b == 0)
52: return JACOBI_Z0 (a);
53:
54: /* (a/2)=0 if a even */
55: if (mpz_even_p (a))
56: return 0;
57:
58: /* (a/2)=(2/a) when a odd */
59: count_trailing_zeros (twos, b);
60: b >>= twos;
61: if (b == 1)
62: return JACOBI_TWOS_U (twos, PTR(a)[0]);
63:
64: return mpn_jacobi_base (mpz_fdiv_ui (a, b), b,
65: JACOBI_TWOS_U_BIT1(twos, PTR(a)[0]));
66: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>