Generated by Cython 0.9.6.13 on Fri Apr 11 10:13:15 2008

Raw output: _Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0.c

 1: 
 2: include "interrupt.pxi"  # ctrl-c interrupt block support
 3: include "stdsage.pxi"  # ctrl-c interrupt block support
 4: 
 5: include "cdefs.pxi"
 6: from sage.rings.integer cimport Integer
 7: def last_digits8(Integer n, Integer e, unsigned int d):
static PyObject *__pyx_pf_71_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0_last_digits8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_71_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0_last_digits8[] = "File: _Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0.pyx (starting at line 7)\n\n    Return the last d digits of n^e.\n    ";
static PyObject *__pyx_pf_71_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0_last_digits8(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  struct __pyx_obj_4sage_5rings_7integer_Integer *__pyx_v_n = 0;
  struct __pyx_obj_4sage_5rings_7integer_Integer *__pyx_v_e = 0;
  unsigned int __pyx_v_d;
  mpz_t __pyx_v_ten;
  mpz_t __pyx_v_tenpow;
  struct __pyx_obj_4sage_5rings_7integer_Integer *__pyx_v_s = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {"n","e","d",0};
  if (likely(!__pyx_kwds) && likely(PyTuple_GET_SIZE(__pyx_args) == 3)) {
    __pyx_v_n = ((struct __pyx_obj_4sage_5rings_7integer_Integer *)PyTuple_GET_ITEM(__pyx_args, 0));
    __pyx_v_e = ((struct __pyx_obj_4sage_5rings_7integer_Integer *)PyTuple_GET_ITEM(__pyx_args, 1));
    __pyx_v_d = PyInt_AsUnsignedLongMask(PyTuple_GET_ITEM(__pyx_args, 2)); if (unlikely((__pyx_v_d == (unsigned int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L2;}
  }
  else {
    if (unlikely(!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_n, &__pyx_v_e, &__pyx_v_d))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L2;}
  }
  goto __pyx_L3;
  __pyx_L2:;
  __Pyx_AddTraceback("_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0.last_digits8");
  return NULL;
  __pyx_L3:;
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_n), __pyx_ptype_4sage_5rings_7integer_Integer, 1, "n"))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_e), __pyx_ptype_4sage_5rings_7integer_Integer, 1, "e"))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}
  return;
  __Pyx_AddTraceback("_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0");
}
 8:     """
 9:     Return the last d digits of n^e.
 10:     """
 11:     cdef mpz_t ten, tenpow
 12:     mpz_init_set_ui(ten, 10)     # ten = 10
  mpz_init_set_ui(__pyx_v_ten, 10);
 13:     mpz_init(tenpow)
  mpz_init(__pyx_v_tenpow);
 14:     mpz_pow_ui(tenpow, ten, d)   # tenpow = 10^d
  mpz_pow_ui(__pyx_v_tenpow, __pyx_v_ten, __pyx_v_d);
 15: 
 16:     cdef Integer s = Integer()
  __pyx_1 = PyObject_Call(((PyObject*)__pyx_ptype_4sage_5rings_7integer_Integer), __pyx_empty_tuple, NULL); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;}
  if (!__Pyx_TypeTest(__pyx_1, __pyx_ptype_4sage_5rings_7integer_Integer)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;}
  __pyx_v_s = ((struct __pyx_obj_4sage_5rings_7integer_Integer *)__pyx_1);
  __pyx_1 = 0;

 17:     mpz_powm(s.value, n.value, e.value, tenpow)  # m = n^d % tenpow
  mpz_powm(__pyx_v_s->value, __pyx_v_n->value, __pyx_v_e->value, __pyx_v_tenpow);
 18:     mpz_clear(ten); mpz_clear(tenpow)  # avoid memory leaks!
  mpz_clear(__pyx_v_ten);
  mpz_clear(__pyx_v_tenpow);
 19: 
 20:     return s
  Py_INCREF(((PyObject *)__pyx_v_s));
  __pyx_r = ((PyObject *)__pyx_v_s);
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage156_spyx_0.last_digits8");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_XDECREF((PyObject *)__pyx_v_s);
  return __pyx_r;
}