Beispiel #1
0
Error, error, unsupported BITS_PER_MP_LIMB
#endif


int
mpz_kronecker_ui (mpz_srcptr a, unsigned long b)
{
  mp_srcptr  a_ptr = PTR(a);
  mp_size_t  a_size;
  mp_limb_t  a_rem;
  int        result_bit1;

  a_size = SIZ(a);
  if (a_size == 0)
    return JACOBI_0U (b);

  if (b > GMP_NUMB_MAX)
    {
      mp_limb_t  blimbs[2];
      mpz_t      bz;
      ALLOC(bz) = numberof (blimbs);
      PTR(bz) = blimbs;
      mpz_set_ui (bz, b);
      return mpz_kronecker (a, bz);
    }

  if ((b & 1) != 0)
    {
      result_bit1 = JACOBI_ASGN_SU_BIT1 (a_size, b);
    }
  else
    {
      mp_limb_t  a_low = a_ptr[0];
      int        twos;

      if (b == 0)
        return JACOBI_LS0 (a_low, a_size);   /* (a/0) */

      if (! (a_low & 1))
        return 0;  /* (even/even)=0 */

      /* (a/2)=(2/a) for a odd */
      count_trailing_zeros (twos, b);
      b >>= twos;
      result_bit1 = (JACOBI_TWOS_U_BIT1 (twos, a_low)
                     ^ JACOBI_ASGN_SU_BIT1 (a_size, b));
    }

  if (b == 1)
    return JACOBI_BIT1_TO_PN (result_bit1);  /* (a/1)=1 for any a */

  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);
  return mpn_jacobi_base (a_rem, (mp_limb_t) b, result_bit1);
}
Beispiel #2
0
int
mpz_si_kronecker (long a, mpz_srcptr b)
{
  mp_srcptr  b_ptr;
  mp_limb_t  b_low;
  mp_size_t  b_size;
  mp_size_t  b_abs_size;
  mp_limb_t  a_limb, b_rem;
  unsigned   twos;
  int        result_bit1;

#if GMP_NUMB_BITS < BITS_PER_ULONG
  if (a > GMP_NUMB_MAX || a < -GMP_NUMB_MAX)
    {
      mp_limb_t  alimbs[2];
      mpz_t      az;
      ALLOC(az) = numberof (alimbs);
      PTR(az) = alimbs;
      mpz_set_si (az, a);
      return mpz_kronecker (az, b);
    }
#endif

  b_size = SIZ (b);
  if (b_size == 0)
    return JACOBI_S0 (a);  /* (a/0) */

  /* account for the effect of the sign of b, then ignore it */
  result_bit1 = JACOBI_BSGN_SS_BIT1 (a, b_size);

  b_ptr = PTR(b);
  b_low = b_ptr[0];
  b_abs_size = ABS (b_size);

  if ((b_low & 1) != 0)
    {
      /* b odd */

      result_bit1 ^= JACOBI_ASGN_SU_BIT1 (a, b_low);
      a_limb = (unsigned long) ABS(a);

      if ((a_limb & 1) == 0)
	{
	  /* (0/b)=1 for b=+/-1, 0 otherwise */
	  if (a_limb == 0)
	    return (b_abs_size == 1 && b_low == 1);

	  /* a even, b odd */
	  count_trailing_zeros (twos, a_limb);
	  a_limb >>= twos;
	  /* (a*2^n/b) = (a/b) * twos(n,a) */
	  result_bit1 ^= JACOBI_TWOS_U_BIT1 (twos, b_low);
	}
    }