Generated by Cython 0.9.6.13 on Fri Apr 11 09:08:40 2008
Raw output: _Users_was__sage_sage_notebook_worksheets_admin_135_code_sage110_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_digits7(Integer n, Integer e, unsigned int d):
static PyObject *__pyx_k_1p; static char __pyx_k_1[] = "0"; static PyObject *__pyx_pf_71_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage110_spyx_0_last_digits7(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_71_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage110_spyx_0_last_digits7[] = "File: _Users_was__sage_sage_notebook_worksheets_admin_135_code_sage110_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_sage110_spyx_0_last_digits7(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_v_t; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; Py_ssize_t __pyx_3 = 0; PyObject *__pyx_4 = 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_sage110_spyx_0.last_digits7"); return NULL; __pyx_L3:; __pyx_v_t = Py_None; Py_INCREF(Py_None); 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_sage110_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:
19: t = str(s)
__pyx_1 = PyTuple_New(1); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} Py_INCREF(((PyObject *)__pyx_v_s)); PyTuple_SET_ITEM(__pyx_1, 0, ((PyObject *)__pyx_v_s)); __pyx_2 = PyObject_Call(((PyObject*)&PyString_Type), __pyx_1, NULL); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_v_t); __pyx_v_t = __pyx_2; __pyx_2 = 0;
20: t = '0'*(dcoerce-len(t)) + t
__pyx_1 = __pyx_k_1p; Py_INCREF(__pyx_1); __pyx_3 = PyObject_Length(__pyx_v_t); if (unlikely(__pyx_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} __pyx_2 = PyInt_FromSsize_t((__pyx_v_d - __pyx_3)); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} __pyx_4 = PyNumber_Multiply(__pyx_1, __pyx_2); if (unlikely(!__pyx_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_2); __pyx_2 = 0; __pyx_1 = PyNumber_Add(__pyx_4, __pyx_v_t); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} Py_DECREF(__pyx_4); __pyx_4 = 0; Py_DECREF(__pyx_v_t); __pyx_v_t = __pyx_1; __pyx_1 = 0;
21: return t
Py_INCREF(__pyx_v_t); __pyx_r = __pyx_v_t; goto __pyx_L0; __pyx_r = Py_None; Py_INCREF(Py_None); goto __pyx_L0; __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_4); __Pyx_AddTraceback("_Users_was__sage_sage_notebook_worksheets_admin_135_code_sage110_spyx_0.last_digits7"); __pyx_r = NULL; __pyx_L0:; Py_XDECREF((PyObject *)__pyx_v_s); Py_DECREF(__pyx_v_t); return __pyx_r; }