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

Diff for /OpenXM_contrib/gmp/mpz/Attic/kronzs.c between version 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2000/09/09 14:12:54 version 1.1.1.2, 2003/08/25 16:06:33
Line 1 
Line 1 
 /* mpz_kronecker_si -- Kronecker/Jacobi symbol. */  /* mpz_kronecker_si -- mpz+long Kronecker/Jacobi symbol.
   
 /*  Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
 Copyright (C) 1999, 2000 Free Software Foundation, Inc.  
   
 This file is part of the GNU MP Library.  This file is part of the GNU MP Library.
   
Line 18  License for more details.
Line 17  License for more details.
 You should have received a copy of the GNU Lesser General Public License  You should have received a copy of the GNU Lesser General Public License
 along with the GNU MP Library; see the file COPYING.LIB.  If not, write to  along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,  the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 MA 02111-1307, USA.  MA 02111-1307, USA. */
 */  
   
 #include "gmp.h"  #include "gmp.h"
 #include "gmp-impl.h"  #include "gmp-impl.h"
 #include "longlong.h"  #include "longlong.h"
   
   
 /* This function is expected to be often used with b odd, so there's a test  /* This implementation depends on BITS_PER_MP_LIMB being even, so that
    for this before invoking count_trailing_zeros().     (a/2)^BITS_PER_MP_LIMB = 1 and so there's no need to pay attention to how
      many low zero limbs are stripped.  */
   #if BITS_PER_MP_LIMB % 2 != 0
   Error, error, unsupported BITS_PER_MP_LIMB
   #endif
   
    After the absolute value of b is established it's treated as an unsigned  
   /* After the absolute value of b is established it's treated as an unsigned
    long, because 0x80..00 doesn't fit in a signed long. */     long, because 0x80..00 doesn't fit in a signed long. */
   
 int  int
 #if __STDC__  
 mpz_kronecker_si (mpz_srcptr a, long b)  mpz_kronecker_si (mpz_srcptr a, long b)
 #else  
 mpz_kronecker_si (a, b)  
      mpz_srcptr a;  
      long       b;  
 #endif  
 {  {
   int  result_bit1;    mp_srcptr  a_ptr = PTR(a);
   int  twos;    mp_size_t  a_size;
     mp_limb_t  a_rem, b_limb;
     int        result_bit1;
   
   if (b == 0)    a_size = SIZ(a);
     return JACOBI_Z0 (a);    if (a_size == 0)
       return JACOBI_0S (b);
   
   result_bit1 = JACOBI_BSGN_ZS_BIT1(a, b);  #if GMP_NUMB_BITS < BITS_PER_ULONG
   b = ABS (b);    if (b > GMP_NUMB_MAX || b < -GMP_NUMB_MAX)
       {
         mp_limb_t  blimbs[2];
         mpz_t      bz;
         ALLOC(bz) = numberof (blimbs);
         PTR(bz) = blimbs;
         mpz_set_si (bz, b);
         return mpz_kronecker (a, bz);
       }
   #endif
   
   if (b == 1)    result_bit1 = JACOBI_BSGN_SS_BIT1 (a_size, b);
     return JACOBI_BIT1_TO_PN (result_bit1);  /* (a/1) = 1 for any a */    b_limb = (unsigned long) ABS (b);
   
   if (b & 1)    if ((b_limb & 1) == 0)
     return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, result_bit1);      {
         mp_limb_t  a_low = a_ptr[0];
   /* result 0 if both a,b even */        int        twos;
   if (mpz_even_p (a))  
     return 0;  
   
   /* (a/2)=(2/a) when a odd */        if (b_limb == 0)
   count_trailing_zeros (twos, b);          return JACOBI_LS0 (a_low, a_size);   /* (a/0) */
   result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, PTR(a)[0]);  
   
   b = ((unsigned long) b) >> twos;        if (! (a_low & 1))
   if (b == 1)          return 0;  /* (even/even)=0 */
     return JACOBI_BIT1_TO_PN (result_bit1);  
   else        /* (a/2)=(2/a) for a odd */
     return mpn_jacobi_base (mpz_fdiv_ui (a, b), b, result_bit1);        count_trailing_zeros (twos, b_limb);
         b_limb >>= twos;
         result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, a_low);
       }
   
     if (b_limb == 1)
       return JACOBI_BIT1_TO_PN (result_bit1);  /* (a/1)=1 for any a */
   
     result_bit1 ^= JACOBI_ASGN_SU_BIT1 (a_size, b_limb);
     a_size = ABS(a_size);
   
     /* (a/b) = (a mod b / b) */
     JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1, a_rem, a_ptr, a_size, b_limb);
     return mpn_jacobi_base (a_rem, b_limb, result_bit1);
 }  }
   
   

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2

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