Generated by Cython 0.29.15
Yellow lines hint at Python interaction.
Click on a line that starts with a "+
" to see the C code that Cython generated for it.
Raw output: cy_golden_ratio.cpp
01: # cython: language_level = 3
02: # distutils: language = c++
03:
04:
+05: cdef double c_golden_ratio(int n):
static double __pyx_f_15cy_golden_ratio_c_golden_ratio(int __pyx_v_n) { double __pyx_v_s; CYTHON_UNUSED int __pyx_v__; double __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("c_golden_ratio", 0); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_WriteUnraisable("cy_golden_ratio.c_golden_ratio", __pyx_clineno, __pyx_lineno, __pyx_filename, 1, 0); __pyx_r = 0; __pyx_L0:; __Pyx_RefNannyFinishContext(); return __pyx_r; }
+06: cdef double s = 1.0
__pyx_v_s = 1.0;
+07: for _ in range(n):
__pyx_t_1 = __pyx_v_n; __pyx_t_2 = __pyx_t_1; for (__pyx_t_3 = 0; __pyx_t_3 < __pyx_t_2; __pyx_t_3+=1) { __pyx_v__ = __pyx_t_3;
+08: s = 1.0 + 1.0 / s
if (unlikely(__pyx_v_s == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "float division"); __PYX_ERR(0, 8, __pyx_L1_error) } __pyx_v_s = (1.0 + (1.0 / __pyx_v_s)); }
+09: return s
__pyx_r = __pyx_v_s; goto __pyx_L0;
10:
11:
+12: def golden_ratio(n):
/* Python wrapper */ static PyObject *__pyx_pw_15cy_golden_ratio_1golden_ratio(PyObject *__pyx_self, PyObject *__pyx_v_n); /*proto*/ static PyMethodDef __pyx_mdef_15cy_golden_ratio_1golden_ratio = {"golden_ratio", (PyCFunction)__pyx_pw_15cy_golden_ratio_1golden_ratio, METH_O, 0}; static PyObject *__pyx_pw_15cy_golden_ratio_1golden_ratio(PyObject *__pyx_self, PyObject *__pyx_v_n) { PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("golden_ratio (wrapper)", 0); __pyx_r = __pyx_pf_15cy_golden_ratio_golden_ratio(__pyx_self, ((PyObject *)__pyx_v_n)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_15cy_golden_ratio_golden_ratio(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_n) { PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("golden_ratio", 0); /* … */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("cy_golden_ratio.golden_ratio", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_n_s_n); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_); /* … */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_15cy_golden_ratio_1golden_ratio, NULL, __pyx_n_s_cy_golden_ratio); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); if (PyDict_SetItem(__pyx_d, __pyx_n_s_golden_ratio, __pyx_t_1) < 0) __PYX_ERR(0, 12, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+13: c_golden_ratio(n)
__pyx_t_1 = __Pyx_PyInt_As_int(__pyx_v_n); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L1_error) (void)(__pyx_f_15cy_golden_ratio_c_golden_ratio(__pyx_t_1));