[BACK]Return to kronzs.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpz

Annotation of OpenXM_contrib/gmp/mpz/kronzs.c, Revision 1.1

1.1     ! maekawa     1: /* mpz_kronecker_si -- 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 odd, so there's a test
        !            30:    for this before invoking count_trailing_zeros().
        !            31:
        !            32:    After the absolute value of b is established it's treated as an unsigned
        !            33:    long, because 0x80..00 doesn't fit in a signed long. */
        !            34:
        !            35: int
        !            36: #if __STDC__
        !            37: mpz_kronecker_si (mpz_srcptr a, long b)
        !            38: #else
        !            39: mpz_kronecker_si (a, b)
        !            40:      mpz_srcptr a;
        !            41:      long       b;
        !            42: #endif
        !            43: {
        !            44:   int  result_bit1;
        !            45:   int  twos;
        !            46:
        !            47:   if (b == 0)
        !            48:     return JACOBI_Z0 (a);
        !            49:
        !            50:   result_bit1 = JACOBI_BSGN_ZS_BIT1(a, b);
        !            51:   b = ABS (b);
        !            52:
        !            53:   if (b == 1)
        !            54:     return JACOBI_BIT1_TO_PN (result_bit1);  /* (a/1) = 1 for any a */
        !            55:
        !            56:   if (b & 1)
        !            57:     return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, result_bit1);
        !            58:
        !            59:   /* result 0 if both a,b even */
        !            60:   if (mpz_even_p (a))
        !            61:     return 0;
        !            62:
        !            63:   /* (a/2)=(2/a) when a odd */
        !            64:   count_trailing_zeros (twos, b);
        !            65:   result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, PTR(a)[0]);
        !            66:
        !            67:   b = ((unsigned long) b) >> twos;
        !            68:   if (b == 1)
        !            69:     return JACOBI_BIT1_TO_PN (result_bit1);
        !            70:   else
        !            71:     return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, result_bit1);
        !            72: }
        !            73:
        !            74:

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>