Generated by Cython 3.0.9
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: quicktions.c
+0001: # cython: language_level=3str
__pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (PyDict_SetItem(__pyx_t_9, __pyx_kp_u_Fraction_limit_denominator_line, __pyx_kp_u_Closest_Fraction_to_self_with_de) < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_9) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
0002: ## cython: profile=True
0003:
0004: # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
0005: # 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved
0006: #
0007: # Based on the "fractions" module in CPython 3.4+.
0008: # https://hg.python.org/cpython/file/b18288f24501/Lib/fractions.py
0009: #
0010: # Updated to match the recent development in CPython.
0011: # https://github.com/python/cpython/blob/main/Lib/fractions.py
0012: #
0013: # Adapted for efficient Cython compilation by Stefan Behnel.
0014: #
0015:
0016: """
0017: Fast fractions data type for rational numbers.
0018:
0019: This is an almost-drop-in replacement for the standard library's
0020: "fractions.Fraction".
0021: """
0022:
0023: from __future__ import division, absolute_import, print_function
0024:
0025:
+0026: __all__ = ['Fraction']
__pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_Fraction_2); __Pyx_GIVEREF(__pyx_n_s_Fraction_2); if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Fraction_2)) __PYX_ERR(0, 26, __pyx_L1_error); if (PyDict_SetItem(__pyx_d, __pyx_n_s_all, __pyx_t_2) < 0) __PYX_ERR(0, 26, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0027:
+0028: __version__ = '1.17'
if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_kp_s_1_17) < 0) __PYX_ERR(0, 28, __pyx_L1_error)
0029:
0030: cimport cython
0031: from cpython.unicode cimport Py_UNICODE_TODECIMAL
0032: from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
0033: from cpython.version cimport PY_MAJOR_VERSION
0034: from cpython.long cimport PyLong_FromString
0035:
0036: cdef extern from *:
0037: cdef long LONG_MAX, INT_MAX
0038: cdef long long PY_LLONG_MIN, PY_LLONG_MAX
0039: cdef long long MAX_SMALL_NUMBER "(PY_LLONG_MAX / 100)"
0040:
0041: cdef object Rational, Integral, Real, Complex, Decimal, math, operator, re, sys
+0042: cdef object PY_MAX_LONG_LONG = PY_LLONG_MAX
__pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(PY_LLONG_MAX); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_PY_MAX_LONG_LONG); __Pyx_DECREF_SET(__pyx_v_10quicktions_PY_MAX_LONG_LONG, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
0043:
+0044: from numbers import Rational, Integral, Real, Complex
__pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_n_s_Rational); __Pyx_GIVEREF(__pyx_n_s_Rational); if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_Rational)) __PYX_ERR(0, 44, __pyx_L1_error); __Pyx_INCREF(__pyx_n_s_Integral); __Pyx_GIVEREF(__pyx_n_s_Integral); if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_Integral)) __PYX_ERR(0, 44, __pyx_L1_error); __Pyx_INCREF(__pyx_n_s_Real); __Pyx_GIVEREF(__pyx_n_s_Real); if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_Real)) __PYX_ERR(0, 44, __pyx_L1_error); __Pyx_INCREF(__pyx_n_s_Complex); __Pyx_GIVEREF(__pyx_n_s_Complex); if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 3, __pyx_n_s_Complex)) __PYX_ERR(0, 44, __pyx_L1_error); __pyx_t_3 = __Pyx_Import(__pyx_n_s_numbers, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Rational); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_Rational); __Pyx_DECREF_SET(__pyx_v_10quicktions_Rational, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Integral); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_Integral); __Pyx_DECREF_SET(__pyx_v_10quicktions_Integral, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Real); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_Real); __Pyx_DECREF_SET(__pyx_v_10quicktions_Real, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_Complex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_Complex); __Pyx_DECREF_SET(__pyx_v_10quicktions_Complex, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+0045: from decimal import Decimal
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_n_s_Decimal); __Pyx_GIVEREF(__pyx_n_s_Decimal); if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_Decimal)) __PYX_ERR(0, 45, __pyx_L1_error); __pyx_t_2 = __Pyx_Import(__pyx_n_s_decimal, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Decimal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 45, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions_Decimal); __Pyx_DECREF_SET(__pyx_v_10quicktions_Decimal, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+0046: import math
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_math, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_math); __Pyx_DECREF_SET(__pyx_v_10quicktions_math, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+0047: import operator
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_operator, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_operator); __Pyx_DECREF_SET(__pyx_v_10quicktions_operator, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+0048: import re
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_re, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_re); __Pyx_DECREF_SET(__pyx_v_10quicktions_re, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+0049: import sys
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_sys, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 49, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_sys); __Pyx_DECREF_SET(__pyx_v_10quicktions_sys, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
0050:
+0051: cdef bint _decimal_supports_integer_ratio = hasattr(Decimal, "as_integer_ratio") # Py3.6+
__pyx_t_2 = __pyx_v_10quicktions_Decimal; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = __Pyx_HasAttr(__pyx_t_2, __pyx_n_s_as_integer_ratio); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(0, 51, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_10quicktions__decimal_supports_integer_ratio = __pyx_t_4;
+0052: cdef object _operator_index = operator.index
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions__operator_index); __Pyx_DECREF_SET(__pyx_v_10quicktions__operator_index, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
0053: cdef object math_gcd
+0054: try:
{ /*try:*/ { /* … */ } __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L7_try_end; __pyx_L2_error:; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_L4_except_error:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_5, __pyx_t_6); goto __pyx_L1_error; __pyx_L3_exception_handled:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_5, __pyx_t_6); __pyx_L7_try_end:; }
+0055: math_gcd = math.gcd
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_n_s_gcd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 55, __pyx_L2_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_math_gcd); __Pyx_DECREF_SET(__pyx_v_10quicktions_math_gcd, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+0056: except AttributeError:
__pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); if (__pyx_t_7) { __Pyx_ErrRestore(0,0,0); goto __pyx_L3_exception_handled; } goto __pyx_L4_except_error;
0057: pass
0058:
0059:
0060: # Cache widely used 10**x int objects.
0061: DEF CACHED_POW10 = 64 # sys.getsizeof(tuple[58]) == 512 bytes in Py3.7
0062:
+0063: cdef tuple _cache_pow10():
static PyObject *__pyx_f_10quicktions__cache_pow10(void) { int __pyx_v_i; int __pyx_v_in_ull; PyObject *__pyx_v_l = NULL; PyObject *__pyx_v_x = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("quicktions._cache_pow10", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_l); __Pyx_XDECREF(__pyx_v_x); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0064: cdef int i
+0065: in_ull = True
__pyx_v_in_ull = 1;
+0066: l = []
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_l = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+0067: x = 1
__Pyx_INCREF(__pyx_int_1);
__pyx_v_x = __pyx_int_1;
+0068: for i in range(CACHED_POW10):
for (__pyx_t_2 = 0; __pyx_t_2 < 64; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2;
+0069: l.append(x)
__pyx_t_3 = __Pyx_PyList_Append(__pyx_v_l, __pyx_v_x); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 69, __pyx_L1_error)
+0070: if in_ull:
if (__pyx_v_in_ull) { /* … */ }
+0071: try:
{ /*try:*/ { /* … */ } __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L13_try_end; __pyx_L6_error:; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_L8_except_error:; __Pyx_XGIVEREF(__pyx_t_4); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); goto __pyx_L1_error; __pyx_L7_exception_handled:; __Pyx_XGIVEREF(__pyx_t_4); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_4, __pyx_t_5, __pyx_t_6); __pyx_L13_try_end:; }
+0072: _C_POW_10[i] = x
__pyx_t_7 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_x); if (unlikely((__pyx_t_7 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 72, __pyx_L6_error) (__pyx_v_10quicktions__C_POW_10[__pyx_v_i]) = __pyx_t_7;
+0073: except OverflowError:
__pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); if (__pyx_t_8) { __Pyx_AddTraceback("quicktions._cache_pow10", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_9, &__pyx_t_10) < 0) __PYX_ERR(0, 73, __pyx_L8_except_error) __Pyx_XGOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_10);
+0074: in_ull = False
__pyx_v_in_ull = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L7_exception_handled; } goto __pyx_L8_except_error;
+0075: x *= 10
__pyx_t_10 = __Pyx_PyInt_MultiplyObjC(__pyx_v_x, __pyx_int_10, 10, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_10); __pyx_t_10 = 0; }
+0076: return tuple(l)
__Pyx_XDECREF(__pyx_r); __pyx_t_10 = PyList_AsTuple(__pyx_v_l); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 76, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_r = ((PyObject*)__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L0;
0077:
0078: cdef unsigned long long[CACHED_POW10] _C_POW_10
+0079: cdef tuple POW_10 = _cache_pow10()
__pyx_t_2 = __pyx_f_10quicktions__cache_pow10(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_POW_10); __Pyx_DECREF_SET(__pyx_v_10quicktions_POW_10, ((PyObject*)__pyx_t_2)); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
0080:
0081:
+0082: cdef unsigned long long _c_pow10(Py_ssize_t i):
static unsigned PY_LONG_LONG __pyx_f_10quicktions__c_pow10(Py_ssize_t __pyx_v_i) { unsigned PY_LONG_LONG __pyx_r; /* … */ /* function exit code */ __pyx_L0:; return __pyx_r; }
+0083: return _C_POW_10[i]
__pyx_r = (__pyx_v_10quicktions__C_POW_10[__pyx_v_i]); goto __pyx_L0;
0084:
0085:
+0086: cdef pow10(long long i):
static PyObject *__pyx_f_10quicktions_pow10(PY_LONG_LONG __pyx_v_i) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.pow10", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+0087: if 0 <= i < CACHED_POW10:
__pyx_t_1 = (0 <= __pyx_v_i); if (__pyx_t_1) { __pyx_t_1 = (__pyx_v_i < 64); } if (__pyx_t_1) { /* … */ }
+0088: return POW_10[i]
__Pyx_XDECREF(__pyx_r); if (unlikely(__pyx_v_10quicktions_POW_10 == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 88, __pyx_L1_error) } __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_10quicktions_POW_10, __pyx_v_i, PY_LONG_LONG, 1, __Pyx_PyInt_From_PY_LONG_LONG, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 88, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0089: else:
+0090: return 10 ** (<object> i)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Power(__pyx_int_10, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 90, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; }
0091:
0092:
0093: # Half-private GCD implementation.
0094:
0095: cdef extern from *:
0096: """
0097: #if PY_VERSION_HEX >= 0x030c00a5 && defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
0098: #define __Quicktions_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) (x))
0099: #if CYTHON_COMPILING_IN_CPYTHON
0100: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) (((PyLongObject*)x)->long_value.ob_digit[0]))
0101: #else
0102: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) PyUnstable_Long_CompactValue((PyLongObject*) (x))))
0103: #endif
0104: #elif PY_VERSION_HEX < 0x030c0000 && CYTHON_COMPILING_IN_CPYTHON
0105: #define __Quicktions_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
0106: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) ((Py_SIZE(x) == 0) ? 0 : (((PyLongObject*)x)->ob_digit)[0]))
0107: #else
0108: #define __Quicktions_PyLong_IsCompact(x) (0)
0109: #define __Quicktions_PyLong_CompactValueUnsigned(x) (0U)
0110: #endif
0111: #if PY_VERSION_HEX < 0x030500F0 || PY_VERSION_HEX >= 0x030d0000 || !CYTHON_COMPILING_IN_CPYTHON
0112: #define _PyLong_GCD(a, b) (NULL)
0113: #endif
0114:
0115: #ifdef __GCC__
0116: #define __Quicktions_IS_GCC 1
0117: #define __Quicktions_trailing_zeros_uint(x) __builtin_ctz(x)
0118: #define __Quicktions_trailing_zeros_ulong(x) __builtin_ctzl(x)
0119: #define __Quicktions_trailing_zeros_ullong(x) __builtin_ctzll(x)
0120: #else
0121: #define __Quicktions_IS_GCC 0
0122: #define __Quicktions_trailing_zeros_uint(x) (0)
0123: #define __Quicktions_trailing_zeros_ulong(x) (0)
0124: #define __Quicktions_trailing_zeros_ullong(x) (0)
0125: #endif
0126: """
0127: bint PyLong_IsCompact "__Quicktions_PyLong_IsCompact" (x)
0128: Py_ssize_t PyLong_CompactValueUnsigned "__Quicktions_PyLong_CompactValueUnsigned" (x)
0129:
0130: # CPython 3.5-3.12 has a fast PyLong GCD implementation that we can use.
0131: # In CPython 3.13, math.gcd() is fast enough to call it directly.
0132: int PY_VERSION_HEX
0133: int HAS_PYLONG_GCD "(CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000)"
0134: _PyLong_GCD(a, b)
0135:
0136: bint IS_GCC "__Quicktions_IS_GCC"
0137: int trailing_zeros_uint "__Quicktions_trailing_zeros_uint" (unsigned int x)
0138: int trailing_zeros_ulong "__Quicktions_trailing_zeros_ulong" (unsigned long x)
0139: int trailing_zeros_ullong "__Quicktions_trailing_zeros_ullong" (unsigned long long x)
0140:
0141:
+0142: cpdef _gcd(a, b):
static PyObject *__pyx_pw_10quicktions_1_gcd(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyObject *__pyx_f_10quicktions__gcd(PyObject *__pyx_v_a, PyObject *__pyx_v_b, CYTHON_UNUSED int __pyx_skip_dispatch) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions._gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* Python wrapper */ static PyObject *__pyx_pw_10quicktions_1_gcd(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions__gcd, "Calculate the Greatest Common Divisor of a and b as a non-negative number.\n "); static PyMethodDef __pyx_mdef_10quicktions_1_gcd = {"_gcd", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_1_gcd, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions__gcd}; static PyObject *__pyx_pw_10quicktions_1_gcd(PyObject *__pyx_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_a = 0; PyObject *__pyx_v_b = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("_gcd (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_a,&__pyx_n_s_b,0}; PyObject* values[2] = {0,0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_a)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L3_error) else goto __pyx_L5_argtuple_error; CYTHON_FALLTHROUGH; case 1: if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_b)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 142, __pyx_L3_error) else { __Pyx_RaiseArgtupleInvalid("_gcd", 1, 2, 2, 1); __PYX_ERR(0, 142, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "_gcd") < 0)) __PYX_ERR(0, 142, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 2)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); } __pyx_v_a = values[0]; __pyx_v_b = values[1]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("_gcd", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 142, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions._gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions__gcd(__pyx_self, __pyx_v_a, __pyx_v_b); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions__gcd(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_10quicktions__gcd(__pyx_v_a, __pyx_v_b, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("quicktions._gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__20 = PyTuple_Pack(2, __pyx_n_s_a, __pyx_n_s_b); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__20); __Pyx_GIVEREF(__pyx_tuple__20); /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_1_gcd, 0, __pyx_n_s_gcd_2, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_d, __pyx_n_s_gcd_2, __pyx_t_2) < 0) __PYX_ERR(0, 142, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_gcd_2, 142, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 142, __pyx_L1_error)
0143: """Calculate the Greatest Common Divisor of a and b as a non-negative number.
0144: """
+0145: if PyLong_IsCompact(a) and PyLong_IsCompact(b):
__pyx_t_2 = __Quicktions_PyLong_IsCompact(__pyx_v_a); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = __Quicktions_PyLong_IsCompact(__pyx_v_b); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0146: return _c_gcd(PyLong_CompactValueUnsigned(a), PyLong_CompactValueUnsigned(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_f_10quicktions__c_gcd(__Quicktions_PyLong_CompactValueUnsigned(__pyx_v_a), __Quicktions_PyLong_CompactValueUnsigned(__pyx_v_b)); if (unlikely(__pyx_t_3 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 146, __pyx_L1_error) __pyx_t_4 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 146, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0147: if PY_VERSION_HEX >= 0x030d0000:
__pyx_t_1 = (PY_VERSION_HEX >= 0x030d0000); if (__pyx_t_1) { /* … */ }
+0148: return math_gcd(a, b)
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_10quicktions_math_gcd); __pyx_t_5 = __pyx_v_10quicktions_math_gcd; __pyx_t_6 = NULL; __pyx_t_7 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); __pyx_t_7 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_6, __pyx_v_a, __pyx_v_b}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 148, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0149: if PY_VERSION_HEX < 0x030500F0 or not HAS_PYLONG_GCD:
__pyx_t_2 = (PY_VERSION_HEX < 0x030500F0); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L8_bool_binop_done; } __pyx_t_2 = (!((CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000) != 0)); __pyx_t_1 = __pyx_t_2; __pyx_L8_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0150: return _gcd_fallback(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __pyx_f_10quicktions__gcd_fallback(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0151: return _PyLong_GCD(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = _PyLong_GCD(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0152:
0153:
+0154: ctypedef unsigned long long ullong
typedef unsigned PY_LONG_LONG __pyx_t_10quicktions_ullong;
+0155: ctypedef unsigned long ulong
typedef unsigned long __pyx_t_10quicktions_ulong;
0156: ctypedef unsigned int uint
0157:
0158: ctypedef fused cunumber:
0159: ullong
0160: ulong
0161: uint
0162:
0163:
+0164: cdef ullong _abs(long long x):
static __pyx_t_10quicktions_ullong __pyx_f_10quicktions__abs(PY_LONG_LONG __pyx_v_x) { __pyx_t_10quicktions_ullong __pyx_r; /* … */ /* function exit code */ __pyx_L0:; return __pyx_r; }
+0165: if x == PY_LLONG_MIN:
__pyx_t_1 = (__pyx_v_x == PY_LLONG_MIN); if (__pyx_t_1) { /* … */ }
+0166: return (<ullong>PY_LLONG_MAX) + 1
__pyx_r = (((__pyx_t_10quicktions_ullong)PY_LLONG_MAX) + 1); goto __pyx_L0;
+0167: return abs(x)
__pyx_t_2 = __Pyx_abs_longlong(__pyx_v_x); __pyx_r = __pyx_t_2; goto __pyx_L0;
0168:
0169:
+0170: cdef cunumber _igcd(cunumber a, cunumber b):
static __pyx_t_10quicktions_ullong __pyx_fuse_0__pyx_f_10quicktions__igcd(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) { __pyx_t_10quicktions_ullong __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions._igcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; } static __pyx_t_10quicktions_ulong __pyx_fuse_1__pyx_f_10quicktions__igcd(__pyx_t_10quicktions_ulong __pyx_v_a, __pyx_t_10quicktions_ulong __pyx_v_b) { __pyx_t_10quicktions_ulong __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions._igcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; } static __pyx_t_10quicktions_uint __pyx_fuse_2__pyx_f_10quicktions__igcd(__pyx_t_10quicktions_uint __pyx_v_a, __pyx_t_10quicktions_uint __pyx_v_b) { __pyx_t_10quicktions_uint __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions._igcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; }
0171: """Euclid's GCD algorithm"""
+0172: if IS_GCC:
if (__Quicktions_IS_GCC) { /* … */ } /* … */ if (__Quicktions_IS_GCC) { /* … */ } /* … */ if (__Quicktions_IS_GCC) { /* … */ }
+0173: return _binary_gcd(a, b)
__pyx_t_1 = __pyx_fuse_0__pyx_f_10quicktions__binary_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; /* … */ __pyx_t_1 = __pyx_fuse_1__pyx_f_10quicktions__binary_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; /* … */ __pyx_t_1 = __pyx_fuse_2__pyx_f_10quicktions__binary_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 173, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0;
0174: else:
+0175: return _euclid_gcd(a, b)
/*else*/ { __pyx_t_1 = __pyx_fuse_0__pyx_f_10quicktions__euclid_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 175, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; } /* … */ /*else*/ { __pyx_t_1 = __pyx_fuse_1__pyx_f_10quicktions__euclid_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 175, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; } /* … */ /*else*/ { __pyx_t_1 = __pyx_fuse_2__pyx_f_10quicktions__euclid_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 175, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; }
0176:
0177:
+0178: cdef cunumber _euclid_gcd(cunumber a, cunumber b):
static __pyx_t_10quicktions_ullong __pyx_fuse_0__pyx_f_10quicktions__euclid_gcd(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) { __pyx_t_10quicktions_ullong __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions._euclid_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; } static __pyx_t_10quicktions_ulong __pyx_fuse_1__pyx_f_10quicktions__euclid_gcd(__pyx_t_10quicktions_ulong __pyx_v_a, __pyx_t_10quicktions_ulong __pyx_v_b) { __pyx_t_10quicktions_ulong __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions._euclid_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; } static __pyx_t_10quicktions_uint __pyx_fuse_2__pyx_f_10quicktions__euclid_gcd(__pyx_t_10quicktions_uint __pyx_v_a, __pyx_t_10quicktions_uint __pyx_v_b) { __pyx_t_10quicktions_uint __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions._euclid_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; }
0179: """Euclid's GCD algorithm"""
+0180: while b:
while (1) { __pyx_t_1 = (__pyx_v_b != 0); if (!__pyx_t_1) break; /* … */ while (1) { __pyx_t_1 = (__pyx_v_b != 0); if (!__pyx_t_1) break; /* … */ while (1) { __pyx_t_1 = (__pyx_v_b != 0); if (!__pyx_t_1) break;
+0181: a, b = b, a%b
__pyx_t_2 = __pyx_v_b; if (unlikely(__pyx_v_b == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); __PYX_ERR(0, 181, __pyx_L1_error) } __pyx_t_3 = (__pyx_v_a % __pyx_v_b); __pyx_v_a = __pyx_t_2; __pyx_v_b = __pyx_t_3; } /* … */ __pyx_t_2 = __pyx_v_b; if (unlikely(__pyx_v_b == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); __PYX_ERR(0, 181, __pyx_L1_error) } __pyx_t_3 = (__pyx_v_a % __pyx_v_b); __pyx_v_a = __pyx_t_2; __pyx_v_b = __pyx_t_3; } /* … */ __pyx_t_2 = __pyx_v_b; if (unlikely(__pyx_v_b == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "integer division or modulo by zero"); __PYX_ERR(0, 181, __pyx_L1_error) } __pyx_t_3 = (__pyx_v_a % __pyx_v_b); __pyx_v_a = __pyx_t_2; __pyx_v_b = __pyx_t_3; }
+0182: return a
__pyx_r = __pyx_v_a; goto __pyx_L0; /* … */ __pyx_r = __pyx_v_a; goto __pyx_L0; /* … */ __pyx_r = __pyx_v_a; goto __pyx_L0;
0183:
0184:
+0185: cdef inline int trailing_zeros(cunumber x):
static CYTHON_INLINE int __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_t_10quicktions_ullong __pyx_v_x) { int __pyx_r; /* … */ /* function exit code */ __pyx_L0:; return __pyx_r; } static CYTHON_INLINE int __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_t_10quicktions_ulong __pyx_v_x) { int __pyx_r; /* … */ /* function exit code */ __pyx_L0:; return __pyx_r; } static CYTHON_INLINE int __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_t_10quicktions_uint __pyx_v_x) { int __pyx_r; /* … */ /* function exit code */ __pyx_L0:; return __pyx_r; }
0186: if cunumber is uint:
+0187: return trailing_zeros_uint(x)
__pyx_r = __Quicktions_trailing_zeros_uint(__pyx_v_x); goto __pyx_L0;
0188: elif cunumber is ulong:
+0189: return trailing_zeros_ulong(x)
__pyx_r = __Quicktions_trailing_zeros_ulong(__pyx_v_x); goto __pyx_L0;
0190: else:
+0191: return trailing_zeros_ullong(x)
__pyx_r = __Quicktions_trailing_zeros_ullong(__pyx_v_x); goto __pyx_L0;
0192:
0193:
+0194: cdef cunumber _binary_gcd(cunumber a, cunumber b):
static __pyx_t_10quicktions_ullong __pyx_fuse_0__pyx_f_10quicktions__binary_gcd(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) { int __pyx_v_i; int __pyx_v_j; int __pyx_v_k; __pyx_t_10quicktions_ullong __pyx_r; /* … */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("quicktions._binary_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; } static __pyx_t_10quicktions_ulong __pyx_fuse_1__pyx_f_10quicktions__binary_gcd(__pyx_t_10quicktions_ulong __pyx_v_a, __pyx_t_10quicktions_ulong __pyx_v_b) { int __pyx_v_i; int __pyx_v_j; int __pyx_v_k; __pyx_t_10quicktions_ulong __pyx_r; /* … */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("quicktions._binary_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; } static __pyx_t_10quicktions_uint __pyx_fuse_2__pyx_f_10quicktions__binary_gcd(__pyx_t_10quicktions_uint __pyx_v_a, __pyx_t_10quicktions_uint __pyx_v_b) { int __pyx_v_i; int __pyx_v_j; int __pyx_v_k; __pyx_t_10quicktions_uint __pyx_r; /* … */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("quicktions._binary_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; return __pyx_r; }
0195: # See https://en.wikipedia.org/wiki/Binary_GCD_algorithm
+0196: if not a:
__pyx_t_1 = (!(__pyx_v_a != 0)); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (!(__pyx_v_a != 0)); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (!(__pyx_v_a != 0)); if (__pyx_t_1) { /* … */ }
+0197: return b
__pyx_r = __pyx_v_b; goto __pyx_L0; /* … */ __pyx_r = __pyx_v_b; goto __pyx_L0; /* … */ __pyx_r = __pyx_v_b; goto __pyx_L0;
+0198: if not b:
__pyx_t_1 = (!(__pyx_v_b != 0)); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (!(__pyx_v_b != 0)); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (!(__pyx_v_b != 0)); if (__pyx_t_1) { /* … */ }
+0199: return a
__pyx_r = __pyx_v_a; goto __pyx_L0; /* … */ __pyx_r = __pyx_v_a; goto __pyx_L0; /* … */ __pyx_r = __pyx_v_a; goto __pyx_L0;
0200:
+0201: cdef int i = trailing_zeros(a)
__pyx_t_2 = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L1_error) __pyx_v_i = __pyx_t_2; /* … */ __pyx_t_2 = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L1_error) __pyx_v_i = __pyx_t_2; /* … */ __pyx_t_2 = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 201, __pyx_L1_error) __pyx_v_i = __pyx_t_2;
+0202: a >>= i
__pyx_v_a = (__pyx_v_a >> __pyx_v_i); /* … */ __pyx_v_a = (__pyx_v_a >> __pyx_v_i); /* … */ __pyx_v_a = (__pyx_v_a >> __pyx_v_i);
+0203: cdef int j = trailing_zeros(b)
__pyx_t_2 = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 203, __pyx_L1_error) __pyx_v_j = __pyx_t_2; /* … */ __pyx_t_2 = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 203, __pyx_L1_error) __pyx_v_j = __pyx_t_2; /* … */ __pyx_t_2 = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); if (unlikely(__pyx_t_2 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 203, __pyx_L1_error) __pyx_v_j = __pyx_t_2;
+0204: b >>= j
__pyx_v_b = (__pyx_v_b >> __pyx_v_j); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_j); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_j);
0205:
+0206: cdef int k = min(i, j)
__pyx_t_2 = __pyx_v_j; __pyx_t_3 = __pyx_v_i; __pyx_t_1 = (__pyx_t_2 < __pyx_t_3); if (__pyx_t_1) { __pyx_t_4 = __pyx_t_2; } else { __pyx_t_4 = __pyx_t_3; } __pyx_v_k = __pyx_t_4; /* … */ __pyx_t_2 = __pyx_v_j; __pyx_t_3 = __pyx_v_i; __pyx_t_1 = (__pyx_t_2 < __pyx_t_3); if (__pyx_t_1) { __pyx_t_4 = __pyx_t_2; } else { __pyx_t_4 = __pyx_t_3; } __pyx_v_k = __pyx_t_4; /* … */ __pyx_t_2 = __pyx_v_j; __pyx_t_3 = __pyx_v_i; __pyx_t_1 = (__pyx_t_2 < __pyx_t_3); if (__pyx_t_1) { __pyx_t_4 = __pyx_t_2; } else { __pyx_t_4 = __pyx_t_3; } __pyx_v_k = __pyx_t_4;
0207:
+0208: while True:
while (1) { /* … */ while (1) { /* … */ while (1) {
+0209: if a > b:
__pyx_t_1 = (__pyx_v_a > __pyx_v_b); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (__pyx_v_a > __pyx_v_b); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (__pyx_v_a > __pyx_v_b); if (__pyx_t_1) { /* … */ }
+0210: a, b = b, a
__pyx_t_5 = __pyx_v_b; __pyx_t_6 = __pyx_v_a; __pyx_v_a = __pyx_t_5; __pyx_v_b = __pyx_t_6; /* … */ __pyx_t_5 = __pyx_v_b; __pyx_t_6 = __pyx_v_a; __pyx_v_a = __pyx_t_5; __pyx_v_b = __pyx_t_6; /* … */ __pyx_t_5 = __pyx_v_b; __pyx_t_6 = __pyx_v_a; __pyx_v_a = __pyx_t_5; __pyx_v_b = __pyx_t_6;
+0211: b -= a
__pyx_v_b = (__pyx_v_b - __pyx_v_a); /* … */ __pyx_v_b = (__pyx_v_b - __pyx_v_a); /* … */ __pyx_v_b = (__pyx_v_b - __pyx_v_a);
+0212: if not b:
__pyx_t_1 = (!(__pyx_v_b != 0)); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (!(__pyx_v_b != 0)); if (__pyx_t_1) { /* … */ } /* … */ __pyx_t_1 = (!(__pyx_v_b != 0)); if (__pyx_t_1) { /* … */ }
+0213: return a << k
__pyx_r = (__pyx_v_a << __pyx_v_k); goto __pyx_L0; /* … */ __pyx_r = (__pyx_v_a << __pyx_v_k); goto __pyx_L0; /* … */ __pyx_r = (__pyx_v_a << __pyx_v_k); goto __pyx_L0;
+0214: b >>= trailing_zeros(b)
__pyx_t_4 = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_v_b = (__pyx_v_b >> __pyx_t_4); } /* … */ __pyx_t_4 = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_v_b = (__pyx_v_b >> __pyx_t_4); } /* … */ __pyx_t_4 = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_v_b = (__pyx_v_b >> __pyx_t_4); }
0215:
0216:
+0217: cdef _py_gcd(ullong a, ullong b):
static PyObject *__pyx_f_10quicktions__py_gcd(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions._py_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+0218: if a <= <ullong>INT_MAX and b <= <ullong>INT_MAX:
__pyx_t_2 = (__pyx_v_a <= ((__pyx_t_10quicktions_ullong)INT_MAX)); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = (__pyx_v_b <= ((__pyx_t_10quicktions_ullong)INT_MAX)); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0219: return <int> _igcd[uint](<uint> a, <uint> b)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_fuse_2__pyx_f_10quicktions__igcd(((__pyx_t_10quicktions_uint)__pyx_v_a), ((__pyx_t_10quicktions_uint)__pyx_v_b)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 219, __pyx_L1_error) __pyx_t_4 = __Pyx_PyInt_From_int(((int)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0220: elif a <= <ullong>LONG_MAX and b <= <ullong>LONG_MAX:
__pyx_t_2 = (__pyx_v_a <= ((__pyx_t_10quicktions_ullong)LONG_MAX)); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L6_bool_binop_done; } __pyx_t_2 = (__pyx_v_b <= ((__pyx_t_10quicktions_ullong)LONG_MAX)); __pyx_t_1 = __pyx_t_2; __pyx_L6_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0221: return <long> _igcd[ulong](<ulong> a, <ulong> b)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __pyx_fuse_1__pyx_f_10quicktions__igcd(((__pyx_t_10quicktions_ulong)__pyx_v_a), ((__pyx_t_10quicktions_ulong)__pyx_v_b)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 221, __pyx_L1_error) __pyx_t_4 = __Pyx_PyInt_From_long(((long)__pyx_t_5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 221, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0222: elif b:
__pyx_t_1 = (__pyx_v_b != 0); if (__pyx_t_1) { /* … */ }
+0223: a = _igcd[ullong](a, b)
__pyx_t_6 = __pyx_fuse_0__pyx_f_10quicktions__igcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 223, __pyx_L1_error)
__pyx_v_a = __pyx_t_6;
0224: # try PyInt downcast in Py2
+0225: if PY_MAJOR_VERSION < 3 and a <= <ullong>LONG_MAX:
__pyx_t_2 = (PY_MAJOR_VERSION < 3); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L9_bool_binop_done; } __pyx_t_2 = (__pyx_v_a <= ((__pyx_t_10quicktions_ullong)LONG_MAX)); __pyx_t_1 = __pyx_t_2; __pyx_L9_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0226: return <long>a
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyInt_From_long(((long)__pyx_v_a)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 226, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0227: return a
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 227, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0228:
0229:
+0230: cdef ullong _c_gcd(ullong a, ullong b):
static __pyx_t_10quicktions_ullong __pyx_f_10quicktions__c_gcd(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) {
__pyx_t_10quicktions_ullong __pyx_r;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_AddTraceback("quicktions._c_gcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
return __pyx_r;
}
+0231: if a <= <ullong>INT_MAX and b <= <ullong>INT_MAX:
__pyx_t_2 = (__pyx_v_a <= ((__pyx_t_10quicktions_ullong)INT_MAX)); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = (__pyx_v_b <= ((__pyx_t_10quicktions_ullong)INT_MAX)); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0232: return _igcd[uint](<uint> a, <uint> b)
__pyx_t_3 = __pyx_fuse_2__pyx_f_10quicktions__igcd(((__pyx_t_10quicktions_uint)__pyx_v_a), ((__pyx_t_10quicktions_uint)__pyx_v_b)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 232, __pyx_L1_error)
__pyx_r = __pyx_t_3;
goto __pyx_L0;
+0233: elif a <= <ullong>LONG_MAX and b <= <ullong>LONG_MAX:
__pyx_t_2 = (__pyx_v_a <= ((__pyx_t_10quicktions_ullong)LONG_MAX)); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L6_bool_binop_done; } __pyx_t_2 = (__pyx_v_b <= ((__pyx_t_10quicktions_ullong)LONG_MAX)); __pyx_t_1 = __pyx_t_2; __pyx_L6_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0234: return _igcd[ulong](<ulong> a, <ulong> b)
__pyx_t_4 = __pyx_fuse_1__pyx_f_10quicktions__igcd(((__pyx_t_10quicktions_ulong)__pyx_v_a), ((__pyx_t_10quicktions_ulong)__pyx_v_b)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 234, __pyx_L1_error)
__pyx_r = __pyx_t_4;
goto __pyx_L0;
0235: else:
+0236: return _igcd[ullong](a, b)
/*else*/ {
__pyx_t_5 = __pyx_fuse_0__pyx_f_10quicktions__igcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 236, __pyx_L1_error)
__pyx_r = __pyx_t_5;
goto __pyx_L0;
}
0237:
0238:
+0239: cdef _gcd_fallback(a, b):
static PyObject *__pyx_f_10quicktions__gcd_fallback(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { __pyx_t_10quicktions_ullong __pyx_v_au; __pyx_t_10quicktions_ullong __pyx_v_bu; PY_LONG_LONG __pyx_v_ai; PY_LONG_LONG __pyx_v_bi; PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_a); __Pyx_INCREF(__pyx_v_b); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("quicktions._gcd_fallback", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_a); __Pyx_XDECREF(__pyx_v_b); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0240: """Fallback GCD implementation if _PyLong_GCD() is not available.
0241: """
0242: # Try doing the computation in C space. If the numbers are too
0243: # large at the beginning, do object calculations until they are small enough.
0244: cdef ullong au, bu
0245: cdef long long ai, bi
0246:
0247: # Optimistically try to switch to C space.
+0248: try:
{ /*try:*/ { /* … */ } /* … */ __pyx_L5_except_error:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L1_error; __pyx_L6_except_return:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L0; __pyx_L4_exception_handled:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); }
+0249: ai, bi = a, b
__pyx_t_4 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_4 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 249, __pyx_L3_error) __pyx_t_5 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_5 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 249, __pyx_L3_error) __pyx_v_ai = __pyx_t_4; __pyx_v_bi = __pyx_t_5;
+0250: except OverflowError:
__pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); if (__pyx_t_8) { __Pyx_ErrRestore(0,0,0); goto __pyx_L4_exception_handled; } goto __pyx_L5_except_error;
0251: pass
0252: else:
+0253: au = _abs(ai)
/*else:*/ { __pyx_t_6 = __pyx_f_10quicktions__abs(__pyx_v_ai); if (unlikely(__pyx_t_6 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 253, __pyx_L5_except_error) __pyx_v_au = __pyx_t_6;
+0254: bu = _abs(bi)
__pyx_t_6 = __pyx_f_10quicktions__abs(__pyx_v_bi); if (unlikely(__pyx_t_6 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 254, __pyx_L5_except_error) __pyx_v_bu = __pyx_t_6;
+0255: return _py_gcd(au, bu)
__Pyx_XDECREF(__pyx_r); __pyx_t_7 = __pyx_f_10quicktions__py_gcd(__pyx_v_au, __pyx_v_bu); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 255, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L6_except_return; } __pyx_L3_error:;
0256:
0257: # Do object calculation until we reach the C space limit.
+0258: a = abs(a)
__pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_v_a); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_7); __pyx_t_7 = 0;
+0259: b = abs(b)
__pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_v_b); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 259, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_7); __pyx_t_7 = 0;
+0260: while b > PY_MAX_LONG_LONG:
while (1) { __pyx_t_7 = PyObject_RichCompare(__pyx_v_b, __pyx_v_10quicktions_PY_MAX_LONG_LONG, Py_GT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 260, __pyx_L1_error) __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 260, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (!__pyx_t_9) break;
+0261: a, b = b, a%b
__pyx_t_7 = __pyx_v_b; __Pyx_INCREF(__pyx_t_7); __pyx_t_10 = PyNumber_Remainder(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 261, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_10); __pyx_t_10 = 0; }
+0262: while b and a > PY_MAX_LONG_LONG:
while (1) { __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_v_b); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 262, __pyx_L1_error) if (__pyx_t_11) { } else { __pyx_t_9 = __pyx_t_11; goto __pyx_L13_bool_binop_done; } __pyx_t_10 = PyObject_RichCompare(__pyx_v_a, __pyx_v_10quicktions_PY_MAX_LONG_LONG, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 262, __pyx_L1_error) __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 262, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_9 = __pyx_t_11; __pyx_L13_bool_binop_done:; if (!__pyx_t_9) break;
+0263: a, b = b, a%b
__pyx_t_10 = __pyx_v_b; __Pyx_INCREF(__pyx_t_10); __pyx_t_7 = PyNumber_Remainder(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_7); __pyx_t_7 = 0; }
+0264: if not b:
__pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_b); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 264, __pyx_L1_error) __pyx_t_11 = (!__pyx_t_9); if (__pyx_t_11) { /* … */ }
+0265: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_a); __pyx_r = __pyx_v_a; goto __pyx_L0;
+0266: return _py_gcd(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_6 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error) __pyx_t_12 = __Pyx_PyInt_As_unsigned_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_12 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 266, __pyx_L1_error) __pyx_t_7 = __pyx_f_10quicktions__py_gcd(__pyx_t_6, __pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 266, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
0267:
0268:
0269: # Constants related to the hash implementation; hash(x) is based
0270: # on the reduction of x modulo the prime _PyHASH_MODULUS.
0271:
0272: cdef Py_hash_t _PyHASH_MODULUS
+0273: try:
{ /*try:*/ { /* … */ } __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L13_try_end; __pyx_L8_error:; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_L10_except_error:; __Pyx_XGIVEREF(__pyx_t_6); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_1); __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_5, __pyx_t_1); goto __pyx_L1_error; __pyx_L9_exception_handled:; __Pyx_XGIVEREF(__pyx_t_6); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_1); __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_5, __pyx_t_1); __pyx_L13_try_end:; }
+0274: _PyHASH_MODULUS = sys.hash_info.modulus
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_sys, __pyx_n_s_hash_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 274, __pyx_L8_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_modulus); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 274, __pyx_L8_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8 = __Pyx_PyInt_AsHash_t(__pyx_t_3); if (unlikely((__pyx_t_8 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 274, __pyx_L8_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_10quicktions__PyHASH_MODULUS = __pyx_t_8;
+0275: except AttributeError: # pre Py3.2
__pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); if (__pyx_t_7) { __Pyx_AddTraceback("quicktions", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_3, &__pyx_t_2, &__pyx_t_9) < 0) __PYX_ERR(0, 275, __pyx_L10_except_error) __Pyx_XGOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_9);
0276: # adapted from pyhash.h in Py3.4
+0277: _PyHASH_MODULUS = (<Py_hash_t>1) << (61 if sizeof(Py_hash_t) >= 8 else 31) - 1
__pyx_t_4 = ((sizeof(Py_hash_t)) >= 8); if (__pyx_t_4) { __pyx_t_10 = 61; } else { __pyx_t_10 = 31; } __pyx_v_10quicktions__PyHASH_MODULUS = (((Py_hash_t)1) << (__pyx_t_10 - 1)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L9_exception_handled; } goto __pyx_L10_except_error;
0278:
0279:
0280: # Value to be used for rationals that reduce to infinity modulo
0281: # _PyHASH_MODULUS.
0282: cdef Py_hash_t _PyHASH_INF
+0283: try:
{ /*try:*/ { /* … */ } __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L21_try_end; __pyx_L16_error:; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_L18_except_error:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_5, __pyx_t_6); goto __pyx_L1_error; __pyx_L17_exception_handled:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_5); __Pyx_XGIVEREF(__pyx_t_6); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_5, __pyx_t_6); __pyx_L21_try_end:; }
+0284: _PyHASH_INF = sys.hash_info.inf
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_sys, __pyx_n_s_hash_info); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 284, __pyx_L16_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_inf); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 284, __pyx_L16_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_8 = __Pyx_PyInt_AsHash_t(__pyx_t_2); if (unlikely((__pyx_t_8 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 284, __pyx_L16_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_10quicktions__PyHASH_INF = __pyx_t_8;
+0285: except AttributeError: # pre Py3.2
__pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); if (__pyx_t_7) { __Pyx_AddTraceback("quicktions", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_2, &__pyx_t_9, &__pyx_t_3) < 0) __PYX_ERR(0, 285, __pyx_L18_except_error) __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_3);
+0286: _PyHASH_INF = hash(float('+inf'))
__pyx_t_11 = __Pyx_PyString_AsDouble(__pyx_kp_s_inf_2); if (unlikely(__pyx_t_11 == ((double)((double)-1)) && PyErr_Occurred())) __PYX_ERR(0, 286, __pyx_L18_except_error) __pyx_t_12 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 286, __pyx_L18_except_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_8 = PyObject_Hash(__pyx_t_12); if (unlikely(__pyx_t_8 == ((Py_hash_t)-1))) __PYX_ERR(0, 286, __pyx_L18_except_error) __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_v_10quicktions__PyHASH_INF = __pyx_t_8; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L17_exception_handled; } goto __pyx_L18_except_error;
0287:
0288:
0289: # Helpers for formatting
0290:
+0291: cdef _round_to_exponent(n, d, exponent, bint no_neg_zero=False):
static PyObject *__pyx_f_10quicktions__round_to_exponent(PyObject *__pyx_v_n, PyObject *__pyx_v_d, PyObject *__pyx_v_exponent, struct __pyx_opt_args_10quicktions__round_to_exponent *__pyx_optional_args) { int __pyx_v_no_neg_zero = ((int)0); PyObject *__pyx_v_q = NULL; PyObject *__pyx_v_r = NULL; int __pyx_v_sign; PyObject *__pyx_r = NULL; if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_no_neg_zero = __pyx_optional_args->no_neg_zero; } } __Pyx_INCREF(__pyx_v_n); __Pyx_INCREF(__pyx_v_d); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions._round_to_exponent", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_q); __Pyx_XDECREF(__pyx_v_r); __Pyx_XDECREF(__pyx_v_n); __Pyx_XDECREF(__pyx_v_d); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ struct __pyx_opt_args_10quicktions__round_to_exponent { int __pyx_n; int no_neg_zero; };
0292: """Round a rational number to the nearest multiple of a given power of 10.
0293:
0294: Rounds the rational number n/d to the nearest integer multiple of
0295: 10**exponent, rounding to the nearest even integer multiple in the case of
0296: a tie. Returns a pair (sign: bool, significand: int) representing the
0297: rounded value (-1)**sign * significand * 10**exponent.
0298:
0299: If no_neg_zero is true, then the returned sign will always be False when
0300: the significand is zero. Otherwise, the sign reflects the sign of the
0301: input.
0302:
0303: d must be positive, but n and d need not be relatively prime.
0304: """
+0305: if exponent >= 0:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_exponent, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 305, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 305, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0306: d *= 10**exponent
__pyx_t_1 = PyNumber_Power(__pyx_int_10, __pyx_v_exponent, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_v_d, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_d, __pyx_t_3); __pyx_t_3 = 0;
0307: else:
+0308: n *= 10**-exponent
/*else*/ { __pyx_t_3 = PyNumber_Negative(__pyx_v_exponent); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyNumber_Power(__pyx_int_10, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_v_n, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_3); __pyx_t_3 = 0; } __pyx_L3:;
0309:
0310: # The divmod quotient is correct for round-ties-towards-positive-infinity;
0311: # In the case of a tie, we zero out the least significant bit of q.
+0312: q, r = divmod(n + (d >> 1), d)
__pyx_t_3 = __Pyx_PyInt_RshiftObjC(__pyx_v_d, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyNumber_Add(__pyx_v_n, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Divmod(__pyx_t_1, __pyx_v_d); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 312, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_1 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_1 = PyList_GET_ITEM(sequence, 0); __pyx_t_4 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_4); #else __pyx_t_1 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_1 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_1)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); index = 1; __pyx_t_4 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 312, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L5_unpacking_done; __pyx_L4_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 312, __pyx_L1_error) __pyx_L5_unpacking_done:; } __pyx_v_q = __pyx_t_1; __pyx_t_1 = 0; __pyx_v_r = __pyx_t_4; __pyx_t_4 = 0;
+0313: if r == 0 and d & 1 == 0:
__pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_r, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 313, __pyx_L1_error) if (__pyx_t_7) { } else { __pyx_t_2 = __pyx_t_7; goto __pyx_L7_bool_binop_done; } __pyx_t_3 = __Pyx_PyInt_AndObjC(__pyx_v_d, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 313, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_3, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 313, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_7; __pyx_L7_bool_binop_done:; if (__pyx_t_2) { /* … */ }
+0314: q &= -2
__pyx_t_3 = __Pyx_PyInt_AndObjC(__pyx_v_q, __pyx_int_neg_2, -2L, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 314, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_q, __pyx_t_3); __pyx_t_3 = 0;
0315:
+0316: cdef bint sign = q < 0 if no_neg_zero else n < 0
if (__pyx_v_no_neg_zero) { __pyx_t_3 = PyObject_RichCompare(__pyx_v_q, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 316, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_7; } else { __pyx_t_3 = PyObject_RichCompare(__pyx_v_n, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 316, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 316, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_7; } __pyx_v_sign = __pyx_t_2;
+0317: return sign, abs(q)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_sign); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_v_q); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4)) __PYX_ERR(0, 317, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0318:
0319:
+0320: cdef _round_to_figures(n, d, Py_ssize_t figures):
static PyObject *__pyx_f_10quicktions__round_to_figures(PyObject *__pyx_v_n, PyObject *__pyx_v_d, Py_ssize_t __pyx_v_figures) { int __pyx_v_sign; PyObject *__pyx_v_str_n = NULL; PyObject *__pyx_v_str_d = NULL; Py_ssize_t __pyx_v_m; PyObject *__pyx_v_exponent = NULL; PyObject *__pyx_v_significand = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("quicktions._round_to_figures", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_str_n); __Pyx_XDECREF(__pyx_v_str_d); __Pyx_XDECREF(__pyx_v_exponent); __Pyx_XDECREF(__pyx_v_significand); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0321: """Round a rational number to a given number of significant figures.
0322:
0323: Rounds the rational number n/d to the given number of significant figures
0324: using the round-ties-to-even rule, and returns a triple
0325: (sign: bool, significand: int, exponent: int) representing the rounded
0326: value (-1)**sign * significand * 10**exponent.
0327:
0328: In the special case where n = 0, returns a significand of zero and
0329: an exponent of 1 - figures, for compatibility with formatting.
0330: Otherwise, the returned significand satisfies
0331: 10**(figures - 1) <= significand < 10**figures.
0332:
0333: d must be positive, but n and d need not be relatively prime.
0334: figures must be positive.
0335: """
0336: # Special case for n == 0.
+0337: if n == 0:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_n, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 337, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0338: return False, 0, 1 - figures
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyInt_FromSsize_t((1 - __pyx_v_figures)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 338, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(Py_False); __Pyx_GIVEREF(Py_False); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, Py_False)) __PYX_ERR(0, 338, __pyx_L1_error); __Pyx_INCREF(__pyx_int_0); __Pyx_GIVEREF(__pyx_int_0); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_int_0)) __PYX_ERR(0, 338, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2)) __PYX_ERR(0, 338, __pyx_L1_error); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0339:
0340: cdef bint sign
0341:
0342: # Find integer m satisfying 10**(m - 1) <= abs(n)/d <= 10**m. (If abs(n)/d
0343: # is a power of 10, either of the two possible values for m is fine.)
+0344: str_n, str_d = str(abs(n)), str(d)
__pyx_t_3 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_Str(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 344, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_Str(__pyx_v_d); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 344, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_str_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_str_d = __pyx_t_3; __pyx_t_3 = 0;
+0345: cdef Py_ssize_t m = len(str_n) - len(str_d) + (str_d <= str_n)
__pyx_t_4 = PyObject_Length(__pyx_v_str_n); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 345, __pyx_L1_error) __pyx_t_5 = PyObject_Length(__pyx_v_str_d); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 345, __pyx_L1_error) __pyx_t_3 = PyInt_FromSsize_t((__pyx_t_4 - __pyx_t_5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyObject_RichCompare(__pyx_v_str_d, __pyx_v_str_n, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 345, __pyx_L1_error) __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_6); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 345, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_m = __pyx_t_5;
0346:
0347: # Round to a multiple of 10**(m - figures). The significand we get
0348: # satisfies 10**(figures - 1) <= significand <= 10**figures.
+0349: exponent = m - figures
__pyx_t_6 = PyInt_FromSsize_t((__pyx_v_m - __pyx_v_figures)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 349, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_v_exponent = __pyx_t_6; __pyx_t_6 = 0;
+0350: sign, significand = _round_to_exponent(n, d, exponent)
__pyx_t_6 = __pyx_f_10quicktions__round_to_exponent(__pyx_v_n, __pyx_v_d, __pyx_v_exponent, NULL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if ((likely(PyTuple_CheckExact(__pyx_t_6))) || (PyList_CheckExact(__pyx_t_6))) { PyObject* sequence = __pyx_t_6; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 350, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_2 = PyList_GET_ITEM(sequence, 0); __pyx_t_3 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); index = 0; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 350, __pyx_L1_error) __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L5_unpacking_done; __pyx_L4_unpacking_failed:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_8 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 350, __pyx_L1_error) __pyx_L5_unpacking_done:; } __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 350, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_sign = __pyx_t_1; __pyx_v_significand = __pyx_t_3; __pyx_t_3 = 0;
0351:
0352: # Adjust in the case where significand == 10**figures, to ensure that
0353: # 10**(figures - 1) <= significand < 10**figures.
+0354: if len(str(significand)) == figures + 1:
__pyx_t_6 = __Pyx_PyObject_Str(__pyx_v_significand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = PyObject_Length(__pyx_t_6); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 354, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_1 = (__pyx_t_5 == (__pyx_v_figures + 1)); if (__pyx_t_1) { /* … */ }
+0355: significand //= 10
__pyx_t_6 = __Pyx_PyInt_FloorDivideObjC(__pyx_v_significand, __pyx_int_10, 10, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 355, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_significand, __pyx_t_6); __pyx_t_6 = 0;
+0356: exponent += 1
__pyx_t_6 = __Pyx_PyInt_AddObjC(__pyx_v_exponent, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_exponent, __pyx_t_6); __pyx_t_6 = 0;
0357:
+0358: return sign, significand, exponent
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = __Pyx_PyBool_FromLong(__pyx_v_sign); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_6); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_6)) __PYX_ERR(0, 358, __pyx_L1_error); __Pyx_INCREF(__pyx_v_significand); __Pyx_GIVEREF(__pyx_v_significand); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_significand)) __PYX_ERR(0, 358, __pyx_L1_error); __Pyx_INCREF(__pyx_v_exponent); __Pyx_GIVEREF(__pyx_v_exponent); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_exponent)) __PYX_ERR(0, 358, __pyx_L1_error); __pyx_t_6 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0359:
0360:
0361: # Pattern for matching non-float-style format specifications.
+0362: cdef object _GENERAL_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_n_s_compile); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* … */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_kp_s_P_fill_P_align_P_sign_Alt_flag); __Pyx_GIVEREF(__pyx_kp_s_P_fill_P_align_P_sign_Alt_flag); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_s_P_fill_P_align_P_sign_Alt_flag)) __PYX_ERR(0, 362, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_12); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_12)) __PYX_ERR(0, 362, __pyx_L1_error); __pyx_t_12 = 0; __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0363: (?:
0364: (?P<fill>.)?
0365: (?P<align>[<>=^])
0366: )?
0367: (?P<sign>[-+ ]?)
0368: # Alt flag forces a slash and denominator in the output, even for
0369: # integer-valued Fraction objects.
0370: (?P<alt>\#)?
0371: # We don't implement the zeropad flag since there's no single obvious way
0372: # to interpret it.
0373: (?P<minimumwidth>0|[1-9][0-9]*)?
0374: (?P<thousands_sep>[,_])?
0375: $
+0376: """, re.DOTALL | re.VERBOSE).match
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_n_s_DOTALL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 376, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_n_s_VERBOSE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_12 = PyNumber_Or(__pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 376, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_match); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 376, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER); __Pyx_DECREF_SET(__pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
0377:
0378:
0379: # Pattern for matching float-style format specifications;
0380: # supports 'e', 'E', 'f', 'F', 'g', 'G' and '%' presentation types.
+0381: cdef object _FLOAT_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_n_s_compile); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_kp_s_P_fill_P_align_P_sign_P_no_neg); __Pyx_GIVEREF(__pyx_kp_s_P_fill_P_align_P_sign_P_no_neg); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_kp_s_P_fill_P_align_P_sign_P_no_neg)) __PYX_ERR(0, 381, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_9); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_9)) __PYX_ERR(0, 381, __pyx_L1_error); __pyx_t_9 = 0; __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0382: (?:
0383: (?P<fill>.)?
0384: (?P<align>[<>=^])
0385: )?
0386: (?P<sign>[-+ ]?)
0387: (?P<no_neg_zero>z)?
0388: (?P<alt>\#)?
0389: # A '0' that's *not* followed by another digit is parsed as a minimum width
0390: # rather than a zeropad flag.
0391: (?P<zeropad>0(?=[0-9]))?
0392: (?P<minimumwidth>0|[1-9][0-9]*)?
0393: (?P<thousands_sep>[,_])?
0394: (?:\.(?P<precision>0|[1-9][0-9]*))?
0395: (?P<presentation_type>[eEfFgG%])
0396: $
+0397: """, re.DOTALL | re.VERBOSE).match
__pyx_t_12 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_n_s_DOTALL); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_n_s_VERBOSE); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyNumber_Or(__pyx_t_12, __pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_match); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER); __Pyx_DECREF_SET(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
0398:
+0399: cdef object NOINIT = object()
__pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 399, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions_NOINIT); __Pyx_DECREF_SET(__pyx_v_10quicktions_NOINIT, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
0400:
0401:
+0402: cdef class Fraction:
struct __pyx_obj_10quicktions_Fraction { PyObject_HEAD struct __pyx_vtabstruct_10quicktions_Fraction *__pyx_vtab; PyObject *_numerator; PyObject *_denominator; Py_hash_t _hash; }; struct __pyx_vtabstruct_10quicktions_Fraction { PyObject *(*_format_general)(struct __pyx_obj_10quicktions_Fraction *, PyObject *); PyObject *(*_format_float_style)(struct __pyx_obj_10quicktions_Fraction *, PyObject *); PyObject *(*_eq)(struct __pyx_obj_10quicktions_Fraction *, PyObject *); PyObject *(*_richcmp)(struct __pyx_obj_10quicktions_Fraction *, PyObject *, int); }; static struct __pyx_vtabstruct_10quicktions_Fraction *__pyx_vtabptr_10quicktions_Fraction;
0403: """A Rational number.
0404:
0405: Takes a string like '3/2' or '1.5', another Rational instance, a
0406: numerator/denominator pair, or a float.
0407:
0408: Examples
0409: --------
0410:
0411: >>> Fraction(10, -8)
0412: Fraction(-5, 4)
0413: >>> Fraction(Fraction(1, 7), 5)
0414: Fraction(1, 35)
0415: >>> Fraction(Fraction(1, 7), Fraction(2, 3))
0416: Fraction(3, 14)
0417: >>> Fraction('314')
0418: Fraction(314, 1)
0419: >>> Fraction('-35/4')
0420: Fraction(-35, 4)
0421: >>> Fraction('3.1415') # conversion from numeric string
0422: Fraction(6283, 2000)
0423: >>> Fraction('-47e-2') # string may include a decimal exponent
0424: Fraction(-47, 100)
0425: >>> Fraction(1.47) # direct construction from float (exact conversion)
0426: Fraction(6620291452234629, 4503599627370496)
0427: >>> Fraction(2.25)
0428: Fraction(9, 4)
0429: >>> from decimal import Decimal
0430: >>> Fraction(Decimal('1.47'))
0431: Fraction(147, 100)
0432:
0433: """
0434: cdef _numerator
0435: cdef _denominator
0436: cdef Py_hash_t _hash
0437:
+0438: def __cinit__(self, numerator=0, denominator=None):
/* Python wrapper */ static int __pyx_pw_10quicktions_8Fraction_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static int __pyx_pw_10quicktions_8Fraction_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_numerator = 0; PyObject *__pyx_v_denominator = 0; CYTHON_UNUSED Py_ssize_t __pyx_nargs; CYTHON_UNUSED PyObject *const *__pyx_kwvalues; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1; #endif __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_numerator,&__pyx_n_s_denominator,0}; PyObject* values[2] = {0,0}; values[0] = __Pyx_Arg_NewRef_VARARGS(((PyObject *)__pyx_int_0)); values[1] = __Pyx_Arg_NewRef_VARARGS(((PyObject *)Py_None)); if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds); switch (__pyx_nargs) { case 0: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_numerator); if (value) { values[0] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L3_error) } CYTHON_FALLTHROUGH; case 1: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_denominator); if (value) { values[1] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 438, __pyx_L3_error) } } else { switch (__pyx_nargs) { case 2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1); CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_numerator = values[0]; __pyx_v_denominator = values[1]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__cinit__", 0, 0, 2, __pyx_nargs); __PYX_ERR(0, 438, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions.Fraction.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return -1; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction___cinit__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self), __pyx_v_numerator, __pyx_v_denominator); /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_10quicktions_8Fraction___cinit__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_numerator, PyObject *__pyx_v_denominator) { int __pyx_v__normalize; PyObject *__pyx_v_is_normalised = NULL; PyObject *__pyx_v_value = NULL; PyObject *__pyx_v_g = NULL; int __pyx_r; __Pyx_INCREF(__pyx_v_numerator); __Pyx_INCREF(__pyx_v_denominator); /* … */ /* function exit code */ __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("quicktions.Fraction.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_is_normalised); __Pyx_XDECREF(__pyx_v_value); __Pyx_XDECREF(__pyx_v_g); __Pyx_XDECREF(__pyx_v_numerator); __Pyx_XDECREF(__pyx_v_denominator); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+0439: self._hash = -1
__pyx_v_self->_hash = -1L;
+0440: if numerator is NOINIT:
__pyx_t_1 = (__pyx_v_numerator == __pyx_v_10quicktions_NOINIT); if (__pyx_t_1) { /* … */ }
+0441: return # fast-path for external initialisation
__pyx_r = 0; goto __pyx_L0;
0442:
+0443: cdef bint _normalize = True
__pyx_v__normalize = 1;
+0444: if denominator is None:
__pyx_t_1 = (__pyx_v_denominator == Py_None); if (__pyx_t_1) { /* … */ goto __pyx_L4; }
+0445: if type(numerator) is int or type(numerator) is long:
__pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyInt_Type))); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L6_bool_binop_done; } __pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyLong_Type))); __pyx_t_1 = __pyx_t_2; __pyx_L6_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0446: self._numerator = numerator
__Pyx_INCREF(__pyx_v_numerator); __Pyx_GIVEREF(__pyx_v_numerator); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_v_numerator;
+0447: self._denominator = 1
__Pyx_INCREF(__pyx_int_1); __Pyx_GIVEREF(__pyx_int_1); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_int_1;
+0448: return
__pyx_r = 0; goto __pyx_L0;
0449:
+0450: elif type(numerator) is float:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyFloat_Type))); if (__pyx_t_1) { /* … */ }
0451: # Exact conversion
+0452: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 452, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_4 = PyList_GET_ITEM(sequence, 0); __pyx_t_5 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); #else __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 452, __pyx_L1_error) __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L9_unpacking_done; __pyx_L8_unpacking_failed:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_8 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 452, __pyx_L1_error) __pyx_L9_unpacking_done:; } __Pyx_GIVEREF(__pyx_t_4); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_4; __pyx_t_4 = 0; __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_5; __pyx_t_5 = 0;
+0453: return
__pyx_r = 0; goto __pyx_L0;
0454:
+0455: elif type(numerator) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0456: self._numerator = (<Fraction>numerator)._numerator
__pyx_t_3 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_numerator; __Pyx_INCREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_3; __pyx_t_3 = 0;
+0457: self._denominator = (<Fraction>numerator)._denominator
__pyx_t_3 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_denominator; __Pyx_INCREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_3; __pyx_t_3 = 0;
+0458: return
__pyx_r = 0; goto __pyx_L0;
0459:
+0460: elif isinstance(numerator, unicode):
__pyx_t_1 = PyUnicode_Check(__pyx_v_numerator);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+0461: numerator, denominator, is_normalised = _parse_fraction(
__pyx_t_3 = __pyx_fuse_0__pyx_f_10quicktions__parse_fraction(((PyObject*)__pyx_v_numerator), __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (likely(__pyx_t_3 != Py_None)) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 461, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_7 = PyTuple_GET_ITEM(sequence, 2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_7); #else __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 461, __pyx_L1_error) } __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_4); __pyx_t_4 = 0; __pyx_v_is_normalised = __pyx_t_7; __pyx_t_7 = 0;
+0462: <unicode>numerator, len(<unicode>numerator))
if (unlikely(__pyx_v_numerator == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 462, __pyx_L1_error) } __pyx_t_9 = __Pyx_PyUnicode_GET_LENGTH(((PyObject*)__pyx_v_numerator)); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 462, __pyx_L1_error)
+0463: if is_normalised:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_is_normalised); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 463, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0464: _normalize = False
__pyx_v__normalize = 0;
0465: # fall through to normalisation below
0466:
+0467: elif PY_MAJOR_VERSION < 3 and isinstance(numerator, bytes):
__pyx_t_2 = (PY_MAJOR_VERSION < 3);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L11_bool_binop_done;
}
__pyx_t_2 = PyBytes_Check(__pyx_v_numerator);
__pyx_t_1 = __pyx_t_2;
__pyx_L11_bool_binop_done:;
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+0468: numerator, denominator, is_normalised = _parse_fraction(
__pyx_t_3 = __pyx_fuse_1__pyx_f_10quicktions__parse_fraction(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 468, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (likely(__pyx_t_3 != Py_None)) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 468, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_7 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); #else __pyx_t_7 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 468, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 468, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 468, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 468, __pyx_L1_error) } __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_4); __pyx_t_4 = 0; __pyx_v_is_normalised = __pyx_t_5; __pyx_t_5 = 0;
+0469: <bytes>numerator, len(<bytes>numerator))
if (unlikely(__pyx_v_numerator == Py_None)) { PyErr_SetString(PyExc_TypeError, "expected bytes, NoneType found"); __PYX_ERR(0, 469, __pyx_L1_error) } __pyx_t_10 = __Pyx_PyBytes_AsWritableString(__pyx_v_numerator); if (unlikely((!__pyx_t_10) && PyErr_Occurred())) __PYX_ERR(0, 469, __pyx_L1_error) if (unlikely(__pyx_v_numerator == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 469, __pyx_L1_error) } __pyx_t_9 = __Pyx_PyBytes_GET_SIZE(((PyObject*)__pyx_v_numerator)); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 469, __pyx_L1_error)
+0470: if is_normalised:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_is_normalised); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 470, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0471: _normalize = False
__pyx_v__normalize = 0;
0472: # fall through to normalisation below
0473:
+0474: elif isinstance(numerator, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_numerator);
if (__pyx_t_1) {
/* … */
}
0475: # Exact conversion
+0476: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_5))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 476, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_5 = PyList_GET_ITEM(sequence, 0); __pyx_t_4 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); #else __pyx_t_5 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 476, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); index = 0; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L14_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); index = 1; __pyx_t_4 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L14_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 476, __pyx_L1_error) __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L15_unpacking_done; __pyx_L14_unpacking_failed:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_8 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 476, __pyx_L1_error) __pyx_L15_unpacking_done:; } __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_5; __pyx_t_5 = 0; __Pyx_GIVEREF(__pyx_t_4); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_4; __pyx_t_4 = 0;
+0477: return
__pyx_r = 0; goto __pyx_L0;
0478:
+0479: elif isinstance(numerator, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_3 = __pyx_v_10quicktions_Rational; __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_numerator, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L16_bool_binop_done; } __pyx_t_2 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_3); __pyx_t_1 = __pyx_t_2; __pyx_L16_bool_binop_done:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+0480: self._numerator = numerator.numerator
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 480, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_3; __pyx_t_3 = 0;
+0481: self._denominator = numerator.denominator
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 481, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_3; __pyx_t_3 = 0;
+0482: return
__pyx_r = 0; goto __pyx_L0;
0483:
+0484: elif isinstance(numerator, Decimal):
__pyx_t_3 = __pyx_v_10quicktions_Decimal; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_3); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 484, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (likely(__pyx_t_1)) { /* … */ }
+0485: if _decimal_supports_integer_ratio:
if (__pyx_v_10quicktions__decimal_supports_integer_ratio) { /* … */ goto __pyx_L18; }
0486: # Exact conversion
+0487: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 487, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 487, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 487, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_4 = PyList_GET_ITEM(sequence, 0); __pyx_t_5 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); #else __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 487, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 487, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 487, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_8 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); index = 0; __pyx_t_4 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L19_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_5 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_5)) goto __pyx_L19_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 487, __pyx_L1_error) __pyx_t_8 = NULL; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; goto __pyx_L20_unpacking_done; __pyx_L19_unpacking_failed:; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_8 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 487, __pyx_L1_error) __pyx_L20_unpacking_done:; } __Pyx_GIVEREF(__pyx_t_4); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_4; __pyx_t_4 = 0; __Pyx_GIVEREF(__pyx_t_5); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_5; __pyx_t_5 = 0;
0488: else:
+0489: value = Fraction.from_decimal(numerator)
/*else*/ { __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_10quicktions_Fraction), __pyx_n_s_from_decimal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 489, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_5))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_numerator}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 489, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_v_value = __pyx_t_3; __pyx_t_3 = 0;
+0490: self._numerator = (<Fraction>value)._numerator
__pyx_t_3 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_value)->_numerator; __Pyx_INCREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_3; __pyx_t_3 = 0;
+0491: self._denominator = (<Fraction>value)._denominator
__pyx_t_3 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_value)->_denominator; __Pyx_INCREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_3; __pyx_t_3 = 0; } __pyx_L18:;
+0492: return
__pyx_r = 0; goto __pyx_L0;
0493:
0494: else:
+0495: raise TypeError("argument should be a string "
/*else*/ { __pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 495, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(0, 495, __pyx_L1_error) } __pyx_L5:; /* … */ __pyx_tuple_ = PyTuple_Pack(1, __pyx_kp_s_argument_should_be_a_string_or_a); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 495, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_);
0496: "or a Rational instance")
0497:
+0498: elif type(numerator) is int is type(denominator):
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyInt_Type))); if (__pyx_t_1) { __pyx_t_1 = ((&PyInt_Type) == ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_denominator)))); } if (__pyx_t_1) { goto __pyx_L4; }
0499: pass # *very* normal case
0500:
+0501: elif PY_MAJOR_VERSION < 3 and type(numerator) is long is type(denominator):
__pyx_t_2 = (PY_MAJOR_VERSION < 3); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L21_bool_binop_done; } __pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyLong_Type))); if (__pyx_t_2) { __pyx_t_2 = ((&PyLong_Type) == ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_denominator)))); } __pyx_t_1 = __pyx_t_2; __pyx_L21_bool_binop_done:; if (__pyx_t_1) { goto __pyx_L4; }
0502: pass # *very* normal case
0503:
+0504: elif type(numerator) is Fraction is type(denominator):
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { __pyx_t_1 = (__pyx_ptype_10quicktions_Fraction == ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_denominator)))); } if (__pyx_t_1) { /* … */ goto __pyx_L4; }
0505: numerator, denominator = (
+0506: (<Fraction>numerator)._numerator * (<Fraction>denominator)._denominator,
__pyx_t_3 = PyNumber_Multiply(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_denominator)->_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 506, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+0507: (<Fraction>denominator)._numerator * (<Fraction>numerator)._denominator
__pyx_t_5 = PyNumber_Multiply(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_denominator)->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 507, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
0508: )
0509:
+0510: elif (isinstance(numerator, (Fraction, Rational)) and
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_5 = __pyx_v_10quicktions_Rational; __pyx_t_11 = __Pyx_TypeCheck(__pyx_v_numerator, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_11) { } else { __pyx_t_2 = __pyx_t_11; goto __pyx_L25_bool_binop_done; } __pyx_t_11 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_5); __pyx_t_2 = __pyx_t_11; __pyx_L25_bool_binop_done:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L23_bool_binop_done; } /* … */ if (likely(__pyx_t_1)) { /* … */ goto __pyx_L4; }
+0511: isinstance(denominator, (Fraction, Rational))):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_5 = __pyx_v_10quicktions_Rational; __pyx_t_11 = __Pyx_TypeCheck(__pyx_v_denominator, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_11) { } else { __pyx_t_2 = __pyx_t_11; goto __pyx_L27_bool_binop_done; } __pyx_t_11 = PyObject_IsInstance(__pyx_v_denominator, __pyx_t_5); __pyx_t_2 = __pyx_t_11; __pyx_L27_bool_binop_done:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L23_bool_binop_done:;
0512: numerator, denominator = (
+0513: numerator.numerator * denominator.denominator,
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_denominator, __pyx_n_s_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Multiply(__pyx_t_5, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+0514: denominator.numerator * numerator.denominator
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_denominator, __pyx_n_s_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 514, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 514, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_7 = PyNumber_Multiply(__pyx_t_3, __pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 514, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_7); __pyx_t_7 = 0;
0515: )
0516:
0517: else:
+0518: raise TypeError("both arguments should be "
/*else*/ { __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 518, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __PYX_ERR(0, 518, __pyx_L1_error) } __pyx_L4:; /* … */ __pyx_tuple__2 = PyTuple_Pack(1, __pyx_kp_s_both_arguments_should_be_Rationa); if (unlikely(!__pyx_tuple__2)) __PYX_ERR(0, 518, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2);
0519: "Rational instances")
0520:
+0521: if denominator == 0:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_denominator, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 521, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+0522: raise ZeroDivisionError(f'Fraction({numerator}, 0)')
__pyx_t_7 = PyTuple_New(3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = 0; __pyx_t_12 = 127; __Pyx_INCREF(__pyx_kp_u_Fraction); __pyx_t_9 += 9; __Pyx_GIVEREF(__pyx_kp_u_Fraction); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_kp_u_Fraction); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_numerator, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_12; __pyx_t_9 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_0); __pyx_t_9 += 4; __Pyx_GIVEREF(__pyx_kp_u_0); PyTuple_SET_ITEM(__pyx_t_7, 2, __pyx_kp_u_0); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_7, 3, __pyx_t_9, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ZeroDivisionError, __pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __PYX_ERR(0, 522, __pyx_L1_error)
+0523: if _normalize:
if (__pyx_v__normalize) { /* … */ }
+0524: if not isinstance(numerator, int):
__pyx_t_1 = PyInt_Check(__pyx_v_numerator);
__pyx_t_2 = (!__pyx_t_1);
if (__pyx_t_2) {
/* … */
}
+0525: numerator = int(numerator)
__pyx_t_7 = __Pyx_PyNumber_Int(__pyx_v_numerator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_7); __pyx_t_7 = 0;
+0526: if not isinstance(denominator, int):
__pyx_t_2 = PyInt_Check(__pyx_v_denominator);
__pyx_t_1 = (!__pyx_t_2);
if (__pyx_t_1) {
/* … */
}
+0527: denominator = int(denominator)
__pyx_t_7 = __Pyx_PyNumber_Int(__pyx_v_denominator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 527, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_7); __pyx_t_7 = 0;
+0528: g = _gcd(numerator, denominator)
__pyx_t_7 = __pyx_f_10quicktions__gcd(__pyx_v_numerator, __pyx_v_denominator, 0); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 528, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_v_g = __pyx_t_7; __pyx_t_7 = 0;
0529: # NOTE: 'is' tests on integers are generally a bad idea, but
0530: # they are fast and if they fail here, it'll still be correct
+0531: if denominator < 0:
__pyx_t_7 = PyObject_RichCompare(__pyx_v_denominator, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_7); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 531, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 531, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (__pyx_t_1) { /* … */ }
+0532: if g is 1:
__pyx_t_1 = (__pyx_v_g == __pyx_int_1); if (__pyx_t_1) { /* … */ goto __pyx_L34; }
+0533: numerator = -numerator
__pyx_t_7 = PyNumber_Negative(__pyx_v_numerator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_7); __pyx_t_7 = 0;
+0534: denominator = -denominator
__pyx_t_7 = PyNumber_Negative(__pyx_v_denominator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 534, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_7); __pyx_t_7 = 0;
0535: else:
+0536: g = -g
/*else*/ { __pyx_t_7 = PyNumber_Negative(__pyx_v_g); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 536, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_g, __pyx_t_7); __pyx_t_7 = 0; } __pyx_L34:;
+0537: if g is not 1:
__pyx_t_1 = (__pyx_v_g != __pyx_int_1); if (__pyx_t_1) { /* … */ }
+0538: numerator //= g
__pyx_t_7 = PyNumber_InPlaceFloorDivide(__pyx_v_numerator, __pyx_v_g); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 538, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_7); __pyx_t_7 = 0;
+0539: denominator //= g
__pyx_t_7 = PyNumber_InPlaceFloorDivide(__pyx_v_denominator, __pyx_v_g); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 539, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_7); __pyx_t_7 = 0;
+0540: self._numerator = numerator
__Pyx_INCREF(__pyx_v_numerator); __Pyx_GIVEREF(__pyx_v_numerator); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_v_numerator;
+0541: self._denominator = denominator
__Pyx_INCREF(__pyx_v_denominator); __Pyx_GIVEREF(__pyx_v_denominator); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_v_denominator;
0542:
+0543: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_3from_float(PyObject *__pyx_v_cls, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_2from_float, "Converts a finite float to a rational number, exactly.\n\n Beware that Fraction.from_float(0.3) != Fraction(3, 10).\n\n "); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_3from_float = {"from_float", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_3from_float, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_2from_float}; static PyObject *__pyx_pw_10quicktions_8Fraction_3from_float(PyObject *__pyx_v_cls, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_f = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("from_float (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_f,0}; PyObject* values[1] = {0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_f)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 543, __pyx_L3_error) else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "from_float") < 0)) __PYX_ERR(0, 543, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); } __pyx_v_f = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("from_float", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 543, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions.Fraction.from_float", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_2from_float(((PyTypeObject*)__pyx_v_cls), __pyx_v_f); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_2from_float(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_f) { PyObject *__pyx_v_ratio = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions.Fraction.from_float", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_ratio); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__22 = PyTuple_Pack(3, __pyx_n_s_cls, __pyx_n_s_f, __pyx_n_s_ratio); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__22); __Pyx_GIVEREF(__pyx_tuple__22); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_3from_float, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_from_float, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_float, __pyx_t_3) < 0) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __Pyx_GetNameInClass(__pyx_t_3, (PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_float); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = __Pyx_Method_ClassMethod(__pyx_t_3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_float, __pyx_t_9) < 0) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_from_float, 543, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 543, __pyx_L1_error)
0544: def from_float(cls, f):
0545: """Converts a finite float to a rational number, exactly.
0546:
0547: Beware that Fraction.from_float(0.3) != Fraction(3, 10).
0548:
0549: """
+0550: try:
{ /*try:*/ { /* … */ } /* … */ __pyx_L5_except_error:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L1_error; __pyx_L6_except_return:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); goto __pyx_L0; __pyx_L4_exception_handled:; __Pyx_XGIVEREF(__pyx_t_1); __Pyx_XGIVEREF(__pyx_t_2); __Pyx_XGIVEREF(__pyx_t_3); __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); }
+0551: ratio = f.as_integer_ratio()
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_f, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 551, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = NULL; __pyx_t_7 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_5))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_5, function); __pyx_t_7 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 551, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } __pyx_v_ratio = __pyx_t_4; __pyx_t_4 = 0;
+0552: except (ValueError, OverflowError, AttributeError):
__pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); if (__pyx_t_7) { __Pyx_ErrRestore(0,0,0); goto __pyx_L4_exception_handled; } goto __pyx_L5_except_error;
0553: pass # not something we can convert, raise concrete exceptions below
0554: else:
+0555: return cls(*ratio)
/*else:*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PySequence_Tuple(__pyx_v_ratio); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 555, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_v_cls), __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 555, __pyx_L5_except_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L6_except_return; } __pyx_L3_error:; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
0556:
+0557: if isinstance(f, Integral):
__pyx_t_5 = __pyx_v_10quicktions_Integral; __Pyx_INCREF(__pyx_t_5); __pyx_t_8 = PyObject_IsInstance(__pyx_v_f, __pyx_t_5); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 557, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_8) { /* … */ }
+0558: return cls(f)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_v_cls), __pyx_v_f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+0559: elif not isinstance(f, float):
__pyx_t_8 = PyFloat_Check(__pyx_v_f);
__pyx_t_9 = (!__pyx_t_8);
if (unlikely(__pyx_t_9)) {
/* … */
}
+0560: raise TypeError(f"{cls.__name__}.from_float() only takes floats, not {f!r} ({type(f).__name__})")
__pyx_t_5 = PyTuple_New(6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_10 = 0; __pyx_t_11 = 127; __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_kp_u_from_float_only_takes_floats_no); __pyx_t_10 += 37; __Pyx_GIVEREF(__pyx_kp_u_from_float_only_takes_floats_no); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_kp_u_from_float_only_takes_floats_no); __pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_kp_u__3); __pyx_t_10 += 2; __Pyx_GIVEREF(__pyx_kp_u__3); PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_kp_u__3); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_f)), __pyx_n_s_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u__4); __pyx_t_10 += 1; __Pyx_GIVEREF(__pyx_kp_u__4); PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_kp_u__4); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_5, 6, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 560, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 560, __pyx_L1_error)
+0561: if math.isinf(f):
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_n_s_isinf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 561, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = NULL; __pyx_t_7 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_7 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_f}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 561, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 561, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_t_9)) { /* … */ }
+0562: raise OverflowError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_10 = 0; __pyx_t_11 = 127; __Pyx_INCREF(__pyx_kp_u_Cannot_convert); __pyx_t_10 += 15; __Pyx_GIVEREF(__pyx_kp_u_Cannot_convert); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_Cannot_convert); __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_to); __pyx_t_10 += 4; __Pyx_GIVEREF(__pyx_kp_u_to); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_to); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_kp_u__5); __pyx_t_10 += 1; __Pyx_GIVEREF(__pyx_kp_u__5); PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u__5); __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OverflowError, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 562, __pyx_L1_error)
+0563: raise ValueError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_10 = 0; __pyx_t_11 = 127; __Pyx_INCREF(__pyx_kp_u_Cannot_convert); __pyx_t_10 += 15; __Pyx_GIVEREF(__pyx_kp_u_Cannot_convert); PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_Cannot_convert); __pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_6); __pyx_t_6 = 0; __Pyx_INCREF(__pyx_kp_u_to); __pyx_t_10 += 4; __Pyx_GIVEREF(__pyx_kp_u_to); PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_to); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_11; __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u__5); __pyx_t_10 += 1; __Pyx_GIVEREF(__pyx_kp_u__5); PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u__5); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 563, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 563, __pyx_L1_error)
0564:
+0565: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_5from_decimal(PyObject *__pyx_v_cls, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_4from_decimal, "Converts a finite Decimal instance to a rational number, exactly."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_5from_decimal = {"from_decimal", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_5from_decimal, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_4from_decimal}; static PyObject *__pyx_pw_10quicktions_8Fraction_5from_decimal(PyObject *__pyx_v_cls, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_dec = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("from_decimal (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_dec,0}; PyObject* values[1] = {0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_dec)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 565, __pyx_L3_error) else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "from_decimal") < 0)) __PYX_ERR(0, 565, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); } __pyx_v_dec = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("from_decimal", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 565, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions.Fraction.from_decimal", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_4from_decimal(((PyTypeObject*)__pyx_v_cls), __pyx_v_dec); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_4from_decimal(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_dec) { Py_ssize_t __pyx_v_exp; PyObject *__pyx_v_num = NULL; PyObject *__pyx_v_denom = NULL; PyObject *__pyx_v_sign = NULL; PyObject *__pyx_v_digits = NULL; PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_dec); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_12); __Pyx_AddTraceback("quicktions.Fraction.from_decimal", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_num); __Pyx_XDECREF(__pyx_v_denom); __Pyx_XDECREF(__pyx_v_sign); __Pyx_XDECREF(__pyx_v_digits); __Pyx_XDECREF(__pyx_v_dec); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__24 = PyTuple_Pack(7, __pyx_n_s_cls, __pyx_n_s_dec, __pyx_n_s_exp, __pyx_n_s_num, __pyx_n_s_denom, __pyx_n_s_sign, __pyx_n_s_digits); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__24); __Pyx_GIVEREF(__pyx_tuple__24); /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_5from_decimal, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_from_decimal, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_decimal, __pyx_t_9) < 0) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __Pyx_GetNameInClass(__pyx_t_9, (PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_decimal); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_decimal, __pyx_t_3) < 0) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__25 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__24, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_from_decimal, 565, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 565, __pyx_L1_error)
0566: def from_decimal(cls, dec):
0567: """Converts a finite Decimal instance to a rational number, exactly."""
0568: cdef Py_ssize_t exp
+0569: if isinstance(dec, Integral):
__pyx_t_1 = __pyx_v_10quicktions_Integral; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyObject_IsInstance(__pyx_v_dec, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 569, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0570: dec = Decimal(int(dec))
__pyx_t_3 = __Pyx_PyNumber_Int(__pyx_v_dec); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 570, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_10quicktions_Decimal); __pyx_t_4 = __pyx_v_10quicktions_Decimal; __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_3}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 570, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __Pyx_DECREF_SET(__pyx_v_dec, __pyx_t_1); __pyx_t_1 = 0;
+0571: elif not isinstance(dec, Decimal):
__pyx_t_1 = __pyx_v_10quicktions_Decimal; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = PyObject_IsInstance(__pyx_v_dec, __pyx_t_1); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 571, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_7 = (!__pyx_t_2); if (unlikely(__pyx_t_7)) { /* … */ } __pyx_L3:;
+0572: raise TypeError(
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 572, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 572, __pyx_L1_error)
+0573: f"{cls.__name__}.from_decimal() only takes Decimals, not {dec!r} ({type(dec).__name__})")
__pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = 0; __pyx_t_9 = 127; __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3); __pyx_t_3 = 0; __Pyx_INCREF(__pyx_kp_u_from_decimal_only_takes_Decimal); __pyx_t_8 += 41; __Pyx_GIVEREF(__pyx_kp_u_from_decimal_only_takes_Decimal); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_kp_u_from_decimal_only_takes_Decimal); __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_dec), __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_t_3); __pyx_t_3 = 0; __Pyx_INCREF(__pyx_kp_u__3); __pyx_t_8 += 2; __Pyx_GIVEREF(__pyx_kp_u__3); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__3); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_dec)), __pyx_n_s_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_3, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u__4); __pyx_t_8 += 1; __Pyx_GIVEREF(__pyx_kp_u__4); PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_kp_u__4); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 6, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+0574: if dec.is_infinite():
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_dec, __pyx_n_s_is_infinite); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 574, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 574, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 574, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0575: raise OverflowError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = 0; __pyx_t_9 = 127; __Pyx_INCREF(__pyx_kp_u_Cannot_convert); __pyx_t_8 += 15; __Pyx_GIVEREF(__pyx_kp_u_Cannot_convert); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Cannot_convert); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_dec, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u_to); __pyx_t_8 += 4; __Pyx_GIVEREF(__pyx_kp_u_to); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_to); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_3); __pyx_t_3 = 0; __Pyx_INCREF(__pyx_kp_u__5); __pyx_t_8 += 1; __Pyx_GIVEREF(__pyx_kp_u__5); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__5); __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OverflowError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 575, __pyx_L1_error)
+0576: if dec.is_nan():
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dec, __pyx_n_s_is_nan); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0577: raise ValueError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = 0; __pyx_t_9 = 127; __Pyx_INCREF(__pyx_kp_u_Cannot_convert); __pyx_t_8 += 15; __Pyx_GIVEREF(__pyx_kp_u_Cannot_convert); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_Cannot_convert); __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_dec, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3); __pyx_t_3 = 0; __Pyx_INCREF(__pyx_kp_u_to); __pyx_t_8 += 4; __Pyx_GIVEREF(__pyx_kp_u_to); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_to); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_n_s_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_3, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_9 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_9) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_9; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_4); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_kp_u__5); __pyx_t_8 += 1; __Pyx_GIVEREF(__pyx_kp_u__5); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__5); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 577, __pyx_L1_error)
0578:
+0579: if _decimal_supports_integer_ratio:
if (__pyx_v_10quicktions__decimal_supports_integer_ratio) { /* … */ }
+0580: num, denom = dec.as_integer_ratio()
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_dec, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 580, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_4 = PyList_GET_ITEM(sequence, 0); __pyx_t_3 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); #else __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_4 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_4)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_3 = __pyx_t_10(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L7_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_5), 2) < 0) __PYX_ERR(0, 580, __pyx_L1_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L8_unpacking_done; __pyx_L7_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_10 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 580, __pyx_L1_error) __pyx_L8_unpacking_done:; } __pyx_v_num = __pyx_t_4; __pyx_t_4 = 0; __pyx_v_denom = __pyx_t_3; __pyx_t_3 = 0;
+0581: return _fraction_from_coprime_ints(num, denom, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_11.__pyx_n = 1; __pyx_t_11.cls = ((PyObject *)__pyx_v_cls); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_num, __pyx_v_denom, &__pyx_t_11); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 581, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0582:
+0583: sign, digits, exp = dec.as_tuple()
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_dec, __pyx_n_s_as_tuple); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_1))) || (PyList_CheckExact(__pyx_t_1))) { PyObject* sequence = __pyx_t_1; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 583, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_5 = PyTuple_GET_ITEM(sequence, 2); } else { __pyx_t_3 = PyList_GET_ITEM(sequence, 0); __pyx_t_4 = PyList_GET_ITEM(sequence, 1); __pyx_t_5 = PyList_GET_ITEM(sequence, 2); } __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); #else __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { Py_ssize_t index = -1; __pyx_t_12 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_10 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_12); index = 0; __pyx_t_3 = __pyx_t_10(__pyx_t_12); if (unlikely(!__pyx_t_3)) goto __pyx_L9_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_10(__pyx_t_12); if (unlikely(!__pyx_t_4)) goto __pyx_L9_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); index = 2; __pyx_t_5 = __pyx_t_10(__pyx_t_12); if (unlikely(!__pyx_t_5)) goto __pyx_L9_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_12), 3) < 0) __PYX_ERR(0, 583, __pyx_L1_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; goto __pyx_L10_unpacking_done; __pyx_L9_unpacking_failed:; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __pyx_t_10 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 583, __pyx_L1_error) __pyx_L10_unpacking_done:; } __pyx_t_8 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_8 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_sign = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_digits = __pyx_t_4; __pyx_t_4 = 0; __pyx_v_exp = __pyx_t_8;
+0584: digits = int(''.join(map(str, digits)))
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF((PyObject *)(&PyString_Type)); __Pyx_GIVEREF((PyObject *)(&PyString_Type)); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)(&PyString_Type)))) __PYX_ERR(0, 584, __pyx_L1_error); __Pyx_INCREF(__pyx_v_digits); __Pyx_GIVEREF(__pyx_v_digits); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_digits)) __PYX_ERR(0, 584, __pyx_L1_error); __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyString_Join(__pyx_kp_s__6, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_digits, __pyx_t_5); __pyx_t_5 = 0;
+0585: if sign:
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_sign); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 585, __pyx_L1_error) if (__pyx_t_7) { /* … */ }
+0586: digits = -digits
__pyx_t_5 = PyNumber_Negative(__pyx_v_digits); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_digits, __pyx_t_5); __pyx_t_5 = 0;
+0587: if exp >= 0:
__pyx_t_7 = (__pyx_v_exp >= 0); if (__pyx_t_7) { /* … */ }
+0588: return _fraction_from_coprime_ints(digits * pow10(exp), 1, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __pyx_f_10quicktions_pow10(__pyx_v_exp); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = PyNumber_Multiply(__pyx_v_digits, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_11.__pyx_n = 1; __pyx_t_11.cls = ((PyObject *)__pyx_v_cls); __pyx_t_5 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_1, __pyx_int_1, &__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0589: else:
+0590: return cls(digits, pow10(-exp))
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_5 = __pyx_f_10quicktions_pow10((-__pyx_v_exp)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_digits); __Pyx_GIVEREF(__pyx_v_digits); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_digits)) __PYX_ERR(0, 590, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_5); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_Call(((PyObject *)__pyx_v_cls), __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; }
0591:
+0592: def is_integer(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_7is_integer(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_6is_integer, "Return True if the Fraction is an integer."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_7is_integer = {"is_integer", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_7is_integer, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_6is_integer}; static PyObject *__pyx_pw_10quicktions_8Fraction_7is_integer(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("is_integer (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("is_integer", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "is_integer", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_6is_integer(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_6is_integer(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("quicktions.Fraction.is_integer", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__26 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__26)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__26); __Pyx_GIVEREF(__pyx_tuple__26); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_7is_integer, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_is_integer, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_is_integer, __pyx_t_3) < 0) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_is_integer, 592, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 592, __pyx_L1_error)
0593: """Return True if the Fraction is an integer."""
+0594: return self._denominator == 1
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_EqObjC(__pyx_v_self->_denominator, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0595:
+0596: def as_integer_ratio(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_9as_integer_ratio(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_8as_integer_ratio, "Return a pair of integers, whose ratio is equal to the original Fraction.\n\n The ratio is in lowest terms and has a positive denominator.\n "); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_9as_integer_ratio = {"as_integer_ratio", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_9as_integer_ratio, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_8as_integer_ratio}; static PyObject *__pyx_pw_10quicktions_8Fraction_9as_integer_ratio(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("as_integer_ratio (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("as_integer_ratio", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "as_integer_ratio", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_8as_integer_ratio(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_8as_integer_ratio(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("quicktions.Fraction.as_integer_ratio", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_9as_integer_ratio, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_as_integer_ratio, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__28)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_as_integer_ratio, __pyx_t_3) < 0) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__28 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_as_integer_ratio, 596, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__28)) __PYX_ERR(0, 596, __pyx_L1_error)
0597: """Return a pair of integers, whose ratio is equal to the original Fraction.
0598:
0599: The ratio is in lowest terms and has a positive denominator.
0600: """
+0601: return (self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_self->_numerator); __Pyx_GIVEREF(__pyx_v_self->_numerator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->_numerator)) __PYX_ERR(0, 601, __pyx_L1_error); __Pyx_INCREF(__pyx_v_self->_denominator); __Pyx_GIVEREF(__pyx_v_self->_denominator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->_denominator)) __PYX_ERR(0, 601, __pyx_L1_error); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0602:
+0603: def limit_denominator(self, max_denominator=1000000):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_11limit_denominator(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_10limit_denominator, "Closest Fraction to self with denominator at most max_denominator.\n\n >>> Fraction('3.141592653589793').limit_denominator(10)\n Fraction(22, 7)\n >>> Fraction('3.141592653589793').limit_denominator(100)\n Fraction(311, 99)\n >>> Fraction(4321, 8765).limit_denominator(10000)\n Fraction(4321, 8765)\n\n "); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_11limit_denominator = {"limit_denominator", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_11limit_denominator, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_10limit_denominator}; static PyObject *__pyx_pw_10quicktions_8Fraction_11limit_denominator(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_max_denominator = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("limit_denominator (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_max_denominator,0}; PyObject* values[1] = {0}; values[0] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)__pyx_int_1000000)); if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_max_denominator); if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 603, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "limit_denominator") < 0)) __PYX_ERR(0, 603, __pyx_L3_error) } } else { switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_max_denominator = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("limit_denominator", 0, 0, 1, __pyx_nargs); __PYX_ERR(0, 603, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions.Fraction.limit_denominator", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_10limit_denominator(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self), __pyx_v_max_denominator); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_10limit_denominator(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_max_denominator) { PyObject *__pyx_v_p0 = NULL; PyObject *__pyx_v_q0 = NULL; PyObject *__pyx_v_p1 = NULL; PyObject *__pyx_v_q1 = NULL; PyObject *__pyx_v_n = NULL; PyObject *__pyx_v_d = NULL; PyObject *__pyx_v_a = NULL; PyObject *__pyx_v_q2 = NULL; PyObject *__pyx_v_k = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction.limit_denominator", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_p0); __Pyx_XDECREF(__pyx_v_q0); __Pyx_XDECREF(__pyx_v_p1); __Pyx_XDECREF(__pyx_v_q1); __Pyx_XDECREF(__pyx_v_n); __Pyx_XDECREF(__pyx_v_d); __Pyx_XDECREF(__pyx_v_a); __Pyx_XDECREF(__pyx_v_q2); __Pyx_XDECREF(__pyx_v_k); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__29 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_max_denominator, __pyx_n_s_p0, __pyx_n_s_q0, __pyx_n_s_p1, __pyx_n_s_q1, __pyx_n_s_n, __pyx_n_s_d, __pyx_n_s_a, __pyx_n_s_q2, __pyx_n_s_k); if (unlikely(!__pyx_tuple__29)) __PYX_ERR(0, 603, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__29); __Pyx_GIVEREF(__pyx_tuple__29); __pyx_codeobj__30 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__29, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_limit_denominator, 603, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__30)) __PYX_ERR(0, 603, __pyx_L1_error) /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_11limit_denominator, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_limit_denominator, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__30)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 603, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__31); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_limit_denominator, __pyx_t_3) < 0) __PYX_ERR(0, 603, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_tuple__31 = PyTuple_Pack(1, __pyx_int_1000000); if (unlikely(!__pyx_tuple__31)) __PYX_ERR(0, 603, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__31); __Pyx_GIVEREF(__pyx_tuple__31);
0604: """Closest Fraction to self with denominator at most max_denominator.
0605:
0606: >>> Fraction('3.141592653589793').limit_denominator(10)
0607: Fraction(22, 7)
0608: >>> Fraction('3.141592653589793').limit_denominator(100)
0609: Fraction(311, 99)
0610: >>> Fraction(4321, 8765).limit_denominator(10000)
0611: Fraction(4321, 8765)
0612:
0613: """
0614: # Algorithm notes: For any real number x, define a *best upper
0615: # approximation* to x to be a rational number p/q such that:
0616: #
0617: # (1) p/q >= x, and
0618: # (2) if p/q > r/s >= x then s > q, for any rational r/s.
0619: #
0620: # Define *best lower approximation* similarly. Then it can be
0621: # proved that a rational number is a best upper or lower
0622: # approximation to x if, and only if, it is a convergent or
0623: # semiconvergent of the (unique shortest) continued fraction
0624: # associated to x.
0625: #
0626: # To find a best rational approximation with denominator <= M,
0627: # we find the best upper and lower approximations with
0628: # denominator <= M and take whichever of these is closer to x.
0629: # In the event of a tie, the bound with smaller denominator is
0630: # chosen. If both denominators are equal (which can happen
0631: # only when max_denominator == 1 and self is midway between
0632: # two integers) the lower bound---i.e., the floor of self, is
0633: # taken.
0634:
+0635: if max_denominator < 1:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_max_denominator, __pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 635, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_2)) { /* … */ }
+0636: raise ValueError("max_denominator should be at least 1")
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__7, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 636, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 636, __pyx_L1_error) /* … */ __pyx_tuple__7 = PyTuple_Pack(1, __pyx_kp_s_max_denominator_should_be_at_lea); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 636, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__7); __Pyx_GIVEREF(__pyx_tuple__7);
+0637: if self._denominator <= max_denominator:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_self->_denominator, __pyx_v_max_denominator, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 637, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 637, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0638: return Fraction(self)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_10quicktions_Fraction), ((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 638, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0639:
+0640: p0, q0, p1, q1 = 0, 1, 1, 0
__pyx_t_1 = __pyx_int_0; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_int_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = __pyx_int_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = __pyx_int_0; __Pyx_INCREF(__pyx_t_5); __pyx_v_p0 = __pyx_t_1; __pyx_t_1 = 0; __pyx_v_q0 = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_p1 = __pyx_t_4; __pyx_t_4 = 0; __pyx_v_q1 = __pyx_t_5; __pyx_t_5 = 0;
+0641: n, d = self._numerator, self._denominator
__pyx_t_5 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_4); __pyx_v_n = __pyx_t_5; __pyx_t_5 = 0; __pyx_v_d = __pyx_t_4; __pyx_t_4 = 0;
+0642: while True:
while (1) {
+0643: a = n//d
__pyx_t_4 = PyNumber_FloorDivide(__pyx_v_n, __pyx_v_d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 643, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_4); __pyx_t_4 = 0;
+0644: q2 = q0+a*q1
__pyx_t_4 = PyNumber_Multiply(__pyx_v_a, __pyx_v_q1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 644, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Add(__pyx_v_q0, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 644, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF_SET(__pyx_v_q2, __pyx_t_5); __pyx_t_5 = 0;
+0645: if q2 > max_denominator:
__pyx_t_5 = PyObject_RichCompare(__pyx_v_q2, __pyx_v_max_denominator, Py_GT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 645, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 645, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_2) { /* … */ }
+0646: break
goto __pyx_L6_break;
+0647: p0, q0, p1, q1 = p1, q1, p0+a*p1, q2
__pyx_t_5 = __pyx_v_p1; __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = __pyx_v_q1; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = PyNumber_Multiply(__pyx_v_a, __pyx_v_p1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyNumber_Add(__pyx_v_p0, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __pyx_v_q2; __Pyx_INCREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_p0, __pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_q0, __pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_p1, __pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_q1, __pyx_t_3); __pyx_t_3 = 0;
+0648: n, d = d, n-a*d
__pyx_t_3 = __pyx_v_d; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = PyNumber_Multiply(__pyx_v_a, __pyx_v_d); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 648, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyNumber_Subtract(__pyx_v_n, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 648, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_d, __pyx_t_4); __pyx_t_4 = 0; } __pyx_L6_break:;
0649:
+0650: k = (max_denominator-q0)//q1
__pyx_t_4 = PyNumber_Subtract(__pyx_v_max_denominator, __pyx_v_q0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_FloorDivide(__pyx_t_4, __pyx_v_q1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_k = __pyx_t_3; __pyx_t_3 = 0;
0651:
0652: # Determine which of the candidates (p0+k*p1)/(q0+k*q1) and p1/q1 is
0653: # closer to self. The distance between them is 1/(q1*(q0+k*q1)), while
0654: # the distance from p1/q1 to self is d/(q1*self._denominator). So we
0655: # need to compare 2*(q0+k*q1) with self._denominator/d.
+0656: if 2*d*(q0+k*q1) <= self._denominator:
__pyx_t_3 = __Pyx_PyInt_MultiplyCObj(__pyx_int_2, __pyx_v_d, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Multiply(__pyx_v_k, __pyx_v_q1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyNumber_Add(__pyx_v_q0, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyNumber_Multiply(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_RichCompare(__pyx_t_4, __pyx_v_self->_denominator, Py_LE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0657: return _fraction_from_coprime_ints(p1, q1)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_p1, __pyx_v_q1, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 657, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0658: else:
+0659: return _fraction_from_coprime_ints(p0+k*p1, q0+k*q1)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Multiply(__pyx_v_k, __pyx_v_p1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyNumber_Add(__pyx_v_p0, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Multiply(__pyx_v_k, __pyx_v_q1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_Add(__pyx_v_q0, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
0660:
+0661: @property
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_9numerator_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_10quicktions_8Fraction_9numerator_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_9numerator___get__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_9numerator___get__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0662: def numerator(self):
+0663: return self._numerator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_numerator); __pyx_r = __pyx_v_self->_numerator; goto __pyx_L0;
0664:
+0665: @property
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_11denominator_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_10quicktions_8Fraction_11denominator_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_11denominator___get__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_11denominator___get__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0666: def denominator(self):
+0667: return self._denominator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_denominator); __pyx_r = __pyx_v_self->_denominator; goto __pyx_L0;
0668:
+0669: def __repr__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_13__repr__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_12__repr__, "repr(self)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_12__repr__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_13__repr__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__repr__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_12__repr__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_12__repr__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__repr__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0670: """repr(self)"""
+0671: return '%s(%s, %s)' % (self.__class__.__name__,
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 671, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 671, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 671, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_2)) __PYX_ERR(0, 671, __pyx_L1_error); __Pyx_INCREF(__pyx_v_self->_numerator); __Pyx_GIVEREF(__pyx_v_self->_numerator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->_numerator)) __PYX_ERR(0, 671, __pyx_L1_error); __Pyx_INCREF(__pyx_v_self->_denominator); __Pyx_GIVEREF(__pyx_v_self->_denominator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_self->_denominator)) __PYX_ERR(0, 671, __pyx_L1_error); __pyx_t_2 = 0; /* … */ __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s_s, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 671, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0672: self._numerator, self._denominator)
0673:
+0674: def __str__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_15__str__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_14__str__, "str(self)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_14__str__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_15__str__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__str__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_14__str__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_14__str__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction.__str__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0675: """str(self)"""
+0676: if self._denominator == 1:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_self->_denominator, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 676, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0677: return str(self._numerator)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_Str(__pyx_v_self->_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 677, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+0678: elif PY_MAJOR_VERSION > 2:
__pyx_t_1 = (PY_MAJOR_VERSION > 2); if (__pyx_t_1) { /* … */ }
+0679: return f'{self._numerator}/{self._denominator}'
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 679, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = 127; __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_self->_numerator, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 679, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4; __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_5); __pyx_t_5 = 0; __Pyx_INCREF(__pyx_kp_u__8); __pyx_t_3 += 1; __Pyx_GIVEREF(__pyx_kp_u__8); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u__8); __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_self->_denominator, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 679, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4; __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 679, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0680: else:
+0681: return '%s/%s' % (self._numerator, self._denominator)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 681, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_self->_numerator); __Pyx_GIVEREF(__pyx_v_self->_numerator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_self->_numerator)) __PYX_ERR(0, 681, __pyx_L1_error); __Pyx_INCREF(__pyx_v_self->_denominator); __Pyx_GIVEREF(__pyx_v_self->_denominator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_self->_denominator)) __PYX_ERR(0, 681, __pyx_L1_error); __pyx_t_2 = __Pyx_PyString_Format(__pyx_kp_s_s_s, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 681, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0; }
0682:
0683: @cython.final
+0684: cdef _format_general(self, dict match):
static PyObject *__pyx_f_10quicktions_8Fraction__format_general(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_match) { PyObject *__pyx_v_fill = NULL; Py_UCS4 __pyx_v_align; PyObject *__pyx_v_pos_sign = NULL; int __pyx_v_alternate_form; Py_ssize_t __pyx_v_minimumwidth; PyObject *__pyx_v_thousands_sep = NULL; PyObject *__pyx_v_legacy_thousands_sep = NULL; Py_ssize_t __pyx_v_first_pos; PyObject *__pyx_v_n = NULL; PyObject *__pyx_v_d = NULL; PyObject *__pyx_v_body = NULL; PyObject *__pyx_v_den = NULL; PyObject *__pyx_v_sign = NULL; PyObject *__pyx_v_padding = NULL; Py_ssize_t __pyx_v_half; Py_ssize_t __pyx_7genexpr__pyx_v_pos; Py_ssize_t __pyx_8genexpr1__pyx_v_pos; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_AddTraceback("quicktions.Fraction._format_general", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_fill); __Pyx_XDECREF(__pyx_v_pos_sign); __Pyx_XDECREF(__pyx_v_thousands_sep); __Pyx_XDECREF(__pyx_v_legacy_thousands_sep); __Pyx_XDECREF(__pyx_v_n); __Pyx_XDECREF(__pyx_v_d); __Pyx_XDECREF(__pyx_v_body); __Pyx_XDECREF(__pyx_v_den); __Pyx_XDECREF(__pyx_v_sign); __Pyx_XDECREF(__pyx_v_padding); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0685: """Helper method for __format__.
0686:
0687: Handles fill, alignment, signs, and thousands separators in the
0688: case of no presentation type.
0689: """
0690: # Validate and parse the format specifier.
+0691: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 691, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_fill); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 691, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L3_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s__9); __pyx_t_1 = __pyx_kp_s__9; __pyx_L3_bool_binop_done:; __pyx_v_fill = __pyx_t_1; __pyx_t_1 = 0;
+0692: cdef Py_UCS4 align = ord(match["align"] or ">")
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 692, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 692, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L5_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s__10); __pyx_t_1 = __pyx_kp_s__10; __pyx_L5_bool_binop_done:; __pyx_t_4 = __Pyx_PyObject_Ord(__pyx_t_1); if (unlikely(__pyx_t_4 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 692, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_align = __pyx_t_4;
+0693: pos_sign = "" if match["sign"] == "-" else match["sign"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 693, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 693, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__11, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 693, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__6); __pyx_t_1 = __pyx_kp_s__6; } else { if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 693, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 693, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; } __pyx_v_pos_sign = __pyx_t_1; __pyx_t_1 = 0;
+0694: cdef bint alternate_form = match["alt"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 694, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_alt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 694, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 694, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_alternate_form = __pyx_t_3;
+0695: cdef Py_ssize_t minimumwidth = int(match["minimumwidth"] or "0")
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 695, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_minimumwidth); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 695, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L7_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s_0_2); __pyx_t_1 = __pyx_kp_s_0_2; __pyx_L7_bool_binop_done:; __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_5 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_5 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 695, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_minimumwidth = __pyx_t_5;
+0696: thousands_sep = match["thousands_sep"] or ''
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 696, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_thousands_sep); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 696, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 696, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L9_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s__6); __pyx_t_2 = __pyx_kp_s__6; __pyx_L9_bool_binop_done:; __pyx_v_thousands_sep = __pyx_t_2; __pyx_t_2 = 0;
0697:
+0698: if PY_VERSION_HEX < 0x03060000:
__pyx_t_3 = (PY_VERSION_HEX < 0x03060000); if (__pyx_t_3) { /* … */ }
+0699: legacy_thousands_sep, thousands_sep = thousands_sep, ''
__pyx_t_2 = __pyx_v_thousands_sep; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_kp_s__6; __Pyx_INCREF(__pyx_t_1); __pyx_v_legacy_thousands_sep = __pyx_t_2; __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_thousands_sep, __pyx_t_1); __pyx_t_1 = 0;
0700: cdef Py_ssize_t first_pos # Py2/3.5-only
0701:
0702: # Determine the body and sign representation.
+0703: n, d = self._numerator, self._denominator
__pyx_t_1 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_2); __pyx_v_n = __pyx_t_1; __pyx_t_1 = 0; __pyx_v_d = __pyx_t_2; __pyx_t_2 = 0;
+0704: if PY_VERSION_HEX < 0x03060000 and legacy_thousands_sep:
__pyx_t_6 = (PY_VERSION_HEX < 0x03060000); if (__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L13_bool_binop_done; } if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 704, __pyx_L1_error) } __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_legacy_thousands_sep); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 704, __pyx_L1_error) __pyx_t_3 = __pyx_t_6; __pyx_L13_bool_binop_done:; if (__pyx_t_3) { /* … */ goto __pyx_L12; }
0705: # Insert thousands separators if required.
+0706: body = str(abs(n))
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_Str(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_body = __pyx_t_1; __pyx_t_1 = 0;
+0707: first_pos = 1 + (len(body) - 1) % 3
__pyx_t_5 = PyObject_Length(__pyx_v_body); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 707, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_5 - 1), 3));
+0708: body = body[:first_pos] + "".join([
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_body, 0, __pyx_v_first_pos, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { /* enter inner scope */ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_10 = __Pyx_PyString_Join(__pyx_kp_s__6, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF_SET(__pyx_v_body, __pyx_t_2); __pyx_t_2 = 0;
+0709: legacy_thousands_sep + body[pos : pos + 3]
if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 709, __pyx_L1_error) } __pyx_t_9 = __Pyx_PyObject_GetSlice(__pyx_v_body, __pyx_7genexpr__pyx_v_pos, (__pyx_7genexpr__pyx_v_pos + 3), NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 709, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = PyNumber_Add(__pyx_v_legacy_thousands_sep, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 709, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_10))) __PYX_ERR(0, 708, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } /* exit inner scope */
+0710: for pos in range(first_pos, len(body), 3)
__pyx_t_5 = PyObject_Length(__pyx_v_body); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 710, __pyx_L1_error) __pyx_t_7 = __pyx_t_5; for (__pyx_t_8 = __pyx_v_first_pos; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=3) { __pyx_7genexpr__pyx_v_pos = __pyx_t_8;
0711: ])
+0712: if d > 1 or alternate_form:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_d, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 712, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 712, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L18_bool_binop_done; } __pyx_t_3 = __pyx_v_alternate_form; __pyx_L18_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+0713: den = str(abs(d))
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = __Pyx_PyObject_Str(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 713, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_den = __pyx_t_10; __pyx_t_10 = 0;
+0714: first_pos = 1 + (len(den) - 1) % 3
__pyx_t_5 = PyObject_Length(__pyx_v_den); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 714, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_5 - 1), 3));
+0715: den = den[:first_pos] + "".join([
__pyx_t_10 = __Pyx_PyObject_GetSlice(__pyx_v_den, 0, __pyx_v_first_pos, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); { /* enter inner scope */ __pyx_t_2 = PyList_New(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_9 = __Pyx_PyString_Join(__pyx_kp_s__6, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Add(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 715, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF_SET(__pyx_v_den, __pyx_t_2); __pyx_t_2 = 0;
+0716: legacy_thousands_sep + den[pos: pos + 3]
if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 716, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_den, __pyx_8genexpr1__pyx_v_pos, (__pyx_8genexpr1__pyx_v_pos + 3), NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyNumber_Add(__pyx_v_legacy_thousands_sep, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__Pyx_ListComp_Append(__pyx_t_2, (PyObject*)__pyx_t_9))) __PYX_ERR(0, 715, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } } /* exit inner scope */
+0717: for pos in range(first_pos, len(den), 3)
__pyx_t_5 = PyObject_Length(__pyx_v_den); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 717, __pyx_L1_error) __pyx_t_7 = __pyx_t_5; for (__pyx_t_8 = __pyx_v_first_pos; __pyx_t_8 < __pyx_t_7; __pyx_t_8+=3) { __pyx_8genexpr1__pyx_v_pos = __pyx_t_8;
0718: ])
+0719: body += "/" + den
__pyx_t_2 = PyNumber_Add(__pyx_kp_s__8, __pyx_v_den); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PyNumber_InPlaceAdd(__pyx_v_body, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_body, __pyx_t_9); __pyx_t_9 = 0;
+0720: elif d > 1 or alternate_form:
__pyx_t_9 = PyObject_RichCompare(__pyx_v_d, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 720, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 720, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (!__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L22_bool_binop_done; } __pyx_t_3 = __pyx_v_alternate_form; __pyx_L22_bool_binop_done:; if (__pyx_t_3) { /* … */ goto __pyx_L12; }
+0721: body = f"{abs(n):{thousands_sep}}/{d:{thousands_sep}}"
__pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_5 = 0; __pyx_t_11 = 127; __pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_1 = __Pyx_PyObject_Format(__pyx_t_2, __pyx_t_10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_11; __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1); __pyx_t_1 = 0; __Pyx_INCREF(__pyx_kp_u__8); __pyx_t_5 += 1; __Pyx_GIVEREF(__pyx_kp_u__8); PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_kp_u__8); __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_10 = __Pyx_PyObject_Format(__pyx_v_d, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) : __pyx_t_11; __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10); __Pyx_GIVEREF(__pyx_t_10); PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_9, 3, __pyx_t_5, __pyx_t_11); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_body = __pyx_t_10; __pyx_t_10 = 0;
0722: else:
+0723: body = f"{abs(n):{thousands_sep}}"
/*else*/ { __pyx_t_10 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = __Pyx_PyObject_Format(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_body = __pyx_t_1; __pyx_t_1 = 0; } __pyx_L12:;
+0724: sign = '-' if n < 0 else pos_sign
__pyx_t_9 = PyObject_RichCompare(__pyx_v_n, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 724, __pyx_L1_error) __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 724, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__11); __pyx_t_1 = __pyx_kp_s__11; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_1 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_1; __pyx_t_1 = 0;
0725:
0726: # Pad with fill character if necessary and return.
+0727: padding = fill * (minimumwidth - len(sign) - len(body))
__pyx_t_5 = PyObject_Length(__pyx_v_sign); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 727, __pyx_L1_error) __pyx_t_7 = PyObject_Length(__pyx_v_body); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 727, __pyx_L1_error) __pyx_t_1 = PyInt_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_5) - __pyx_t_7)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyNumber_Multiply(__pyx_v_fill, __pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_padding = __pyx_t_9; __pyx_t_9 = 0;
+0728: if align == u">":
switch (__pyx_v_align) { case 62: /* … */ break; case 60:
+0729: return padding + sign + body
__Pyx_XDECREF(__pyx_r); __pyx_t_9 = PyNumber_Add(__pyx_v_padding, __pyx_v_sign); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 729, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PyNumber_Add(__pyx_t_9, __pyx_v_body); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 729, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+0730: elif align == u"<":
break; case 94:
+0731: return sign + body + padding
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Add(__pyx_v_sign, __pyx_v_body); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_v_padding); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_9; __pyx_t_9 = 0; goto __pyx_L0;
+0732: elif align == u"^":
break; default:
+0733: half = len(padding) // 2
__pyx_t_7 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 733, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_7, 2);
+0734: return padding[:half] + sign + body + padding[half:]
__Pyx_XDECREF(__pyx_r); __pyx_t_9 = __Pyx_PyObject_GetSlice(__pyx_v_padding, 0, __pyx_v_half, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PyNumber_Add(__pyx_t_9, __pyx_v_sign); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_v_body); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_padding, __pyx_v_half, 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_t_1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_10; __pyx_t_10 = 0; goto __pyx_L0;
0735: else: # align == u"="
+0736: return sign + padding + body
__Pyx_XDECREF(__pyx_r); __pyx_t_10 = PyNumber_Add(__pyx_v_sign, __pyx_v_padding); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 736, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_1 = PyNumber_Add(__pyx_t_10, __pyx_v_body); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 736, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; break; }
0737:
0738: @cython.final
+0739: cdef _format_float_style(self, dict match):
static PyObject *__pyx_f_10quicktions_8Fraction__format_float_style(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_match) { PyObject *__pyx_v_fill = NULL; PyObject *__pyx_v_align = NULL; PyObject *__pyx_v_pos_sign = NULL; int __pyx_v_no_neg_zero; int __pyx_v_alternate_form; int __pyx_v_zeropad; Py_ssize_t __pyx_v_minimumwidth; PyObject *__pyx_v_thousands_sep = NULL; Py_ssize_t __pyx_v_precision; Py_UCS4 __pyx_v_presentation_type; int __pyx_v_trim_zeros; int __pyx_v_trim_point; PyObject *__pyx_v_exponent_indicator = NULL; int __pyx_v_negative; int __pyx_v_scientific; Py_ssize_t __pyx_v_exponent; Py_ssize_t __pyx_v_figures; PyObject *__pyx_v_significand = NULL; PyObject *__pyx_v_point_pos = NULL; PyObject *__pyx_v_suffix = NULL; PyObject *__pyx_v_digits = NULL; PyObject *__pyx_v_sign = NULL; PyObject *__pyx_v_leading = NULL; PyObject *__pyx_v_frac_part = NULL; PyObject *__pyx_v_separator = NULL; PyObject *__pyx_v_trailing = NULL; PyObject *__pyx_v_min_leading = NULL; Py_ssize_t __pyx_v_first_pos; PyObject *__pyx_v_body = NULL; PyObject *__pyx_v_padding = NULL; Py_ssize_t __pyx_v_half; Py_ssize_t __pyx_8genexpr2__pyx_v_pos; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_14); __Pyx_AddTraceback("quicktions.Fraction._format_float_style", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_fill); __Pyx_XDECREF(__pyx_v_align); __Pyx_XDECREF(__pyx_v_pos_sign); __Pyx_XDECREF(__pyx_v_thousands_sep); __Pyx_XDECREF(__pyx_v_exponent_indicator); __Pyx_XDECREF(__pyx_v_significand); __Pyx_XDECREF(__pyx_v_point_pos); __Pyx_XDECREF(__pyx_v_suffix); __Pyx_XDECREF(__pyx_v_digits); __Pyx_XDECREF(__pyx_v_sign); __Pyx_XDECREF(__pyx_v_leading); __Pyx_XDECREF(__pyx_v_frac_part); __Pyx_XDECREF(__pyx_v_separator); __Pyx_XDECREF(__pyx_v_trailing); __Pyx_XDECREF(__pyx_v_min_leading); __Pyx_XDECREF(__pyx_v_body); __Pyx_XDECREF(__pyx_v_padding); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0740: """Helper method for __format__; handles float presentation types."""
+0741: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 741, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_fill); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 741, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 741, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L3_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s__9); __pyx_t_1 = __pyx_kp_s__9; __pyx_L3_bool_binop_done:; __pyx_v_fill = __pyx_t_1; __pyx_t_1 = 0;
+0742: align = match["align"] or ">"
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 742, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 742, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 742, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L5_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s__10); __pyx_t_1 = __pyx_kp_s__10; __pyx_L5_bool_binop_done:; __pyx_v_align = __pyx_t_1; __pyx_t_1 = 0;
+0743: pos_sign = "" if match["sign"] == "-" else match["sign"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 743, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__11, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 743, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__6); __pyx_t_1 = __pyx_kp_s__6; } else { if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 743, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __pyx_t_2 = 0; } __pyx_v_pos_sign = __pyx_t_1; __pyx_t_1 = 0;
+0744: cdef bint no_neg_zero = match["no_neg_zero"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 744, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_no_neg_zero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_no_neg_zero = __pyx_t_3;
+0745: cdef bint alternate_form = match["alt"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 745, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_alt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 745, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 745, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_alternate_form = __pyx_t_3;
+0746: cdef bint zeropad = match["zeropad"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 746, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_zeropad); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 746, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_zeropad = __pyx_t_3;
+0747: cdef Py_ssize_t minimumwidth = int(match["minimumwidth"] or "0")
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 747, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_minimumwidth); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 747, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_t_2; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; goto __pyx_L7_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s_0_2); __pyx_t_1 = __pyx_kp_s_0_2; __pyx_L7_bool_binop_done:; __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 747, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_2); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 747, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_minimumwidth = __pyx_t_4;
+0748: thousands_sep = match["thousands_sep"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 748, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_thousands_sep); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 748, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_thousands_sep = __pyx_t_2; __pyx_t_2 = 0;
+0749: cdef Py_ssize_t precision = int(match["precision"] or "6")
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 749, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_precision); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 749, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 749, __pyx_L1_error) if (!__pyx_t_3) { __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } else { __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L9_bool_binop_done; } __Pyx_INCREF(__pyx_kp_s_6); __pyx_t_2 = __pyx_kp_s_6; __pyx_L9_bool_binop_done:; __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 749, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 749, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_precision = __pyx_t_4;
+0750: cdef Py_UCS4 presentation_type = ord(match["presentation_type"])
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 750, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_presentation_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 750, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_Ord(__pyx_t_1); if (unlikely(__pyx_t_5 == ((long)(long)(Py_UCS4)-1))) __PYX_ERR(0, 750, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_presentation_type = __pyx_t_5;
+0751: cdef bint trim_zeros = presentation_type in u"gG" and not alternate_form
switch (__pyx_v_presentation_type) { case 71: case 0x67: __pyx_t_6 = 1; break; default: __pyx_t_6 = 0; break; } __pyx_t_7 = __pyx_t_6; if (__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L11_bool_binop_done; } __pyx_t_7 = (!__pyx_v_alternate_form); __pyx_t_3 = __pyx_t_7; __pyx_L11_bool_binop_done:; __pyx_v_trim_zeros = __pyx_t_3;
+0752: cdef bint trim_point = not alternate_form
__pyx_v_trim_point = (!__pyx_v_alternate_form);
+0753: exponent_indicator = "E" if presentation_type in u"EFG" else "e"
switch (__pyx_v_presentation_type) { case 69: case 70: case 71: __Pyx_INCREF(__pyx_n_s_E); __pyx_t_1 = __pyx_n_s_E; break; default: __Pyx_INCREF(__pyx_n_s_e); __pyx_t_1 = __pyx_n_s_e; break; } __pyx_v_exponent_indicator = __pyx_t_1; __pyx_t_1 = 0;
0754:
0755: cdef bint negative, scientific
0756: cdef Py_ssize_t exponent, figures
0757:
0758: # Round to get the digits we need, figure out where to place the point,
0759: # and decide whether to use scientific notation. 'point_pos' is the
0760: # relative to the _end_ of the digit string: that is, it's the number
0761: # of digits that should follow the point.
+0762: if presentation_type in u"fF%":
switch (__pyx_v_presentation_type) { case 37: case 70: case 0x66: /* … */ break; default:
+0763: exponent = -precision
__pyx_v_exponent = (-__pyx_v_precision);
+0764: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37); if (__pyx_t_3) { /* … */ }
+0765: exponent -= 2
__pyx_v_exponent = (__pyx_v_exponent - 2);
+0766: negative, significand = _round_to_exponent(
__pyx_t_10.__pyx_n = 1; __pyx_t_10.no_neg_zero = __pyx_v_no_neg_zero; __pyx_t_9 = __pyx_f_10quicktions__round_to_exponent(__pyx_t_1, __pyx_t_2, __pyx_t_8, &__pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 766, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_9))) || (PyList_CheckExact(__pyx_t_9))) { PyObject* sequence = __pyx_t_9; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 766, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_8 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_8 = PyList_GET_ITEM(sequence, 0); __pyx_t_2 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(__pyx_t_2); #else __pyx_t_8 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 766, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 766, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else { Py_ssize_t index = -1; __pyx_t_1 = PyObject_GetIter(__pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 766, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_1); index = 0; __pyx_t_8 = __pyx_t_11(__pyx_t_1); if (unlikely(!__pyx_t_8)) goto __pyx_L14_unpacking_failed; __Pyx_GOTREF(__pyx_t_8); index = 1; __pyx_t_2 = __pyx_t_11(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L14_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_1), 2) < 0) __PYX_ERR(0, 766, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L15_unpacking_done; __pyx_L14_unpacking_failed:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 766, __pyx_L1_error) __pyx_L15_unpacking_done:; } __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_8); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 766, __pyx_L1_error) __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_negative = __pyx_t_3; __pyx_v_significand = __pyx_t_2; __pyx_t_2 = 0;
+0767: self._numerator, self._denominator, exponent, no_neg_zero)
__pyx_t_1 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_2); __pyx_t_8 = PyInt_FromSsize_t(__pyx_v_exponent); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 767, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8);
+0768: scientific = False
__pyx_v_scientific = 0;
+0769: point_pos = precision
__pyx_t_9 = PyInt_FromSsize_t(__pyx_v_precision); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 769, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_point_pos = __pyx_t_9; __pyx_t_9 = 0;
0770: else: # presentation_type in "eEgG"
0771: figures = (
+0772: max(precision, 1)
switch (__pyx_v_presentation_type) { case 71: /* … */ __pyx_t_5 = 1; __pyx_t_12 = __pyx_v_precision; __pyx_t_3 = (__pyx_t_5 > __pyx_t_12); if (__pyx_t_3) { __pyx_t_13 = __pyx_t_5; } else { __pyx_t_13 = __pyx_t_12; } __pyx_t_4 = __pyx_t_13; break; default:
+0773: if presentation_type in u"gG"
case 0x67:
+0774: else precision + 1
__pyx_t_4 = (__pyx_v_precision + 1); break; } __pyx_v_figures = __pyx_t_4;
0775: )
+0776: negative, significand, exponent = _round_to_figures(
__pyx_t_8 = __pyx_f_10quicktions__round_to_figures(__pyx_t_9, __pyx_t_2, __pyx_v_figures); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_8))) || (PyList_CheckExact(__pyx_t_8))) { PyObject* sequence = __pyx_t_8; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 776, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); } else { __pyx_t_2 = PyList_GET_ITEM(sequence, 0); __pyx_t_9 = PyList_GET_ITEM(sequence, 1); __pyx_t_1 = PyList_GET_ITEM(sequence, 2); } __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_1); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; } else { Py_ssize_t index = -1; __pyx_t_14 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_11 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_14); index = 0; __pyx_t_2 = __pyx_t_11(__pyx_t_14); if (unlikely(!__pyx_t_2)) goto __pyx_L16_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_9 = __pyx_t_11(__pyx_t_14); if (unlikely(!__pyx_t_9)) goto __pyx_L16_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); index = 2; __pyx_t_1 = __pyx_t_11(__pyx_t_14); if (unlikely(!__pyx_t_1)) goto __pyx_L16_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); if (__Pyx_IternextUnpackEndCheck(__pyx_t_11(__pyx_t_14), 3) < 0) __PYX_ERR(0, 776, __pyx_L1_error) __pyx_t_11 = NULL; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; goto __pyx_L17_unpacking_done; __pyx_L16_unpacking_failed:; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_11 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 776, __pyx_L1_error) __pyx_L17_unpacking_done:; } __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_4 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_negative = __pyx_t_3; __pyx_v_significand = __pyx_t_9; __pyx_t_9 = 0; __pyx_v_exponent = __pyx_t_4;
+0777: self._numerator, self._denominator, figures)
__pyx_t_9 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_9); __pyx_t_2 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_2);
0778: scientific = (
+0779: presentation_type in u"eE"
switch (__pyx_v_presentation_type) { case 69: case 0x65: __pyx_t_7 = 1; break; default: __pyx_t_7 = 0; break; } __pyx_t_6 = __pyx_t_7; if (!__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L18_bool_binop_done; }
+0780: or exponent > 0
__pyx_t_6 = (__pyx_v_exponent > 0); if (!__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L18_bool_binop_done; }
+0781: or exponent + figures <= -4
__pyx_t_6 = ((__pyx_v_exponent + __pyx_v_figures) <= -4L); __pyx_t_3 = __pyx_t_6; __pyx_L18_bool_binop_done:; __pyx_v_scientific = __pyx_t_3;
0782: )
+0783: point_pos = figures - 1 if scientific else -exponent
if (__pyx_v_scientific) { __pyx_t_1 = PyInt_FromSsize_t((__pyx_v_figures - 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __pyx_t_1; __pyx_t_1 = 0; } else { __pyx_t_1 = PyInt_FromSsize_t((-__pyx_v_exponent)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __pyx_t_1; __pyx_t_1 = 0; } __pyx_v_point_pos = __pyx_t_8; __pyx_t_8 = 0; break; }
0784:
0785: # Get the suffix - the part following the digits, if any.
+0786: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37); if (__pyx_t_3) { /* … */ goto __pyx_L21; }
+0787: suffix = "%"
__Pyx_INCREF(__pyx_kp_s__12);
__pyx_v_suffix = __pyx_kp_s__12;
+0788: elif scientific:
if (__pyx_v_scientific) { /* … */ goto __pyx_L21; }
0789: #suffix = f"{exponent_indicator}{exponent + point_pos:+03d}"
+0790: suffix = "%s%+03d" % (exponent_indicator, exponent + point_pos)
__pyx_t_8 = PyInt_FromSsize_t(__pyx_v_exponent); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 790, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_v_point_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 790, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyTuple_New(2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 790, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_INCREF(__pyx_v_exponent_indicator); __Pyx_GIVEREF(__pyx_v_exponent_indicator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_exponent_indicator)) __PYX_ERR(0, 790, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1)) __PYX_ERR(0, 790, __pyx_L1_error); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_s_03d, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 790, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_suffix = __pyx_t_1; __pyx_t_1 = 0;
0791: else:
+0792: suffix = ""
/*else*/ {
__Pyx_INCREF(__pyx_kp_s__6);
__pyx_v_suffix = __pyx_kp_s__6;
}
__pyx_L21:;
0793:
0794: # String of output digits, padded sufficiently with zeros on the left
0795: # so that we'll have at least one digit before the decimal point.
+0796: digits = f"{significand:0{point_pos + 1}d}"
__pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 796, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = 0; __pyx_t_15 = 127; __Pyx_INCREF(__pyx_kp_u_0_2); __pyx_t_4 += 1; __Pyx_GIVEREF(__pyx_kp_u_0_2); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_0_2); __pyx_t_8 = __Pyx_PyInt_AddObjC(__pyx_v_point_pos, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 796, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_t_8, __pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 796, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_15 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) > __pyx_t_15) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) : __pyx_t_15; __pyx_t_4 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_9); __pyx_t_9 = 0; __Pyx_INCREF(__pyx_n_u_d); __pyx_t_4 += 1; __Pyx_GIVEREF(__pyx_n_u_d); PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_n_u_d); __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_1, 3, __pyx_t_4, __pyx_t_15); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 796, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_Format(__pyx_v_significand, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 796, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_digits = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
0797:
0798: # Before padding, the output has the form f"{sign}{leading}{trailing}",
0799: # where `leading` includes thousands separators if necessary and
0800: # `trailing` includes the decimal separator where appropriate.
+0801: sign = "-" if negative else pos_sign
if (__pyx_v_negative) { __Pyx_INCREF(__pyx_kp_s__11); __pyx_t_1 = __pyx_kp_s__11; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_1 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_1; __pyx_t_1 = 0;
+0802: leading = digits[: len(digits) - point_pos]
__pyx_t_4 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_digits); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 802, __pyx_L1_error) __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 802, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyNumber_Subtract(__pyx_t_1, __pyx_v_point_pos); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 802, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (__pyx_t_9 == Py_None); if (__pyx_t_3) { __pyx_t_4 = PY_SSIZE_T_MAX; } else { __pyx_t_13 = __Pyx_PyIndex_AsSsize_t(__pyx_t_9); if (unlikely((__pyx_t_13 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 802, __pyx_L1_error) __pyx_t_4 = __pyx_t_13; } __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = __Pyx_PyUnicode_Substring(__pyx_v_digits, 0, __pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 802, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_leading = __pyx_t_9; __pyx_t_9 = 0;
+0803: frac_part = digits[len(digits) - point_pos :]
__pyx_t_4 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_digits); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 803, __pyx_L1_error) __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 803, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PyNumber_Subtract(__pyx_t_9, __pyx_v_point_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 803, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_3 = (__pyx_t_1 == Py_None); if (__pyx_t_3) { __pyx_t_4 = 0; } else { __pyx_t_13 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_13 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 803, __pyx_L1_error) __pyx_t_4 = __pyx_t_13; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyUnicode_Substring(__pyx_v_digits, __pyx_t_4, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 803, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_frac_part = __pyx_t_1; __pyx_t_1 = 0;
+0804: if trim_zeros:
if (__pyx_v_trim_zeros) { /* … */ }
+0805: frac_part = frac_part.rstrip("0")
__pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyUnicode_Type_rstrip, __pyx_v_frac_part, __pyx_kp_s_0_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 805, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_frac_part, __pyx_t_1); __pyx_t_1 = 0;
+0806: separator = "" if trim_point and not frac_part else "."
if (__pyx_v_trim_point) { } else { __pyx_t_3 = __pyx_v_trim_point; goto __pyx_L23_bool_binop_done; } __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_frac_part); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 806, __pyx_L1_error) __pyx_t_7 = (!__pyx_t_6); __pyx_t_3 = __pyx_t_7; __pyx_L23_bool_binop_done:; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__6); __pyx_t_1 = __pyx_kp_s__6; } else { __Pyx_INCREF(__pyx_kp_s__5); __pyx_t_1 = __pyx_kp_s__5; } __pyx_v_separator = __pyx_t_1; __pyx_t_1 = 0;
+0807: trailing = separator + frac_part + suffix
__pyx_t_1 = PyNumber_Add(__pyx_v_separator, __pyx_v_frac_part); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_v_suffix); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_trailing = __pyx_t_9; __pyx_t_9 = 0;
0808:
0809: # Do zero padding if required.
+0810: if zeropad:
if (__pyx_v_zeropad) { /* … */ }
+0811: min_leading = minimumwidth - len(sign) - len(trailing)
__pyx_t_4 = PyObject_Length(__pyx_v_sign); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 811, __pyx_L1_error) __pyx_t_13 = PyObject_Length(__pyx_v_trailing); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 811, __pyx_L1_error) __pyx_t_9 = PyInt_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_4) - __pyx_t_13)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 811, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_min_leading = __pyx_t_9; __pyx_t_9 = 0;
0812: # When adding thousands separators, they'll be added to the
0813: # zero-padded portion too, so we need to compensate.
+0814: leading = leading.zfill(
__pyx_t_1 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyUnicode_Type_zfill, __pyx_v_leading, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 814, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF_SET(__pyx_v_leading, __pyx_t_1); __pyx_t_1 = 0;
+0815: 3 * min_leading // 4 + 1 if thousands_sep else min_leading
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_thousands_sep); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 815, __pyx_L1_error) if (__pyx_t_3) { __pyx_t_1 = __Pyx_PyInt_MultiplyCObj(__pyx_int_3, __pyx_v_min_leading, 3, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __Pyx_PyInt_FloorDivideObjC(__pyx_t_1, __pyx_int_4, 4, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyInt_AddObjC(__pyx_t_8, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_9 = __pyx_t_1; __pyx_t_1 = 0; } else { __Pyx_INCREF(__pyx_v_min_leading); __pyx_t_9 = __pyx_v_min_leading; }
0816: )
0817:
0818: # Insert thousands separators if required.
+0819: if thousands_sep:
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_thousands_sep); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 819, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0820: first_pos = 1 + (len(leading) - 1) % 3
__pyx_t_13 = PyObject_Length(__pyx_v_leading); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 820, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_13 - 1), 3));
+0821: leading = leading[:first_pos] + "".join([
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_leading, 0, __pyx_v_first_pos, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { /* enter inner scope */ __pyx_t_9 = PyList_New(0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); /* … */ __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__6, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_leading, __pyx_t_9); __pyx_t_9 = 0;
+0822: thousands_sep + leading[pos : pos + 3]
__pyx_t_8 = __Pyx_PyObject_GetSlice(__pyx_v_leading, __pyx_8genexpr2__pyx_v_pos, (__pyx_8genexpr2__pyx_v_pos + 3), NULL, NULL, NULL, 1, 1, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 822, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = PyNumber_Add(__pyx_v_thousands_sep, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 822, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(__Pyx_ListComp_Append(__pyx_t_9, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } /* exit inner scope */
+0823: for pos in range(first_pos, len(leading), 3)
__pyx_t_13 = PyObject_Length(__pyx_v_leading); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 823, __pyx_L1_error) __pyx_t_4 = __pyx_t_13; for (__pyx_t_12 = __pyx_v_first_pos; __pyx_t_12 < __pyx_t_4; __pyx_t_12+=3) { __pyx_8genexpr2__pyx_v_pos = __pyx_t_12;
0824: ])
0825:
0826: # We now have a sign and a body. Pad with fill character if necessary
0827: # and return.
+0828: body = leading + trailing
__pyx_t_9 = PyNumber_Add(__pyx_v_leading, __pyx_v_trailing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 828, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_body = __pyx_t_9; __pyx_t_9 = 0;
+0829: padding = fill * (minimumwidth - len(sign) - len(body))
__pyx_t_13 = PyObject_Length(__pyx_v_sign); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 829, __pyx_L1_error) __pyx_t_4 = PyObject_Length(__pyx_v_body); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 829, __pyx_L1_error) __pyx_t_9 = PyInt_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_13) - __pyx_t_4)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 829, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = PyNumber_Multiply(__pyx_v_fill, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 829, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_padding = __pyx_t_2; __pyx_t_2 = 0;
+0830: if align == ">":
__pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_align, __pyx_kp_s__10, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 830, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0831: return padding + sign + body
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyNumber_Add(__pyx_v_padding, __pyx_v_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PyNumber_Add(__pyx_t_2, __pyx_v_body); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_9; __pyx_t_9 = 0; goto __pyx_L0;
+0832: elif align == "<":
__pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_align, __pyx_kp_s__13, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 832, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0833: return sign + body + padding
__Pyx_XDECREF(__pyx_r); __pyx_t_9 = PyNumber_Add(__pyx_v_sign, __pyx_v_body); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 833, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = PyNumber_Add(__pyx_t_9, __pyx_v_padding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 833, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+0834: elif align == "^":
__pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_align, __pyx_kp_s__14, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 834, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0835: half = len(padding) // 2
__pyx_t_4 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 835, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_4, 2);
+0836: return padding[:half] + sign + body + padding[half:]
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_GetSlice(__pyx_v_padding, 0, __pyx_v_half, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 836, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PyNumber_Add(__pyx_t_2, __pyx_v_sign); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 836, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Add(__pyx_t_9, __pyx_v_body); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 836, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = __Pyx_PyObject_GetSlice(__pyx_v_padding, __pyx_v_half, 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 836, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 836, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0837: else: # align == "="
+0838: return sign + padding + body
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Add(__pyx_v_sign, __pyx_v_padding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 838, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyNumber_Add(__pyx_t_1, __pyx_v_body); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 838, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_9; __pyx_t_9 = 0; goto __pyx_L0; }
0839:
+0840: def __format__(self, format_spec, /):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_17__format__(PyObject *__pyx_v_self, PyObject *__pyx_v_format_spec); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_16__format__, "Format this fraction according to the given format specification."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_17__format__ = {"__format__", (PyCFunction)__pyx_pw_10quicktions_8Fraction_17__format__, METH_O, __pyx_doc_10quicktions_8Fraction_16__format__}; static PyObject *__pyx_pw_10quicktions_8Fraction_17__format__(PyObject *__pyx_v_self, PyObject *__pyx_v_format_spec) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__format__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_16__format__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self), ((PyObject *)__pyx_v_format_spec)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_16__format__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_format_spec) { PyObject *__pyx_v_match_groups = NULL; PyObject *__pyx_v_match = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__format__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_match_groups); __Pyx_XDECREF(__pyx_v_match); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__32 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_format_spec, __pyx_n_s_match_groups, __pyx_n_s_match); if (unlikely(!__pyx_tuple__32)) __PYX_ERR(0, 840, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__32); __Pyx_GIVEREF(__pyx_tuple__32); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_17__format__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___format, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__33)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 840, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_format, __pyx_t_3) < 0) __PYX_ERR(0, 840, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__33 = (PyObject*)__Pyx_PyCode_New(2, 2, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__32, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_format, 840, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__33)) __PYX_ERR(0, 840, __pyx_L1_error)
0841: """Format this fraction according to the given format specification."""
0842:
+0843: if match := _GENERAL_FORMAT_SPECIFICATION_MATCHER(format_spec):
__Pyx_INCREF(__pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER); __pyx_t_2 = __pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER; __pyx_t_3 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_format_spec}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 843, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } __pyx_v_match = __pyx_t_1; __Pyx_INCREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 843, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+0844: return self._format_general(match.groupdict())
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_groupdict); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 844, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 844, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_1))) __PYX_ERR(0, 844, __pyx_L1_error) #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_2 = __pyx_f_10quicktions_8Fraction__format_general(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 844, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0845:
+0846: if match := _FLOAT_FORMAT_SPECIFICATION_MATCHER(format_spec):
__Pyx_INCREF(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER); __pyx_t_1 = __pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER; __pyx_t_3 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_format_spec}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 1+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __Pyx_DECREF_SET(__pyx_v_match, __pyx_t_2); __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 846, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_5) { /* … */ }
0847: # Refuse the temptation to guess if both alignment _and_
0848: # zero padding are specified.
+0849: match_groups = match.groupdict()
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_match, __pyx_n_s_groupdict); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 849, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = NULL; __pyx_t_4 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_1))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_4 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 849, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_v_match_groups = __pyx_t_2; __pyx_t_2 = 0;
+0850: if match_groups["align"] is None or match_groups["zeropad"] is None:
__pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_match_groups, __pyx_n_s_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = (__pyx_t_2 == Py_None); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!__pyx_t_6) { } else { __pyx_t_5 = __pyx_t_6; goto __pyx_L6_bool_binop_done; } __pyx_t_2 = __Pyx_PyObject_Dict_GetItem(__pyx_v_match_groups, __pyx_n_s_zeropad); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = (__pyx_t_2 == Py_None); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_5 = __pyx_t_6; __pyx_L6_bool_binop_done:; if (__pyx_t_5) { /* … */ }
+0851: return self._format_float_style(match_groups)
__Pyx_XDECREF(__pyx_r); if (!(likely(PyDict_CheckExact(__pyx_v_match_groups))||((__pyx_v_match_groups) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_v_match_groups))) __PYX_ERR(0, 851, __pyx_L1_error) #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_2 = __pyx_f_10quicktions_8Fraction__format_float_style(__pyx_v_self, ((PyObject*)__pyx_v_match_groups)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 851, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0852:
+0853: raise ValueError(
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 853, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 853, __pyx_L1_error)
+0854: f"Invalid format specifier {format_spec!r} "
__pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 854, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = 0; __pyx_t_8 = 127; __Pyx_INCREF(__pyx_kp_u_Invalid_format_specifier); __pyx_t_7 += 25; __Pyx_GIVEREF(__pyx_kp_u_Invalid_format_specifier); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_Invalid_format_specifier); __pyx_t_1 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_format_spec), __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 854, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) : __pyx_t_8; __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1); __pyx_t_1 = 0; __Pyx_INCREF(__pyx_kp_u_for_object_of_type); __pyx_t_7 += 20; __Pyx_GIVEREF(__pyx_kp_u_for_object_of_type); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_for_object_of_type); /* … */ __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_2, 4, __pyx_t_7, __pyx_t_8); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 854, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+0855: f"for object of type {type(self).__name__!r}"
__pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))), __pyx_n_s_name); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 855, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_t_1), __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 855, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_8 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_8) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_8; __pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_3); __pyx_t_3 = 0;
0856: )
0857:
+0858: def __add__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_19__add__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_18__add__, "a + b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_18__add__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_19__add__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__add__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_18__add__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_18__add__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__add__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0859: """a + b"""
+0860: return forward(a, b, _add, _math_op_add)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_add; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__add, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 860, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0861:
+0862: def __radd__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_21__radd__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_20__radd__, "a + b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_20__radd__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_21__radd__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__radd__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_20__radd__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_20__radd__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__radd__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0863: """a + b"""
+0864: return reverse(a, b, _add, _math_op_add)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_add; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__add, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 864, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0865:
+0866: def __sub__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_23__sub__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_22__sub__, "a - b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_22__sub__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_23__sub__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__sub__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_22__sub__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_22__sub__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__sub__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0867: """a - b"""
+0868: return forward(a, b, _sub, _math_op_sub)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_sub; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__sub, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0869:
+0870: def __rsub__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_25__rsub__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_24__rsub__, "a - b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_24__rsub__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_25__rsub__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rsub__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_24__rsub__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_24__rsub__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rsub__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0871: """a - b"""
+0872: return reverse(a, b, _sub, _math_op_sub)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_sub; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__sub, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 872, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0873:
+0874: def __mul__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_27__mul__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_26__mul__, "a * b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_26__mul__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_27__mul__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__mul__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_26__mul__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_26__mul__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__mul__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0875: """a * b"""
+0876: return forward(a, b, _mul, _math_op_mul)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_mul; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__mul, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 876, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0877:
+0878: def __rmul__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_29__rmul__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_28__rmul__, "a * b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_28__rmul__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_29__rmul__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rmul__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_28__rmul__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_28__rmul__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rmul__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0879: """a * b"""
+0880: return reverse(a, b, _mul, _math_op_mul)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_mul; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__mul, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 880, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0881:
+0882: def __div__(a, b):
/* Python wrapper */ #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) static PyObject *__pyx_pw_10quicktions_8Fraction_31__div__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_30__div__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_30__div__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_31__div__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__div__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_30__div__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000))*/ #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) static PyObject *__pyx_pf_10quicktions_8Fraction_30__div__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000))*/
0883: """a / b"""
+0884: return forward(a, b, _div, _math_op_div)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_div; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__div, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 884, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0885:
+0886: def __rdiv__(b, a):
/* Python wrapper */ #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) static PyObject *__pyx_pw_10quicktions_8Fraction_33__rdiv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_32__rdiv__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_32__rdiv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_33__rdiv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rdiv__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_32__rdiv__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000))*/ #if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000) static PyObject *__pyx_pf_10quicktions_8Fraction_32__rdiv__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rdiv__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } #endif /*!(#if PY_MAJOR_VERSION < 3 || (CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX < 0x03050000))*/
0887: """a / b"""
+0888: return reverse(a, b, _div, _math_op_div)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_div; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__div, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 888, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0889:
+0890: def __truediv__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_35__truediv__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_34__truediv__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_34__truediv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_35__truediv__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__truediv__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_34__truediv__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_34__truediv__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__truediv__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0891: """a / b"""
+0892: return forward(a, b, _div, _math_op_truediv)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_truediv; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__div, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 892, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0893:
+0894: def __rtruediv__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_37__rtruediv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_36__rtruediv__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_36__rtruediv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_37__rtruediv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rtruediv__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_36__rtruediv__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_36__rtruediv__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rtruediv__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0895: """a / b"""
+0896: return reverse(a, b, _div, _math_op_truediv)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_truediv; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__div, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 896, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0897:
+0898: def __floordiv__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_39__floordiv__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_38__floordiv__, "a // b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_38__floordiv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_39__floordiv__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__floordiv__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_38__floordiv__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_38__floordiv__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__floordiv__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0899: """a // b"""
+0900: return forward(a, b, _floordiv, _math_op_floordiv)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_floordiv; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__floordiv, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 900, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0901:
+0902: def __rfloordiv__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_41__rfloordiv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_40__rfloordiv__, "a // b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_40__rfloordiv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_41__rfloordiv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rfloordiv__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_40__rfloordiv__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_40__rfloordiv__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rfloordiv__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0903: """a // b"""
+0904: return reverse(a, b, _floordiv, _math_op_floordiv)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_floordiv; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__floordiv, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 904, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0905:
+0906: def __mod__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_43__mod__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_42__mod__, "a % b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_42__mod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_43__mod__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__mod__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_42__mod__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_42__mod__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__mod__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0907: """a % b"""
+0908: return forward(a, b, _mod, _math_op_mod)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_mod; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__mod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 908, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0909:
+0910: def __rmod__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_45__rmod__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_44__rmod__, "a % b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_44__rmod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_45__rmod__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rmod__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_44__rmod__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_44__rmod__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rmod__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0911: """a % b"""
+0912: return reverse(a, b, _mod, _math_op_mod)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_mod; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__mod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 912, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0913:
+0914: def __divmod__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_47__divmod__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_46__divmod__, "divmod(self, other): The pair (self // other, self % other).\n\n Sometimes this can be computed faster than the pair of\n operations.\n "); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_46__divmod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_47__divmod__(PyObject *__pyx_v_a, PyObject *__pyx_v_b) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__divmod__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_46__divmod__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_46__divmod__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__divmod__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0915: """divmod(self, other): The pair (self // other, self % other).
0916:
0917: Sometimes this can be computed faster than the pair of
0918: operations.
0919: """
+0920: return forward(a, b, _divmod, _math_op_divmod)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_divmod; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__divmod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 920, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0921:
+0922: def __rdivmod__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_49__rdivmod__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_48__rdivmod__, "divmod(self, other): The pair (self // other, self % other).\n\n Sometimes this can be computed faster than the pair of\n operations.\n "); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_48__rdivmod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_49__rdivmod__(PyObject *__pyx_v_b, PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rdivmod__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_48__rdivmod__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_48__rdivmod__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__rdivmod__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0923: """divmod(self, other): The pair (self // other, self % other).
0924:
0925: Sometimes this can be computed faster than the pair of
0926: operations.
0927: """
+0928: return reverse(a, b, _divmod, _math_op_divmod)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_divmod; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__divmod, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 928, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0929:
+0930: def __pow__(a, b, x):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_51__pow__(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_x); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_50__pow__, "a ** b\n\n If b is not an integer, the result will be a float or complex\n since roots are generally irrational. If b is an integer, the\n result will be rational.\n "); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_50__pow__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_51__pow__(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_x) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pow__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_50__pow__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b), ((PyObject *)__pyx_v_x)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_50__pow__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_x) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("quicktions.Fraction.__pow__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0931: """a ** b
0932:
0933: If b is not an integer, the result will be a float or complex
0934: since roots are generally irrational. If b is an integer, the
0935: result will be rational.
0936: """
+0937: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { /* … */ }
+0938: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
0939:
+0940: if isinstance(b, (int, long)):
__pyx_t_2 = PyInt_Check(__pyx_v_b); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L5_bool_binop_done; } __pyx_t_2 = PyLong_Check(__pyx_v_b); __pyx_t_1 = __pyx_t_2; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0941: return _pow(a.numerator, a.denominator, b, 1)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = __pyx_f_10quicktions__pow(__pyx_t_3, __pyx_t_4, __pyx_v_b, __pyx_int_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+0942: elif isinstance(b, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_5 = __pyx_v_10quicktions_Rational; __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_b, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L7_bool_binop_done; } __pyx_t_2 = PyObject_IsInstance(__pyx_v_b, __pyx_t_5); __pyx_t_1 = __pyx_t_2; __pyx_L7_bool_binop_done:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+0943: return _pow(a.numerator, a.denominator, b.numerator, b.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 943, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 943, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 943, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 943, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __pyx_f_10quicktions__pow(__pyx_t_5, __pyx_t_4, __pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 943, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
0944: else:
+0945: return (a.numerator / a.denominator) ** b
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_numerator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 945, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 945, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 945, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Power(__pyx_t_3, __pyx_v_b, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 945, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0; }
0946:
+0947: def __rpow__(b, a, x):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_53__rpow__(PyObject *__pyx_v_b, PyObject *__pyx_v_a, PyObject *__pyx_v_x); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_52__rpow__, "a ** b\n\n If b is not an integer, the result will be a float or complex\n since roots are generally irrational. If b is an integer, the\n result will be rational.\n "); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_52__rpow__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_53__rpow__(PyObject *__pyx_v_b, PyObject *__pyx_v_a, PyObject *__pyx_v_x) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__rpow__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_52__rpow__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), ((PyObject *)__pyx_v_a), ((PyObject *)__pyx_v_x)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_52__rpow__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_b, PyObject *__pyx_v_a, PyObject *__pyx_v_x) { PyObject *__pyx_v_bn = NULL; PyObject *__pyx_v_bd = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction.__rpow__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_bn); __Pyx_XDECREF(__pyx_v_bd); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0948: """a ** b
0949:
0950: If b is not an integer, the result will be a float or complex
0951: since roots are generally irrational. If b is an integer, the
0952: result will be rational.
0953: """
+0954: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { /* … */ }
+0955: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
0956:
+0957: bn, bd = b.numerator, b.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_b), __pyx_n_s_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 957, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_b), __pyx_n_s_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 957, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_bn = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_bd = __pyx_t_3; __pyx_t_3 = 0;
+0958: if bd == 1 and bn >= 0:
__pyx_t_4 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_bd, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 958, __pyx_L1_error) if (__pyx_t_4) { } else { __pyx_t_1 = __pyx_t_4; goto __pyx_L5_bool_binop_done; } __pyx_t_3 = PyObject_RichCompare(__pyx_v_bn, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 958, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 958, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_4; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* … */ }
0959: # If a is an int, keep it that way if possible.
+0960: return a ** bn
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyNumber_Power(__pyx_v_a, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 960, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0961:
+0962: if isinstance(a, (int, long)):
__pyx_t_4 = PyInt_Check(__pyx_v_a); if (!__pyx_t_4) { } else { __pyx_t_1 = __pyx_t_4; goto __pyx_L8_bool_binop_done; } __pyx_t_4 = PyLong_Check(__pyx_v_a); __pyx_t_1 = __pyx_t_4; __pyx_L8_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0963: return _pow(a, 1, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_f_10quicktions__pow(__pyx_v_a, __pyx_int_1, __pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+0964: if isinstance(a, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_3 = __pyx_v_10quicktions_Rational; __pyx_t_4 = __Pyx_TypeCheck(__pyx_v_a, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_4) { } else { __pyx_t_1 = __pyx_t_4; goto __pyx_L11_bool_binop_done; } __pyx_t_4 = PyObject_IsInstance(__pyx_v_a, __pyx_t_3); __pyx_t_1 = __pyx_t_4; __pyx_L11_bool_binop_done:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+0965: return _pow(a.numerator, a.denominator, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 965, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 965, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = __pyx_f_10quicktions__pow(__pyx_t_3, __pyx_t_2, __pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 965, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0966:
+0967: if bd == 1:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_bd, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 967, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0968: return a ** bn
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = PyNumber_Power(__pyx_v_a, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 968, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0969:
+0970: return a ** (bn / bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 970, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = PyNumber_Power(__pyx_v_a, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 970, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0971:
+0972: def __pos__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_55__pos__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_54__pos__, "+a: Coerces a subclass instance to Fraction"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_54__pos__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_55__pos__(PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__pos__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_54__pos__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_54__pos__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions.Fraction.__pos__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0973: """+a: Coerces a subclass instance to Fraction"""
+0974: if type(a) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_a))) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0975: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_a); __pyx_r = ((PyObject *)__pyx_v_a); goto __pyx_L0;
+0976: return _fraction_from_coprime_ints(a._numerator, a._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __pyx_v_a->_numerator; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_v_a->_denominator; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 976, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0977:
+0978: def __neg__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_57__neg__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_56__neg__, "-a"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_56__neg__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_57__neg__(PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__neg__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_56__neg__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_56__neg__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__neg__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0979: """-a"""
+0980: return _fraction_from_coprime_ints(-a._numerator, a._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Negative(__pyx_v_a->_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_v_a->_denominator; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_1, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0981:
+0982: def __abs__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_59__abs__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_58__abs__, "abs(a)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_58__abs__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_59__abs__(PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__abs__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_58__abs__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_58__abs__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__abs__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0983: """abs(a)"""
+0984: return _fraction_from_coprime_ints(abs(a._numerator), a._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_a->_numerator; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 984, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __pyx_v_a->_denominator; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 984, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0985:
+0986: def __int__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_61__int__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_60__int__, "int(a)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_60__int__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_61__int__(PyObject *__pyx_v_a) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__int__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_60__int__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_60__int__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction.__int__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
0987: """int(a)"""
+0988: if a._numerator < 0:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 988, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 988, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0989: return _operator_index(-(-a._numerator // a._denominator))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyNumber_Negative(__pyx_v_a->_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_FloorDivide(__pyx_t_3, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Negative(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_v_10quicktions__operator_index); __pyx_t_4 = __pyx_v_10quicktions__operator_index; __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_3}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0990: else:
+0991: return _operator_index(a._numerator // a._denominator)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyNumber_FloorDivide(__pyx_v_a->_numerator, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 991, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_10quicktions__operator_index); __pyx_t_3 = __pyx_v_10quicktions__operator_index; __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_4}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 991, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
0992:
+0993: def __trunc__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_63__trunc__(PyObject *__pyx_v_a, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_62__trunc__, "math.trunc(a)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_63__trunc__ = {"__trunc__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_63__trunc__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_62__trunc__}; static PyObject *__pyx_pw_10quicktions_8Fraction_63__trunc__(PyObject *__pyx_v_a, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__trunc__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__trunc__", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__trunc__", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_62__trunc__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_62__trunc__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__trunc__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__34 = PyTuple_Pack(1, __pyx_n_s_a); if (unlikely(!__pyx_tuple__34)) __PYX_ERR(0, 993, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__34); __Pyx_GIVEREF(__pyx_tuple__34); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_63__trunc__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___trunc, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__35)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 993, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_trunc, __pyx_t_3) < 0) __PYX_ERR(0, 993, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_trunc, 993, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 993, __pyx_L1_error)
0994: """math.trunc(a)"""
+0995: if a._numerator < 0:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 995, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 995, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0996: return -(-a._numerator // a._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Negative(__pyx_v_a->_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 996, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_FloorDivide(__pyx_t_1, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 996, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Negative(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 996, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0997: else:
+0998: return a._numerator // a._denominator
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_FloorDivide(__pyx_v_a->_numerator, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 998, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
0999:
+1000: def __floor__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_65__floor__(PyObject *__pyx_v_a, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_64__floor__, "math.floor(a)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_65__floor__ = {"__floor__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_65__floor__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_64__floor__}; static PyObject *__pyx_pw_10quicktions_8Fraction_65__floor__(PyObject *__pyx_v_a, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__floor__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__floor__", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__floor__", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_64__floor__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_64__floor__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__floor__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_65__floor__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___floor, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__36)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1000, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_floor, __pyx_t_3) < 0) __PYX_ERR(0, 1000, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__36 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_floor, 1000, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__36)) __PYX_ERR(0, 1000, __pyx_L1_error)
1001: """math.floor(a)"""
+1002: return a.numerator // a.denominator
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1002, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1002, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_FloorDivide(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1002, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1003:
+1004: def __ceil__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_67__ceil__(PyObject *__pyx_v_a, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_66__ceil__, "math.ceil(a)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_67__ceil__ = {"__ceil__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_67__ceil__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_66__ceil__}; static PyObject *__pyx_pw_10quicktions_8Fraction_67__ceil__(PyObject *__pyx_v_a, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__ceil__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__ceil__", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__ceil__", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_66__ceil__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_66__ceil__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__ceil__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_67__ceil__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___ceil, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1004, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_ceil, __pyx_t_3) < 0) __PYX_ERR(0, 1004, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__37 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__34, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_ceil, 1004, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 1004, __pyx_L1_error)
1005: """math.ceil(a)"""
1006: # The negations cleverly convince floordiv to return the ceiling.
+1007: return -(-a.numerator // a.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1007, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_FloorDivide(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1007, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Negative(__pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1008:
+1009: def __round__(self, ndigits=None):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_69__round__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_68__round__, "round(self, ndigits)\n\n Rounds half toward even.\n "); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_69__round__ = {"__round__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_69__round__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_68__round__}; static PyObject *__pyx_pw_10quicktions_8Fraction_69__round__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { PyObject *__pyx_v_ndigits = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__round__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_ndigits,0}; PyObject* values[1] = {0}; values[0] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None)); if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (kw_args > 0) { PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_ndigits); if (value) { values[0] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1009, __pyx_L3_error) } } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__round__") < 0)) __PYX_ERR(0, 1009, __pyx_L3_error) } } else { switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_ndigits = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__round__", 0, 0, 1, __pyx_nargs); __PYX_ERR(0, 1009, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions.Fraction.__round__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_68__round__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self), __pyx_v_ndigits); /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_68__round__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_ndigits) { PyObject *__pyx_v_floor = NULL; PyObject *__pyx_v_remainder = NULL; PyObject *__pyx_v_shift = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction.__round__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_floor); __Pyx_XDECREF(__pyx_v_remainder); __Pyx_XDECREF(__pyx_v_shift); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__38 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_ndigits, __pyx_n_s_floor_2, __pyx_n_s_remainder, __pyx_n_s_shift); if (unlikely(!__pyx_tuple__38)) __PYX_ERR(0, 1009, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__38); __Pyx_GIVEREF(__pyx_tuple__38); __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__38, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_round_2, 1009, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 1009, __pyx_L1_error) /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_69__round__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___round, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__39)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1009, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_tuple__40); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_round_2, __pyx_t_3) < 0) __PYX_ERR(0, 1009, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_tuple__40 = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_tuple__40)) __PYX_ERR(0, 1009, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__40); __Pyx_GIVEREF(__pyx_tuple__40);
1010: """round(self, ndigits)
1011:
1012: Rounds half toward even.
1013: """
+1014: if ndigits is None:
__pyx_t_1 = (__pyx_v_ndigits == Py_None); if (__pyx_t_1) { /* … */ }
+1015: floor, remainder = divmod(self.numerator, self.denominator)
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Divmod(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_4))) || (PyList_CheckExact(__pyx_t_4))) { PyObject* sequence = __pyx_t_4; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 1015, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_3 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_3 = PyList_GET_ITEM(sequence, 0); __pyx_t_2 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); #else __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { Py_ssize_t index = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_6 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_2 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); if (__Pyx_IternextUnpackEndCheck(__pyx_t_6(__pyx_t_5), 2) < 0) __PYX_ERR(0, 1015, __pyx_L1_error) __pyx_t_6 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L5_unpacking_done; __pyx_L4_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 1015, __pyx_L1_error) __pyx_L5_unpacking_done:; } __pyx_v_floor = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_remainder = __pyx_t_2; __pyx_t_2 = 0;
+1016: if remainder * 2 < self.denominator:
__pyx_t_4 = __Pyx_PyInt_MultiplyObjC(__pyx_v_remainder, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1016, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1016, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyObject_RichCompare(__pyx_t_4, __pyx_t_2, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1016, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1016, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+1017: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
+1018: elif remainder * 2 > self.denominator:
__pyx_t_3 = __Pyx_PyInt_MultiplyObjC(__pyx_v_remainder, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_2, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1019: return floor + 1
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_floor, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1019, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1020: # Deal with the half case:
+1021: elif floor % 2 == 0:
__pyx_t_4 = __Pyx_PyInt_RemainderObjC(__pyx_v_floor, __pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1021, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_4, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1021, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1022: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
1023: else:
+1024: return floor + 1
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyInt_AddObjC(__pyx_v_floor, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1024, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1025: shift = pow10(abs(<long long>ndigits))
__pyx_t_7 = __Pyx_PyInt_As_PY_LONG_LONG(__pyx_v_ndigits); if (unlikely((__pyx_t_7 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 1025, __pyx_L1_error) __pyx_t_8 = __Pyx_abs_longlong(((PY_LONG_LONG)__pyx_t_7)); __pyx_t_4 = __pyx_f_10quicktions_pow10(__pyx_t_8); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1025, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_shift = __pyx_t_4; __pyx_t_4 = 0;
1026: # See _operator_fallbacks.forward to check that the results of
1027: # these operations will always be Fraction and therefore have
1028: # round().
+1029: if ndigits > 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_ndigits, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1029, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1029, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1030: return Fraction(round(self * shift), shift)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyNumber_Multiply(((PyObject *)__pyx_v_self), __pyx_v_shift); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_round, __pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1030, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error); __Pyx_INCREF(__pyx_v_shift); __Pyx_GIVEREF(__pyx_v_shift); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_v_shift)) __PYX_ERR(0, 1030, __pyx_L1_error); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_10quicktions_Fraction), __pyx_t_4, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1031: else:
+1032: return Fraction(round(self / shift) * shift)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_self), __pyx_v_shift); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_round, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1032, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Multiply(__pyx_t_4, __pyx_v_shift); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1032, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)__pyx_ptype_10quicktions_Fraction), __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1032, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
1033:
+1034: def __float__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_71__float__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_70__float__, "float(self) = self.numerator / self.denominator\n\n It's important that this conversion use the integer's \"true\"\n division rather than casting one side to float before dividing\n so that ratios of huge integers convert without overflowing.\n "); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_70__float__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_71__float__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__float__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_70__float__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_70__float__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions.Fraction.__float__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1035: """float(self) = self.numerator / self.denominator
1036:
1037: It's important that this conversion use the integer's "true"
1038: division rather than casting one side to float before dividing
1039: so that ratios of huge integers convert without overflowing.
1040: """
+1041: return _as_float(self.numerator, self.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1041, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1041, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_f_10quicktions__as_float(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1041, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1042:
1043: # Concrete implementations of Complex abstract methods.
+1044: def __complex__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_73__complex__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_72__complex__, "complex(self) == complex(float(self), 0)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_73__complex__ = {"__complex__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_73__complex__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_72__complex__}; static PyObject *__pyx_pw_10quicktions_8Fraction_73__complex__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__complex__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__complex__", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__complex__", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_72__complex__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_72__complex__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__complex__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_73__complex__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___complex, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__41)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_complex, __pyx_t_3) < 0) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_complex, 1044, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(0, 1044, __pyx_L1_error)
1045: """complex(self) == complex(float(self), 0)"""
+1046: return complex(float(self))
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyNumber_Float(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1046, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyComplex_Type)), __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1046, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1047:
1048: # == +self
+1049: real = property(__pos__, doc="Real numbers are their real component.")
__Pyx_GetNameInClass(__pyx_t_3, (PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_pos); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1049, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1049, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3)) __PYX_ERR(0, 1049, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1049, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_doc, __pyx_kp_s_Real_numbers_are_their_real_comp) < 0) __PYX_ERR(0, 1049, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_property, __pyx_t_9, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1049, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_real, __pyx_t_2) < 0) __PYX_ERR(0, 1049, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction);
1050:
1051: # == 0
+1052: @property
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_4imag_1__get__(PyObject *__pyx_v_self); /*proto*/ static PyObject *__pyx_pw_10quicktions_8Fraction_4imag_1__get__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__get__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_4imag___get__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_4imag___get__(CYTHON_UNUSED struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1053: def imag(self):
1054: "Real numbers have no imaginary component."
+1055: return 0
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_int_0); __pyx_r = __pyx_int_0; goto __pyx_L0;
1056:
+1057: def conjugate(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_75conjugate(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_74conjugate, "Conjugate is a no-op for Reals."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_75conjugate = {"conjugate", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_75conjugate, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_74conjugate}; static PyObject *__pyx_pw_10quicktions_8Fraction_75conjugate(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("conjugate (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("conjugate", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "conjugate", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_74conjugate(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_74conjugate(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("quicktions.Fraction.conjugate", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_75conjugate, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_conjugate, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__42)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_conjugate, __pyx_t_2) < 0) __PYX_ERR(0, 1057, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__42 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_conjugate, 1057, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__42)) __PYX_ERR(0, 1057, __pyx_L1_error)
1058: """Conjugate is a no-op for Reals."""
+1059: return +self
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Positive(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1059, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1060:
+1061: def __hash__(self):
/* Python wrapper */ static Py_hash_t __pyx_pw_10quicktions_8Fraction_77__hash__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_76__hash__, "hash(self)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_76__hash__; #endif static Py_hash_t __pyx_pw_10quicktions_8Fraction_77__hash__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; Py_hash_t __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__hash__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_76__hash__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static Py_hash_t __pyx_pf_10quicktions_8Fraction_76__hash__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { Py_hash_t __pyx_v_result; PyObject *__pyx_v_float_val = NULL; PyObject *__pyx_v_dinv = NULL; Py_hash_t __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions.Fraction.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_float_val); __Pyx_XDECREF(__pyx_v_dinv); if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; __Pyx_RefNannyFinishContext(); return __pyx_r; }
1062: """hash(self)"""
+1063: if self._hash != -1:
__pyx_t_1 = (__pyx_v_self->_hash != -1L); if (__pyx_t_1) { /* … */ }
+1064: return self._hash
__pyx_r = __pyx_v_self->_hash; goto __pyx_L0;
1065:
1066: cdef Py_hash_t result
1067:
1068: # Py2 and Py3 use completely different hash functions, we provide both
+1069: if PY_MAJOR_VERSION == 2:
__pyx_t_1 = (PY_MAJOR_VERSION == 2); if (__pyx_t_1) { /* … */ }
+1070: if self._denominator == 1:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_self->_denominator, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1070, __pyx_L1_error) if (__pyx_t_1) { /* … */ goto __pyx_L5; }
1071: # Get integers right.
+1072: result = hash(self._numerator)
__pyx_t_2 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyObject_Hash(__pyx_t_2); if (unlikely(__pyx_t_3 == ((Py_hash_t)-1))) __PYX_ERR(0, 1072, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_result = __pyx_t_3;
1073: else:
1074: # Expensive check, but definitely correct.
+1075: float_val = _as_float(self._numerator, self._denominator)
/*else*/ { __pyx_t_2 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_4); __pyx_t_5 = __pyx_f_10quicktions__as_float(__pyx_t_2, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1075, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_float_val = __pyx_t_5; __pyx_t_5 = 0;
+1076: if self == float_val:
__pyx_t_5 = PyObject_RichCompare(((PyObject *)__pyx_v_self), __pyx_v_float_val, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1076, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1076, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ goto __pyx_L6; }
+1077: result = hash(float_val)
__pyx_t_3 = PyObject_Hash(__pyx_v_float_val); if (unlikely(__pyx_t_3 == ((Py_hash_t)-1))) __PYX_ERR(0, 1077, __pyx_L1_error) __pyx_v_result = __pyx_t_3;
1078: else:
1079: # Use tuple's hash to avoid a high collision rate on
1080: # simple fractions.
+1081: result = hash((self._numerator, self._denominator))
/*else*/ { __pyx_t_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_INCREF(__pyx_v_self->_numerator); __Pyx_GIVEREF(__pyx_v_self->_numerator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_self->_numerator)) __PYX_ERR(0, 1081, __pyx_L1_error); __Pyx_INCREF(__pyx_v_self->_denominator); __Pyx_GIVEREF(__pyx_v_self->_denominator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_v_self->_denominator)) __PYX_ERR(0, 1081, __pyx_L1_error); __pyx_t_3 = PyObject_Hash(__pyx_t_5); if (unlikely(__pyx_t_3 == ((Py_hash_t)-1))) __PYX_ERR(0, 1081, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_result = __pyx_t_3; } __pyx_L6:; } __pyx_L5:;
+1082: self._hash = result
__pyx_v_self->_hash = __pyx_v_result;
+1083: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
1084:
1085: # In order to make sure that the hash of a Fraction agrees
1086: # with the hash of a numerically equal integer, float or
1087: # Decimal instance, we follow the rules for numeric hashes
1088: # outlined in the documentation. (See library docs, 'Built-in
1089: # Types').
1090:
+1091: if PY_VERSION_HEX < 0x030800B1:
__pyx_t_1 = (PY_VERSION_HEX < 0x030800B1); if (__pyx_t_1) { /* … */ goto __pyx_L7; }
1092: # dinv is the inverse of self._denominator modulo the prime
1093: # _PyHASH_MODULUS, or 0 if self._denominator is divisible by
1094: # _PyHASH_MODULUS.
+1095: dinv = pow(self._denominator, _PyHASH_MODULUS - 2, _PyHASH_MODULUS)
__pyx_t_5 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyInt_FromHash_t((__pyx_v_10quicktions__PyHASH_MODULUS - 2)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1095, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyInt_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1095, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyNumber_Power(__pyx_t_5, __pyx_t_4, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1095, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_dinv = __pyx_t_6; __pyx_t_6 = 0;
+1096: if not dinv:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dinv); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1096, __pyx_L1_error) __pyx_t_7 = (!__pyx_t_1); if (__pyx_t_7) { /* … */ goto __pyx_L8; }
+1097: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF;
1098: else:
+1099: result = abs(self._numerator) * dinv % _PyHASH_MODULUS
/*else*/ { __pyx_t_6 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1099, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyNumber_Multiply(__pyx_t_2, __pyx_v_dinv); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1099, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1099, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyNumber_Remainder(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1099, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_3 = __Pyx_PyInt_AsHash_t(__pyx_t_4); if (unlikely((__pyx_t_3 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1099, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_result = __pyx_t_3; } __pyx_L8:;
1100: else:
1101: # Py3.8+
+1102: try:
/*else*/ { { /*try:*/ { /* … */ } /* … */ __pyx_L11_except_error:; __Pyx_XGIVEREF(__pyx_t_8); __Pyx_XGIVEREF(__pyx_t_9); __Pyx_XGIVEREF(__pyx_t_10); __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); goto __pyx_L1_error; __pyx_L10_exception_handled:; __Pyx_XGIVEREF(__pyx_t_8); __Pyx_XGIVEREF(__pyx_t_9); __Pyx_XGIVEREF(__pyx_t_10); __Pyx_ExceptionReset(__pyx_t_8, __pyx_t_9, __pyx_t_10); __pyx_L14_try_end:; } } __pyx_L7:;
+1103: dinv = pow(self._denominator, -1, _PyHASH_MODULUS)
__pyx_t_4 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyInt_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1103, __pyx_L9_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyNumber_Power(__pyx_t_4, __pyx_int_neg_1, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1103, __pyx_L9_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_dinv = __pyx_t_6; __pyx_t_6 = 0;
+1104: except ValueError:
__pyx_t_11 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); if (__pyx_t_11) { __Pyx_AddTraceback("quicktions.Fraction.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_2, &__pyx_t_4) < 0) __PYX_ERR(0, 1104, __pyx_L11_except_error) __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_4);
1105: # ValueError means there is no modular inverse.
+1106: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L10_exception_handled; } goto __pyx_L11_except_error;
1107: else:
1108: # The general algorithm now specifies that the absolute value of
1109: # the hash is
1110: # (|N| * dinv) % P
1111: # where N is self._numerator and P is _PyHASH_MODULUS. That's
1112: # optimized here in two ways: first, for a non-negative int i,
1113: # hash(i) == i % P, but the int hash implementation doesn't need
1114: # to divide, and is faster than doing % P explicitly. So we do
1115: # hash(|N| * dinv)
1116: # instead. Second, N is unbounded, so its product with dinv may
1117: # be arbitrarily expensive to compute. The final answer is the
1118: # same if we use the bounded |N| % P instead, which can again
1119: # be done with an int hash() call. If 0 <= i < P, hash(i) == i,
1120: # so this nested hash() call wastes a bit of time making a
1121: # redundant copy when |N| < P, but can save an arbitrarily large
1122: # amount of computation for large |N|.
+1123: result = hash(hash(abs(self._numerator)) * dinv)
/*else:*/ { __pyx_t_6 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1123, __pyx_L11_except_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_3 = PyObject_Hash(__pyx_t_2); if (unlikely(__pyx_t_3 == ((Py_hash_t)-1))) __PYX_ERR(0, 1123, __pyx_L11_except_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyInt_FromHash_t(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1123, __pyx_L11_except_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyNumber_Multiply(__pyx_t_2, __pyx_v_dinv); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1123, __pyx_L11_except_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_3 = PyObject_Hash(__pyx_t_6); if (unlikely(__pyx_t_3 == ((Py_hash_t)-1))) __PYX_ERR(0, 1123, __pyx_L11_except_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_result = __pyx_t_3; } __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L14_try_end; __pyx_L9_error:; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
1124:
+1125: if self._numerator < 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_self->_numerator, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1125, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1125, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_7) { /* … */ }
+1126: result = -result
__pyx_v_result = (-__pyx_v_result);
+1127: if result == -1:
__pyx_t_7 = (__pyx_v_result == -1L); if (__pyx_t_7) { /* … */ }
+1128: result = -2
__pyx_v_result = -2L;
+1129: self._hash = result
__pyx_v_self->_hash = __pyx_v_result;
+1130: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
1131:
+1132: def __richcmp__(a, b, int op):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_79__richcmp__(PyObject *__pyx_v_a, PyObject *__pyx_v_b, int __pyx_v_op); /*proto*/ static PyObject *__pyx_pw_10quicktions_8Fraction_79__richcmp__(PyObject *__pyx_v_a, PyObject *__pyx_v_b, int __pyx_v_op) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__richcmp__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_78__richcmp__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), ((PyObject *)__pyx_v_b), ((int)__pyx_v_op)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_78__richcmp__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b, int __pyx_v_op) { PyObject *__pyx_v_result = NULL; PyObject *__pyx_r = NULL; __Pyx_INCREF((PyObject *)__pyx_v_a); __Pyx_INCREF(__pyx_v_b); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions.Fraction.__richcmp__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_result); __Pyx_XDECREF((PyObject *)__pyx_v_a); __Pyx_XDECREF(__pyx_v_b); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1133: if isinstance(a, Fraction):
__pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_a), __pyx_ptype_10quicktions_Fraction);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1134: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ); if (__pyx_t_1) { /* … */ }
+1135: return (<Fraction>a)._eq(b)
__Pyx_XDECREF(__pyx_r); #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_2 = __pyx_f_10quicktions_8Fraction__eq(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), __pyx_v_b); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1135, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1136: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE); if (__pyx_t_1) { /* … */ }
+1137: result = (<Fraction>a)._eq(b)
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_2 = __pyx_f_10quicktions_8Fraction__eq(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), __pyx_v_b); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1137, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0;
+1138: return NotImplemented if result is NotImplemented else not result
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = (__pyx_v_result == __pyx_builtin_NotImplemented); if (__pyx_t_1) { __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_t_2 = __pyx_builtin_NotImplemented; } else { __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1138, __pyx_L1_error) __pyx_t_4 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1138, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __pyx_t_4; __pyx_t_4 = 0; } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1139: else:
+1140: a, b = b, a
/*else*/ { if (!(likely(((__pyx_v_b) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_b, __pyx_ptype_10quicktions_Fraction))))) __PYX_ERR(0, 1140, __pyx_L1_error) __pyx_t_2 = __pyx_v_b; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = ((PyObject *)__pyx_v_a); __Pyx_INCREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_a, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_4); __pyx_t_4 = 0;
+1141: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ); if (__pyx_t_1) { /* … */ }
+1142: return (<Fraction>a)._eq(b)
__Pyx_XDECREF(__pyx_r); #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_4 = __pyx_f_10quicktions_8Fraction__eq(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), __pyx_v_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1142, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1143: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE); if (__pyx_t_1) { /* … */ }
+1144: result = (<Fraction>a)._eq(b)
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_4 = __pyx_f_10quicktions_8Fraction__eq(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), __pyx_v_b); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1144, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_4); __pyx_v_result = __pyx_t_4; __pyx_t_4 = 0;
+1145: return NotImplemented if result is NotImplemented else not result
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = (__pyx_v_result == __pyx_builtin_NotImplemented); if (__pyx_t_1) { __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_t_4 = __pyx_builtin_NotImplemented; } else { __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_result); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1145, __pyx_L1_error) __pyx_t_2 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __pyx_t_2; __pyx_t_2 = 0; } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1146: elif op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1147: op = Py_GE
__pyx_v_op = Py_GE;
+1148: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1149: op = Py_LE
__pyx_v_op = Py_LE;
+1150: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1151: op = Py_GT
__pyx_v_op = Py_GT;
+1152: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1153: op = Py_LT
__pyx_v_op = Py_LT;
1154: else:
+1155: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; } __pyx_L5:; } __pyx_L3:;
+1156: return (<Fraction>a)._richcmp(b, op)
__Pyx_XDECREF(__pyx_r); #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_4 = __pyx_f_10quicktions_8Fraction__richcmp(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), __pyx_v_b, __pyx_v_op); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1156, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1157:
1158: @cython.final
+1159: cdef _eq(a, b):
static PyObject *__pyx_f_10quicktions_8Fraction__eq(struct __pyx_obj_10quicktions_Fraction *__pyx_v_a, PyObject *__pyx_v_b) { PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_b); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction._eq", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_b); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1160: if type(b) is int or type(b) is long:
__pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)(&PyInt_Type))); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)(&PyLong_Type))); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+1161: return a._numerator == b and a._denominator == 1
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_v_b, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1161, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1161, __pyx_L1_error) if (__pyx_t_1) { __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L6_bool_binop_done; } __pyx_t_4 = __Pyx_PyInt_EqObjC(__pyx_v_a->_denominator, __pyx_int_1, 1, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_L6_bool_binop_done:; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1162: if type(b) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1163: return (a._numerator == (<Fraction>b)._numerator and
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyObject_RichCompare(__pyx_v_a->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_numerator, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1163, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1163, __pyx_L1_error) if (__pyx_t_1) { __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L9_bool_binop_done; }
+1164: a._denominator == (<Fraction>b)._denominator)
__pyx_t_4 = PyObject_RichCompare(__pyx_v_a->_denominator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_denominator, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1164, __pyx_L1_error) __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_L9_bool_binop_done:; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1165: if isinstance(b, Rational):
__pyx_t_3 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_3); __pyx_t_1 = PyObject_IsInstance(__pyx_v_b, __pyx_t_3); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1165, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+1166: return (a._numerator == b.numerator and
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1166, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1166, __pyx_L1_error) if (__pyx_t_1) { __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = __pyx_t_5; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L12_bool_binop_done; }
+1167: a._denominator == b.denominator)
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = PyObject_RichCompare(__pyx_v_a->_denominator, __pyx_t_5, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1167, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_L12_bool_binop_done:; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1168: if isinstance(b, Complex) and b.imag == 0:
__pyx_t_3 = __pyx_v_10quicktions_Complex; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = PyObject_IsInstance(__pyx_v_b, __pyx_t_3); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 1168, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L15_bool_binop_done; } __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_imag); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = (__Pyx_PyInt_BoolEqObjC(__pyx_t_3, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1168, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L15_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+1169: b = b.real
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_real); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1169, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_3); __pyx_t_3 = 0;
+1170: if isinstance(b, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1171: if math.isnan(b) or math.isinf(b):
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_n_s_isnan); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_b}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L19_bool_binop_done; } __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_n_s_isinf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_b}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L19_bool_binop_done:; if (__pyx_t_1) { /* … */ }
1172: # comparisons with an infinity or nan should behave in
1173: # the same way for any finite a, so treat a as zero.
+1174: return 0.0 == b
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyFloat_EqCObj(__pyx_float_0_0, __pyx_v_b, 0.0, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1175: else:
+1176: return a == a.from_float(b)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_n_s_from_float); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_b}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_4 = PyObject_RichCompare(((PyObject *)__pyx_v_a), __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1176, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1177: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
1178:
1179: @cython.final
+1180: cdef _richcmp(self, other, int op):
static PyObject *__pyx_f_10quicktions_8Fraction__richcmp(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, PyObject *__pyx_v_other, int __pyx_v_op) { PyObject *__pyx_v_a = NULL; PyObject *__pyx_v_b = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction._richcmp", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_a); __Pyx_XDECREF(__pyx_v_b); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1181: """Helper for comparison operators, for internal use only.
1182:
1183: Implement comparison between a Rational instance `self`, and
1184: either another Rational instance or a float `other`. If
1185: `other` is not a Rational instance or a float, return
1186: NotImplemented. `op` should be one of the six standard
1187: comparison operators.
1188:
1189: """
1190: # convert other to a Rational instance where reasonable.
+1191: if isinstance(other, (int, long)):
__pyx_t_2 = PyInt_Check(__pyx_v_other); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = PyLong_Check(__pyx_v_other); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1192: a = self._numerator
__pyx_t_3 = __pyx_v_self->_numerator;
__Pyx_INCREF(__pyx_t_3);
__pyx_v_a = __pyx_t_3;
__pyx_t_3 = 0;
+1193: b = self._denominator * other
__pyx_t_3 = PyNumber_Multiply(__pyx_v_self->_denominator, __pyx_v_other); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_b = __pyx_t_3; __pyx_t_3 = 0;
+1194: elif type(other) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_other)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1195: a = self._numerator * (<Fraction>other)._denominator
__pyx_t_3 = PyNumber_Multiply(__pyx_v_self->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_other)->_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1195, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_a = __pyx_t_3; __pyx_t_3 = 0;
+1196: b = self._denominator * (<Fraction>other)._numerator
__pyx_t_3 = PyNumber_Multiply(__pyx_v_self->_denominator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_other)->_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_b = __pyx_t_3; __pyx_t_3 = 0;
+1197: elif isinstance(other, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1198: if math.isnan(other) or math.isinf(other):
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_n_s_isnan); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_other}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L7_bool_binop_done; } __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_n_s_isinf); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_other}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_2; __pyx_L7_bool_binop_done:; if (__pyx_t_1) { /* … */ goto __pyx_L6; }
+1199: a, b = 0.0, other # Comparison to 0.0 is just as good as any.
__pyx_t_3 = __pyx_float_0_0; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = __pyx_v_other; __Pyx_INCREF(__pyx_t_4); __pyx_v_a = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_b = __pyx_t_4; __pyx_t_4 = 0;
1200: else:
+1201: return self._richcmp(self.from_float(other), op)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_from_float); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1201, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_other}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1201, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" __pyx_t_3 = __pyx_f_10quicktions_8Fraction__richcmp(__pyx_v_self, __pyx_t_4, __pyx_v_op); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1201, __pyx_L1_error) #pragma GCC diagnostic pop __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; } __pyx_L6:;
+1202: elif isinstance(other, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_3 = __pyx_v_10quicktions_Rational; __pyx_t_2 = __Pyx_TypeCheck(__pyx_v_other, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L9_bool_binop_done; } __pyx_t_2 = PyObject_IsInstance(__pyx_v_other, __pyx_t_3); __pyx_t_1 = __pyx_t_2; __pyx_L9_bool_binop_done:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1203: a = self._numerator * other.denominator
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Multiply(__pyx_v_self->_numerator, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_a = __pyx_t_4; __pyx_t_4 = 0;
+1204: b = self._denominator * other.numerator
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_n_s_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Multiply(__pyx_v_self->_denominator, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_b = __pyx_t_3; __pyx_t_3 = 0;
1205: else:
1206: # comparisons with complex should raise a TypeError, for consistency
1207: # with int<->complex, float<->complex, and complex<->complex comparisons.
+1208: if PY_MAJOR_VERSION < 3 and isinstance(other, complex):
/*else*/ {
__pyx_t_2 = (PY_MAJOR_VERSION < 3);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L12_bool_binop_done;
}
__pyx_t_2 = PyComplex_Check(__pyx_v_other);
__pyx_t_1 = __pyx_t_2;
__pyx_L12_bool_binop_done:;
if (unlikely(__pyx_t_1)) {
/* … */
}
+1209: raise TypeError("no ordering relation is defined for complex numbers")
__pyx_t_3 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__15, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1209, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(0, 1209, __pyx_L1_error) /* … */ __pyx_tuple__15 = PyTuple_Pack(1, __pyx_kp_s_no_ordering_relation_is_defined); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 1209, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__15); __Pyx_GIVEREF(__pyx_tuple__15);
+1210: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; } __pyx_L3:;
1211:
+1212: if op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT); if (__pyx_t_1) { /* … */ }
+1213: return a < b
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1213, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1214: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT); if (__pyx_t_1) { /* … */ }
+1215: return a > b
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_GT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1215, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1216: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE); if (__pyx_t_1) { /* … */ }
+1217: return a <= b
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_LE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1217, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1218: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE); if (__pyx_t_1) { /* … */ }
+1219: return a >= b
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1219, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1220: else:
+1221: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1222:
+1223: def __bool__(self):
/* Python wrapper */ static int __pyx_pw_10quicktions_8Fraction_81__bool__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_10quicktions_8Fraction_81__bool__(PyObject *__pyx_v_self) { CYTHON_UNUSED PyObject *const *__pyx_kwvalues; int __pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__bool__ (wrapper)", 0); __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); __pyx_r = __pyx_pf_10quicktions_8Fraction_80__bool__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_10quicktions_8Fraction_80__bool__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { int __pyx_r; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_AddTraceback("quicktions.Fraction.__bool__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; return __pyx_r; }
1224: """a != 0"""
1225: # Use bool() because (a._numerator != 0) can return an
1226: # object which is not a bool.
1227: # See https://bugs.python.org/issue39274
+1228: return bool(self._numerator)
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->_numerator); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1228, __pyx_L1_error) __pyx_r = (!(!__pyx_t_1)); goto __pyx_L0;
1229:
1230: # support for pickling, copy, and deepcopy
1231:
+1232: def __reduce__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_83__reduce__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_10quicktions_8Fraction_83__reduce__ = {"__reduce__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_83__reduce__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10quicktions_8Fraction_83__reduce__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__reduce__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__reduce__", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce__", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_82__reduce__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_82__reduce__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_AddTraceback("quicktions.Fraction.__reduce__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_83__reduce__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___reduce, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__43)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1232, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_reduce, __pyx_t_2) < 0) __PYX_ERR(0, 1232, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__43 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_reduce, 1232, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 1232, __pyx_L1_error)
+1233: return (type(self), (self._numerator, self._denominator))
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_self->_numerator); __Pyx_GIVEREF(__pyx_v_self->_numerator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->_numerator)) __PYX_ERR(0, 1233, __pyx_L1_error); __Pyx_INCREF(__pyx_v_self->_denominator); __Pyx_GIVEREF(__pyx_v_self->_denominator); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->_denominator)) __PYX_ERR(0, 1233, __pyx_L1_error); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(0, 1233, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1)) __PYX_ERR(0, 1233, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1234:
+1235: def __copy__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_85__copy__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_10quicktions_8Fraction_85__copy__ = {"__copy__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_85__copy__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10quicktions_8Fraction_85__copy__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__copy__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); if (unlikely(__pyx_nargs > 0)) { __Pyx_RaiseArgtupleInvalid("__copy__", 1, 0, 0, __pyx_nargs); return NULL;} if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__copy__", 0))) return NULL; __pyx_r = __pyx_pf_10quicktions_8Fraction_84__copy__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_84__copy__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions.Fraction.__copy__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_85__copy__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___copy, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__44)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1235, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_copy, __pyx_t_2) < 0) __PYX_ERR(0, 1235, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__44 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__26, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_copy, 1235, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 1235, __pyx_L1_error)
+1236: if type(self) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1237: return self # I'm immutable; therefore I am my own clone
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_self); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0;
+1238: return type(self)(self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __pyx_t_3 = ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))); __pyx_t_4 = NULL; __pyx_t_5 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_5 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_v_self->_numerator, __pyx_v_self->_denominator}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 2+__pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1239:
+1240: def __deepcopy__(self, memo):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_87__deepcopy__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ); /*proto*/ static PyMethodDef __pyx_mdef_10quicktions_8Fraction_87__deepcopy__ = {"__deepcopy__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_87__deepcopy__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10quicktions_8Fraction_87__deepcopy__(PyObject *__pyx_v_self, #if CYTHON_METH_FASTCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { CYTHON_UNUSED PyObject *__pyx_v_memo = 0; #if !CYTHON_METH_FASTCALL CYTHON_UNUSED Py_ssize_t __pyx_nargs; #endif CYTHON_UNUSED PyObject *const *__pyx_kwvalues; PyObject *__pyx_r = 0; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__deepcopy__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_MACROS __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); #else __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; #endif #endif __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); { PyObject **__pyx_pyargnames[] = {&__pyx_n_s_memo,0}; PyObject* values[1] = {0}; if (__pyx_kwds) { Py_ssize_t kw_args; switch (__pyx_nargs) { case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); switch (__pyx_nargs) { case 0: if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_memo)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 1240, __pyx_L3_error) else goto __pyx_L5_argtuple_error; } if (unlikely(kw_args > 0)) { const Py_ssize_t kwd_pos_args = __pyx_nargs; if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__deepcopy__") < 0)) __PYX_ERR(0, 1240, __pyx_L3_error) } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); } __pyx_v_memo = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__deepcopy__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1240, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_AddTraceback("quicktions.Fraction.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_86__deepcopy__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self), __pyx_v_memo); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ { Py_ssize_t __pyx_temp; for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); } } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_86__deepcopy__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v_memo) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions.Fraction.__deepcopy__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__45 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_memo); if (unlikely(!__pyx_tuple__45)) __PYX_ERR(0, 1240, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__45); __Pyx_GIVEREF(__pyx_tuple__45); /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_87__deepcopy__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___deepcopy, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__46)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1240, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_deepcopy, __pyx_t_2) < 0) __PYX_ERR(0, 1240, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction);
+1241: if type(self) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1242: return self # My components are also immutable
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_self); __pyx_r = ((PyObject *)__pyx_v_self); goto __pyx_L0;
+1243: return type(self)(self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __pyx_t_3 = ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))); __pyx_t_4 = NULL; __pyx_t_5 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_4)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_5 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_v_self->_numerator, __pyx_v_self->_denominator}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 2+__pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1244:
1245:
1246: # Register with Python's numerical tower.
+1247: Rational.register(Fraction)
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_Rational, __pyx_n_s_register); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1247, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1247, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1248:
1249:
+1250: cdef _fraction_from_coprime_ints(numerator, denominator, cls=None):
static PyObject *__pyx_f_10quicktions__fraction_from_coprime_ints(PyObject *__pyx_v_numerator, PyObject *__pyx_v_denominator, struct __pyx_opt_args_10quicktions__fraction_from_coprime_ints *__pyx_optional_args) { PyObject *__pyx_v_cls = ((PyObject *)Py_None); struct __pyx_obj_10quicktions_Fraction *__pyx_v_obj = 0; PyObject *__pyx_r = NULL; if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_cls = __pyx_optional_args->cls; } } /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions._fraction_from_coprime_ints", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF((PyObject *)__pyx_v_obj); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ struct __pyx_opt_args_10quicktions__fraction_from_coprime_ints { int __pyx_n; PyObject *cls; };
1251: """Convert a pair of ints to a rational number, for internal use.
1252:
1253: The ratio of integers should be in lowest terms and the denominator
1254: should be positive.
1255: """
1256: cdef Fraction obj
+1257: if cls is None or cls is Fraction:
__pyx_t_2 = (__pyx_v_cls == Py_None); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L4_bool_binop_done; } __pyx_t_2 = (__pyx_v_cls == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1258: obj = Fraction.__new__(Fraction, NOINIT, NOINIT)
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1258, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_10quicktions_NOINIT); __Pyx_GIVEREF(__pyx_v_10quicktions_NOINIT); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_10quicktions_NOINIT)) __PYX_ERR(0, 1258, __pyx_L1_error); __Pyx_INCREF(__pyx_v_10quicktions_NOINIT); __Pyx_GIVEREF(__pyx_v_10quicktions_NOINIT); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_10quicktions_NOINIT)) __PYX_ERR(0, 1258, __pyx_L1_error); __pyx_t_4 = ((PyObject *)__pyx_tp_new_10quicktions_Fraction(((PyTypeObject *)__pyx_ptype_10quicktions_Fraction), __pyx_t_3, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1258, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_obj = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_4); __pyx_t_4 = 0;
1259: else:
+1260: obj = super(Fraction, cls).__new__(cls)
/*else*/ { __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF((PyObject *)__pyx_ptype_10quicktions_Fraction); __Pyx_GIVEREF((PyObject *)__pyx_ptype_10quicktions_Fraction); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, ((PyObject *)__pyx_ptype_10quicktions_Fraction))) __PYX_ERR(0, 1260, __pyx_L1_error); __Pyx_INCREF(__pyx_v_cls); __Pyx_GIVEREF(__pyx_v_cls); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_cls)) __PYX_ERR(0, 1260, __pyx_L1_error); __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_super, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_new); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_cls}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1260, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_10quicktions_Fraction))))) __PYX_ERR(0, 1260, __pyx_L1_error) __pyx_v_obj = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_4); __pyx_t_4 = 0; } __pyx_L3:;
+1261: obj._numerator = numerator
__Pyx_INCREF(__pyx_v_numerator); __Pyx_GIVEREF(__pyx_v_numerator); __Pyx_GOTREF(__pyx_v_obj->_numerator); __Pyx_DECREF(__pyx_v_obj->_numerator); __pyx_v_obj->_numerator = __pyx_v_numerator;
+1262: obj._denominator = denominator
__Pyx_INCREF(__pyx_v_denominator); __Pyx_GIVEREF(__pyx_v_denominator); __Pyx_GOTREF(__pyx_v_obj->_denominator); __Pyx_DECREF(__pyx_v_obj->_denominator); __pyx_v_obj->_denominator = __pyx_v_denominator;
+1263: return obj
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_obj); __pyx_r = ((PyObject *)__pyx_v_obj); goto __pyx_L0;
1264:
1265:
+1266: cdef _pow(an, ad, bn, bd):
static PyObject *__pyx_f_10quicktions__pow(PyObject *__pyx_v_an, PyObject *__pyx_v_ad, PyObject *__pyx_v_bn, PyObject *__pyx_v_bd) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("quicktions._pow", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1267: if bd == 1:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_bd, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1267, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
1268: # power = bn
+1269: if bn >= 0:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_bn, __pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1269, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1269, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1270: return _fraction_from_coprime_ints(
__Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1270, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1271: an ** bn,
__pyx_t_2 = PyNumber_Power(__pyx_v_an, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+1272: ad ** bn)
__pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+1273: elif an > 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_an, __pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1273, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1273, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1274: return _fraction_from_coprime_ints(
__Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1274, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1275: ad ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1276: an ** -bn)
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1276, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Power(__pyx_v_an, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1276, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1277: elif an == 0:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_an, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1277, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1278: raise ZeroDivisionError(f'Fraction({ad ** -bn}, 0)')
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = 0; __pyx_t_6 = 127; __Pyx_INCREF(__pyx_kp_u_Fraction); __pyx_t_5 += 9; __Pyx_GIVEREF(__pyx_kp_u_Fraction); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_Fraction); __pyx_t_2 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_t_3, __pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) > __pyx_t_6) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) : __pyx_t_6; __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2); __pyx_t_2 = 0; __Pyx_INCREF(__pyx_kp_u_0); __pyx_t_5 += 4; __Pyx_GIVEREF(__pyx_kp_u_0); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_0); __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ZeroDivisionError, __pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 1278, __pyx_L1_error)
1279: else:
+1280: return _fraction_from_coprime_ints(
/*else*/ { __Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_3, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1281: (-ad) ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Power(__pyx_t_4, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+1282: (-an) ** -bn)
__pyx_t_2 = PyNumber_Negative(__pyx_v_an); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = PyNumber_Power(__pyx_t_2, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1283: else:
1284: # A fractional power will generally produce an
1285: # irrational number.
+1286: return (an / ad) ** (bn / bd)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_v_an, __pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1286, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_7 = __Pyx_PyNumber_Divide(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1286, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_3 = PyNumber_Power(__pyx_t_4, __pyx_t_7, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1286, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; }
1287:
1288:
+1289: cdef _as_float(numerator, denominator):
static PyObject *__pyx_f_10quicktions__as_float(PyObject *__pyx_v_numerator, PyObject *__pyx_v_denominator) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("quicktions._as_float", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1290: return numerator / denominator
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_numerator, __pyx_v_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1291:
1292:
1293: # Rational arithmetic algorithms: Knuth, TAOCP, Volume 2, 4.5.1.
1294: #
1295: # Assume input fractions a and b are normalized.
1296: #
1297: # 1) Consider addition/subtraction.
1298: #
1299: # Let g = gcd(da, db). Then
1300: #
1301: # na nb na*db ± nb*da
1302: # a ± b == -- ± -- == ------------- ==
1303: # da db da*db
1304: #
1305: # na*(db//g) ± nb*(da//g) t
1306: # == ----------------------- == -
1307: # (da*db)//g d
1308: #
1309: # Now, if g > 1, we're working with smaller integers.
1310: #
1311: # Note, that t, (da//g) and (db//g) are pairwise coprime.
1312: #
1313: # Indeed, (da//g) and (db//g) share no common factors (they were
1314: # removed) and da is coprime with na (since input fractions are
1315: # normalized), hence (da//g) and na are coprime. By symmetry,
1316: # (db//g) and nb are coprime too. Then,
1317: #
1318: # gcd(t, da//g) == gcd(na*(db//g), da//g) == 1
1319: # gcd(t, db//g) == gcd(nb*(da//g), db//g) == 1
1320: #
1321: # Above allows us optimize reduction of the result to lowest
1322: # terms. Indeed,
1323: #
1324: # g2 = gcd(t, d) == gcd(t, (da//g)*(db//g)*g) == gcd(t, g)
1325: #
1326: # t//g2 t//g2
1327: # a ± b == ----------------------- == ----------------
1328: # (da//g)*(db//g)*(g//g2) (da//g)*(db//g2)
1329: #
1330: # is a normalized fraction. This is useful because the unnormalized
1331: # denominator d could be much larger than g.
1332: #
1333: # We should special-case g == 1 (and g2 == 1), since 60.8% of
1334: # randomly-chosen integers are coprime:
1335: # https://en.wikipedia.org/wiki/Coprime_integers#Probability_of_coprimality
1336: # Note, that g2 == 1 always for fractions, obtained from floats: here
1337: # g is a power of 2 and the unnormalized numerator t is an odd integer.
1338: #
1339: # 2) Consider multiplication
1340: #
1341: # Let g1 = gcd(na, db) and g2 = gcd(nb, da), then
1342: #
1343: # na*nb na*nb (na//g1)*(nb//g2)
1344: # a*b == ----- == ----- == -----------------
1345: # da*db db*da (db//g1)*(da//g2)
1346: #
1347: # Note, that after divisions we're multiplying smaller integers.
1348: #
1349: # Also, the resulting fraction is normalized, because each of
1350: # two factors in the numerator is coprime to each of the two factors
1351: # in the denominator.
1352: #
1353: # Indeed, pick (na//g1). It's coprime with (da//g2), because input
1354: # fractions are normalized. It's also coprime with (db//g1), because
1355: # common factors are removed by g1 == gcd(na, db).
1356: #
1357: # As for addition/subtraction, we should special-case g1 == 1
1358: # and g2 == 1 for same reason. That happens also for multiplying
1359: # rationals, obtained from floats.
1360:
+1361: cdef _add(na, da, nb, db):
static PyObject *__pyx_f_10quicktions__add(PyObject *__pyx_v_na, PyObject *__pyx_v_da, PyObject *__pyx_v_nb, PyObject *__pyx_v_db) { PyObject *__pyx_v_g = NULL; PyObject *__pyx_v_s = NULL; PyObject *__pyx_v_t = NULL; PyObject *__pyx_v_g2 = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions._add", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_g); __Pyx_XDECREF(__pyx_v_s); __Pyx_XDECREF(__pyx_v_t); __Pyx_XDECREF(__pyx_v_g2); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1362: """a + b"""
1363: # return Fraction(na * db + nb * da, da * db)
+1364: g = _gcd(da, db)
__pyx_t_1 = __pyx_f_10quicktions__gcd(__pyx_v_da, __pyx_v_db, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1364, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1365: if g == 1:
__pyx_t_2 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_g, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1365, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1366: return _fraction_from_coprime_ints(na * db + da * nb, da * db)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Multiply(__pyx_v_na, __pyx_v_db); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_Multiply(__pyx_v_da, __pyx_v_nb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Multiply(__pyx_v_da, __pyx_v_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1366, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+1367: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1367, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1368: t = na * (db // g) + nb * s
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_db, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_Multiply(__pyx_v_na, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Multiply(__pyx_v_nb, __pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyNumber_Add(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1368, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_t = __pyx_t_4; __pyx_t_4 = 0;
+1369: g2 = _gcd(t, g)
__pyx_t_4 = __pyx_f_10quicktions__gcd(__pyx_v_t, __pyx_v_g, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1369, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g2 = __pyx_t_4; __pyx_t_4 = 0;
+1370: if g2 == 1:
__pyx_t_2 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_g2, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1370, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1371: return _fraction_from_coprime_ints(t, s * db)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyNumber_Multiply(__pyx_v_s, __pyx_v_db); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_t, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+1372: return _fraction_from_coprime_ints(t // g2, s * (db // g2))
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_FloorDivide(__pyx_v_t, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyNumber_FloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Multiply(__pyx_v_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1373:
+1374: cdef _sub(na, da, nb, db):
static PyObject *__pyx_f_10quicktions__sub(PyObject *__pyx_v_na, PyObject *__pyx_v_da, PyObject *__pyx_v_nb, PyObject *__pyx_v_db) { PyObject *__pyx_v_g = NULL; PyObject *__pyx_v_s = NULL; PyObject *__pyx_v_t = NULL; PyObject *__pyx_v_g2 = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions._sub", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_g); __Pyx_XDECREF(__pyx_v_s); __Pyx_XDECREF(__pyx_v_t); __Pyx_XDECREF(__pyx_v_g2); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1375: """a - b"""
1376: # return Fraction(na * db - nb * da, da * db)
+1377: g = _gcd(da, db)
__pyx_t_1 = __pyx_f_10quicktions__gcd(__pyx_v_da, __pyx_v_db, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1377, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1378: if g == 1:
__pyx_t_2 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_g, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1378, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1379: return _fraction_from_coprime_ints(na * db - da * nb, da * db)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Multiply(__pyx_v_na, __pyx_v_db); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_Multiply(__pyx_v_da, __pyx_v_nb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Subtract(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Multiply(__pyx_v_da, __pyx_v_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_4, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1379, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+1380: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1380, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1381: t = na * (db // g) - nb * s
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_db, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_Multiply(__pyx_v_na, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Multiply(__pyx_v_nb, __pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyNumber_Subtract(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1381, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_t = __pyx_t_4; __pyx_t_4 = 0;
+1382: g2 = _gcd(t, g)
__pyx_t_4 = __pyx_f_10quicktions__gcd(__pyx_v_t, __pyx_v_g, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g2 = __pyx_t_4; __pyx_t_4 = 0;
+1383: if g2 == 1:
__pyx_t_2 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_g2, __pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1383, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1384: return _fraction_from_coprime_ints(t, s * db)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = PyNumber_Multiply(__pyx_v_s, __pyx_v_db); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1384, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_t, __pyx_t_4, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1384, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+1385: return _fraction_from_coprime_ints(t // g2, s * (db // g2))
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_FloorDivide(__pyx_v_t, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PyNumber_FloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Multiply(__pyx_v_s, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1386:
+1387: cdef _mul(na, da, nb, db):
static PyObject *__pyx_f_10quicktions__mul(PyObject *__pyx_v_na, PyObject *__pyx_v_da, PyObject *__pyx_v_nb, PyObject *__pyx_v_db) { PyObject *__pyx_v_g1 = NULL; PyObject *__pyx_v_g2 = NULL; PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_na); __Pyx_INCREF(__pyx_v_da); __Pyx_INCREF(__pyx_v_nb); __Pyx_INCREF(__pyx_v_db); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions._mul", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_g1); __Pyx_XDECREF(__pyx_v_g2); __Pyx_XDECREF(__pyx_v_na); __Pyx_XDECREF(__pyx_v_da); __Pyx_XDECREF(__pyx_v_nb); __Pyx_XDECREF(__pyx_v_db); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1388: """a * b"""
1389: # return Fraction(na * nb, da * db)
+1390: g1 = _gcd(na, db)
__pyx_t_1 = __pyx_f_10quicktions__gcd(__pyx_v_na, __pyx_v_db, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1390, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g1 = __pyx_t_1; __pyx_t_1 = 0;
+1391: if g1 > 1:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_g1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1391, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1391, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1392: na //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_1); __pyx_t_1 = 0;
+1393: db //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1393, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_1); __pyx_t_1 = 0;
+1394: g2 = _gcd(nb, da)
__pyx_t_1 = __pyx_f_10quicktions__gcd(__pyx_v_nb, __pyx_v_da, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1394, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g2 = __pyx_t_1; __pyx_t_1 = 0;
+1395: if g2 > 1:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_g2, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1395, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1395, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1396: nb //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1396, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_1); __pyx_t_1 = 0;
+1397: da //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1397, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_1); __pyx_t_1 = 0;
+1398: return _fraction_from_coprime_ints(na * nb, db * da)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Multiply(__pyx_v_na, __pyx_v_nb); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1398, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = PyNumber_Multiply(__pyx_v_db, __pyx_v_da); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1398, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_1, __pyx_t_3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1398, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1399:
+1400: cdef _div(na, da, nb, db):
static PyObject *__pyx_f_10quicktions__div(PyObject *__pyx_v_na, PyObject *__pyx_v_da, PyObject *__pyx_v_nb, PyObject *__pyx_v_db) { PyObject *__pyx_v_g1 = NULL; PyObject *__pyx_v_g2 = NULL; PyObject *__pyx_v_n = NULL; PyObject *__pyx_v_d = NULL; PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_na); __Pyx_INCREF(__pyx_v_da); __Pyx_INCREF(__pyx_v_nb); __Pyx_INCREF(__pyx_v_db); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions._div", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_g1); __Pyx_XDECREF(__pyx_v_g2); __Pyx_XDECREF(__pyx_v_n); __Pyx_XDECREF(__pyx_v_d); __Pyx_XDECREF(__pyx_v_na); __Pyx_XDECREF(__pyx_v_da); __Pyx_XDECREF(__pyx_v_nb); __Pyx_XDECREF(__pyx_v_db); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1401: """a / b"""
1402: # return Fraction(na * db, da * nb)
1403: # Same as _mul(), with inversed b.
+1404: if nb == 0:
__pyx_t_1 = (__Pyx_PyInt_BoolEqObjC(__pyx_v_nb, __pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1404, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1405: raise ZeroDivisionError(f'Fraction({db}, 0)')
__pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = 0; __pyx_t_4 = 127; __Pyx_INCREF(__pyx_kp_u_Fraction); __pyx_t_3 += 9; __Pyx_GIVEREF(__pyx_kp_u_Fraction); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_kp_u_Fraction); __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_db, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_4) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_4; __pyx_t_3 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_5); __pyx_t_5 = 0; __Pyx_INCREF(__pyx_kp_u_0); __pyx_t_3 += 4; __Pyx_GIVEREF(__pyx_kp_u_0); PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_kp_u_0); __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_2, 3, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ZeroDivisionError, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 1405, __pyx_L1_error)
+1406: g1 = _gcd(na, nb)
__pyx_t_2 = __pyx_f_10quicktions__gcd(__pyx_v_na, __pyx_v_nb, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_g1 = __pyx_t_2; __pyx_t_2 = 0;
+1407: if g1 > 1:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_g1, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1407, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1407, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1408: na //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_2); __pyx_t_2 = 0;
+1409: nb //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_2); __pyx_t_2 = 0;
+1410: g2 = _gcd(db, da)
__pyx_t_2 = __pyx_f_10quicktions__gcd(__pyx_v_db, __pyx_v_da, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1410, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1411: if g2 > 1:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_g2, __pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1411, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1411, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1412: da //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_2); __pyx_t_2 = 0;
+1413: db //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_2); __pyx_t_2 = 0;
+1414: n, d = na * db, nb * da
__pyx_t_2 = PyNumber_Multiply(__pyx_v_na, __pyx_v_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1414, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = PyNumber_Multiply(__pyx_v_nb, __pyx_v_da); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1414, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_5; __pyx_t_5 = 0;
+1415: if d < 0:
__pyx_t_5 = PyObject_RichCompare(__pyx_v_d, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1415, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1415, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+1416: n, d = -n, -d
__pyx_t_5 = PyNumber_Negative(__pyx_v_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1416, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = PyNumber_Negative(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1416, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF_SET(__pyx_v_d, __pyx_t_2); __pyx_t_2 = 0;
+1417: return _fraction_from_coprime_ints(n, d)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_n, __pyx_v_d, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1417, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1418:
+1419: cdef _floordiv(an, ad, bn, bd):
static PyObject *__pyx_f_10quicktions__floordiv(PyObject *__pyx_v_an, PyObject *__pyx_v_ad, PyObject *__pyx_v_bn, PyObject *__pyx_v_bd) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions._floordiv", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1420: """a // b -> int"""
+1421: return (an * bd) // (bn * ad)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Multiply(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Multiply(__pyx_v_bn, __pyx_v_ad); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_FloorDivide(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1422:
+1423: cdef _divmod(an, ad, bn, bd):
static PyObject *__pyx_f_10quicktions__divmod(PyObject *__pyx_v_an, PyObject *__pyx_v_ad, PyObject *__pyx_v_bn, PyObject *__pyx_v_bd) { PyObject *__pyx_v_div = NULL; PyObject *__pyx_v_n_mod = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions._divmod", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_div); __Pyx_XDECREF(__pyx_v_n_mod); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1424: div, n_mod = divmod(an * bd, ad * bn)
__pyx_t_1 = PyNumber_Multiply(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Multiply(__pyx_v_ad, __pyx_v_bn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Divmod(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if ((likely(PyTuple_CheckExact(__pyx_t_3))) || (PyList_CheckExact(__pyx_t_3))) { PyObject* sequence = __pyx_t_3; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 1424, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_2 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_2 = PyList_GET_ITEM(sequence, 0); __pyx_t_1 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_1); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_2 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_2)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_1 = __pyx_t_5(__pyx_t_4); if (unlikely(!__pyx_t_1)) goto __pyx_L3_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); if (__Pyx_IternextUnpackEndCheck(__pyx_t_5(__pyx_t_4), 2) < 0) __PYX_ERR(0, 1424, __pyx_L1_error) __pyx_t_5 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L4_unpacking_done; __pyx_L3_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_5 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 1424, __pyx_L1_error) __pyx_L4_unpacking_done:; } __pyx_v_div = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_n_mod = __pyx_t_1; __pyx_t_1 = 0;
+1425: return div, Fraction(n_mod, ad * bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyNumber_Multiply(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1425, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1425, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_n_mod); __Pyx_GIVEREF(__pyx_v_n_mod); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_n_mod)) __PYX_ERR(0, 1425, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3)) __PYX_ERR(0, 1425, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_10quicktions_Fraction), __pyx_t_1, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1425, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1425, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_div); __Pyx_GIVEREF(__pyx_v_div); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_div)) __PYX_ERR(0, 1425, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3)) __PYX_ERR(0, 1425, __pyx_L1_error); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1426:
+1427: cdef _mod(an, ad, bn, bd):
static PyObject *__pyx_f_10quicktions__mod(PyObject *__pyx_v_an, PyObject *__pyx_v_ad, PyObject *__pyx_v_bn, PyObject *__pyx_v_bd) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions._mod", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1428: return Fraction((an * bd) % (bn * ad), ad * bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Multiply(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Multiply(__pyx_v_bn, __pyx_v_ad); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Remainder(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Multiply(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_3)) __PYX_ERR(0, 1428, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2)) __PYX_ERR(0, 1428, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_10quicktions_Fraction), __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1428, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1429:
1430:
1431: """
1432: In general, we want to implement the arithmetic operations so
1433: that mixed-mode operations either call an implementation whose
1434: author knew about the types of both arguments, or convert both
1435: to the nearest built in type and do the operation there. In
1436: Fraction, that means that we define __add__ and __radd__ as:
1437:
1438: def __add__(self, other):
1439: # Both types have numerators/denominator attributes,
1440: # so do the operation directly
1441: if isinstance(other, (int, Fraction)):
1442: return Fraction(self.numerator * other.denominator +
1443: other.numerator * self.denominator,
1444: self.denominator * other.denominator)
1445: # float and complex don't have those operations, but we
1446: # know about those types, so special case them.
1447: elif isinstance(other, float):
1448: return float(self) + other
1449: elif isinstance(other, complex):
1450: return complex(self) + other
1451: # Let the other type take over.
1452: return NotImplemented
1453:
1454: def __radd__(self, other):
1455: # radd handles more types than add because there's
1456: # nothing left to fall back to.
1457: if isinstance(other, Rational):
1458: return Fraction(self.numerator * other.denominator +
1459: other.numerator * self.denominator,
1460: self.denominator * other.denominator)
1461: elif isinstance(other, Real):
1462: return float(other) + float(self)
1463: elif isinstance(other, Complex):
1464: return complex(other) + complex(self)
1465: return NotImplemented
1466:
1467:
1468: There are 5 different cases for a mixed-type addition on
1469: Fraction. I'll refer to all of the above code that doesn't
1470: refer to Fraction, float, or complex as "boilerplate". 'r'
1471: will be an instance of Fraction, which is a subtype of
1472: Rational (r : Fraction <: Rational), and b : B <:
1473: Complex. The first three involve 'r + b':
1474:
1475: 1. If B <: Fraction, int, float, or complex, we handle
1476: that specially, and all is well.
1477: 2. If Fraction falls back to the boilerplate code, and it
1478: were to return a value from __add__, we'd miss the
1479: possibility that B defines a more intelligent __radd__,
1480: so the boilerplate should return NotImplemented from
1481: __add__. In particular, we don't handle Rational
1482: here, even though we could get an exact answer, in case
1483: the other type wants to do something special.
1484: 3. If B <: Fraction, Python tries B.__radd__ before
1485: Fraction.__add__. This is ok, because it was
1486: implemented with knowledge of Fraction, so it can
1487: handle those instances before delegating to Real or
1488: Complex.
1489:
1490: The next two situations describe 'b + r'. We assume that b
1491: didn't know about Fraction in its implementation, and that it
1492: uses similar boilerplate code:
1493:
1494: 4. If B <: Rational, then __radd_ converts both to the
1495: builtin rational type (hey look, that's us) and
1496: proceeds.
1497: 5. Otherwise, __radd__ tries to find the nearest common
1498: base ABC, and fall back to its builtin type. Since this
1499: class doesn't subclass a concrete type, there's no
1500: implementation to fall back to, so we need to try as
1501: hard as possible to return an actual value, or the user
1502: will get a TypeError.
1503: """
1504:
1505: cdef:
+1506: _math_op_add = operator.add
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1506, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_add); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_add, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1507: _math_op_sub = operator.sub
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_sub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1507, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_sub); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_sub, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1508: _math_op_mul = operator.mul
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_mul); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_mul); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_mul, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1509: _math_op_div = getattr(operator, 'div', operator.truediv) # Py2/3
__pyx_t_3 = __pyx_v_10quicktions_operator; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_truediv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_GetAttr3(__pyx_t_3, __pyx_n_s_div, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_div); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_div, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1510: _math_op_truediv = operator.truediv
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_truediv); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_truediv); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_truediv, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1511: _math_op_floordiv = operator.floordiv
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_floordiv); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1511, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_floordiv); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_floordiv, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1512: _math_op_mod = operator.mod
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_mod); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_mod); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_mod, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1513: _math_op_divmod = divmod
__pyx_t_9 = __Pyx_GetBuiltinName(__pyx_n_s_divmod); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1513, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_divmod); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_divmod, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
1514:
1515:
+1516: ctypedef object (*math_func)(an, ad, bn, bd)
typedef PyObject *(*__pyx_t_10quicktions_math_func)(PyObject *, PyObject *, PyObject *, PyObject *);
1517:
1518:
+1519: cdef forward(a, b, math_func monomorphic_operator, pyoperator):
static PyObject *__pyx_f_10quicktions_forward(PyObject *__pyx_v_a, PyObject *__pyx_v_b, __pyx_t_10quicktions_math_func __pyx_v_monomorphic_operator, PyObject *__pyx_v_pyoperator) { PyObject *__pyx_v_an = NULL; PyObject *__pyx_v_ad = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions.forward", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_an); __Pyx_XDECREF(__pyx_v_ad); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1520: an, ad = (<Fraction>a)._numerator, (<Fraction>a)._denominator
__pyx_t_1 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)->_numerator; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)->_denominator; __Pyx_INCREF(__pyx_t_2); __pyx_v_an = __pyx_t_1; __pyx_t_1 = 0; __pyx_v_ad = __pyx_t_2; __pyx_t_2 = 0;
+1521: if type(b) is Fraction:
__pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_3) { /* … */ }
+1522: return monomorphic_operator(an, ad, (<Fraction>b)._numerator, (<Fraction>b)._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_numerator; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_denominator; __Pyx_INCREF(__pyx_t_1); __pyx_t_4 = __pyx_v_monomorphic_operator(__pyx_v_an, __pyx_v_ad, __pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1523: elif isinstance(b, (int, long)):
__pyx_t_5 = PyInt_Check(__pyx_v_b); if (!__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L4_bool_binop_done; } __pyx_t_5 = PyLong_Check(__pyx_v_b); __pyx_t_3 = __pyx_t_5; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1524: return monomorphic_operator(an, ad, b, 1)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __pyx_v_monomorphic_operator(__pyx_v_an, __pyx_v_ad, __pyx_v_b, __pyx_int_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1524, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1525: elif isinstance(b, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_4 = __pyx_v_10quicktions_Rational; __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_b, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_5) { } else { __pyx_t_3 = __pyx_t_5; goto __pyx_L6_bool_binop_done; } __pyx_t_5 = PyObject_IsInstance(__pyx_v_b, __pyx_t_4); __pyx_t_3 = __pyx_t_5; __pyx_L6_bool_binop_done:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_3) { /* … */ }
+1526: return monomorphic_operator(an, ad, b.numerator, b.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_v_monomorphic_operator(__pyx_v_an, __pyx_v_ad, __pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1527: elif isinstance(b, float):
__pyx_t_3 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1528: return pyoperator(_as_float(an, ad), b)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_f_10quicktions__as_float(__pyx_v_an, __pyx_v_ad); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1528, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_4 = __pyx_v_pyoperator; __pyx_t_6 = NULL; __pyx_t_7 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_7 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_6, __pyx_t_1, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1528, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1529: elif isinstance(b, complex):
__pyx_t_3 = PyComplex_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1530: return pyoperator(complex(a), b)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyComplex_Type)), __pyx_v_a); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1530, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_1 = __pyx_v_pyoperator; __pyx_t_6 = NULL; __pyx_t_7 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_7 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_6, __pyx_t_4, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1530, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1531: else:
+1532: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1533:
1534:
+1535: cdef reverse(a, b, math_func monomorphic_operator, pyoperator):
static PyObject *__pyx_f_10quicktions_reverse(PyObject *__pyx_v_a, PyObject *__pyx_v_b, __pyx_t_10quicktions_math_func __pyx_v_monomorphic_operator, PyObject *__pyx_v_pyoperator) { PyObject *__pyx_v_bn = NULL; PyObject *__pyx_v_bd = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("quicktions.reverse", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_bn); __Pyx_XDECREF(__pyx_v_bd); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1536: bn, bd = (<Fraction>b)._numerator, (<Fraction>b)._denominator
__pyx_t_1 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_numerator; __Pyx_INCREF(__pyx_t_1); __pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_denominator; __Pyx_INCREF(__pyx_t_2); __pyx_v_bn = __pyx_t_1; __pyx_t_1 = 0; __pyx_v_bd = __pyx_t_2; __pyx_t_2 = 0;
+1537: if isinstance(a, (int, long)):
__pyx_t_4 = PyInt_Check(__pyx_v_a); if (!__pyx_t_4) { } else { __pyx_t_3 = __pyx_t_4; goto __pyx_L4_bool_binop_done; } __pyx_t_4 = PyLong_Check(__pyx_v_a); __pyx_t_3 = __pyx_t_4; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1538: return monomorphic_operator(a, 1, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __pyx_v_monomorphic_operator(__pyx_v_a, __pyx_int_1, __pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1538, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1539: elif isinstance(a, Rational):
__pyx_t_2 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = PyObject_IsInstance(__pyx_v_a, __pyx_t_2); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 1539, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { /* … */ }
+1540: return monomorphic_operator(a.numerator, a.denominator, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_n_s_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __pyx_v_monomorphic_operator(__pyx_t_2, __pyx_t_1, __pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+1541: elif isinstance(a, Real):
__pyx_t_5 = __pyx_v_10quicktions_Real; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = PyObject_IsInstance(__pyx_v_a, __pyx_t_5); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 1541, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_3) { /* … */ }
+1542: return pyoperator(float(a), _as_float(bn, bd))
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyNumber_Float(__pyx_v_a); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __pyx_f_10quicktions__as_float(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_6 = __pyx_v_pyoperator; __pyx_t_7 = NULL; __pyx_t_8 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); __pyx_t_8 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_t_1, __pyx_t_2}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 2+__pyx_t_8); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1542, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+1543: elif isinstance(a, Complex):
__pyx_t_5 = __pyx_v_10quicktions_Complex; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = PyObject_IsInstance(__pyx_v_a, __pyx_t_5); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 1543, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_3) { /* … */ }
+1544: return pyoperator(complex(a), complex(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyComplex_Type)), __pyx_v_a); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyComplex_Type)), __pyx_v_b); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_1 = __pyx_v_pyoperator; __pyx_t_7 = NULL; __pyx_t_8 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_7)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_8 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_t_6, __pyx_t_2}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_8, 2+__pyx_t_8); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
1545: else:
+1546: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1547:
1548:
+1549: ctypedef char* charptr
typedef char *__pyx_t_10quicktions_charptr;
1550:
1551: ctypedef fused AnyString:
1552: unicode
1553: charptr
1554:
1555:
+1556: cdef enum ParserState:
enum __pyx_t_10quicktions_ParserState { __pyx_e_10quicktions_BEGIN_SPACE, __pyx_e_10quicktions_BEGIN_SIGN, __pyx_e_10quicktions_SMALL_NUM, __pyx_e_10quicktions_SMALL_NUM_US, __pyx_e_10quicktions_NUM, __pyx_e_10quicktions_NUM_US, __pyx_e_10quicktions_NUM_SPACE, __pyx_e_10quicktions_START_DECIMAL_DOT, __pyx_e_10quicktions_SMALL_DECIMAL_DOT, __pyx_e_10quicktions_DECIMAL_DOT, __pyx_e_10quicktions_SMALL_DECIMAL, __pyx_e_10quicktions_SMALL_DECIMAL_US, __pyx_e_10quicktions_DECIMAL, __pyx_e_10quicktions_DECIMAL_US, __pyx_e_10quicktions_EXP_E, __pyx_e_10quicktions_EXP_SIGN, __pyx_e_10quicktions_EXP, __pyx_e_10quicktions_EXP_US, __pyx_e_10quicktions_END_SPACE, __pyx_e_10quicktions_SMALL_END_SPACE, __pyx_e_10quicktions_DENOM_START, __pyx_e_10quicktions_DENOM_SIGN, __pyx_e_10quicktions_SMALL_DENOM, __pyx_e_10quicktions_SMALL_DENOM_US, __pyx_e_10quicktions_DENOM, __pyx_e_10quicktions_DENOM_US, __pyx_e_10quicktions_DENOM_SPACE };
1557: BEGIN_SPACE # '\s'* -> (BEGIN_SIGN, SMALL_NUM, START_DECIMAL_DOT)
1558: BEGIN_SIGN # [+-] -> (SMALL_NUM, SMALL_DECIMAL_DOT)
1559: SMALL_NUM # [0-9]+ -> (SMALL_NUM, SMALL_NUM_US, NUM, NUM_SPACE, SMALL_DECIMAL_DOT, EXP_E, DENOM_START)
1560: SMALL_NUM_US # '_' -> (SMALL_NUM, NUM)
1561: NUM # [0-9]+ -> (NUM, NUM_US, NUM_SPACE, DECIMAL_DOT, EXP_E, DENOM_START)
1562: NUM_US # '_' -> (NUM)
1563: NUM_SPACE # '\s'+ -> (DENOM_START)
1564:
1565: # 1) floating point syntax
1566: START_DECIMAL_DOT # '.' -> (SMALL_DECIMAL)
1567: SMALL_DECIMAL_DOT # '.' -> (SMALL_DECIMAL, EXP_E, SMALL_END_SPACE)
1568: DECIMAL_DOT # '.' -> (DECIMAL, EXP_E, END_SPACE)
1569: SMALL_DECIMAL # [0-9]+ -> (SMALL_DECIMAL, SMALL_DECIMAL_US, DECIMAL, EXP_E, SMALL_END_SPACE)
1570: SMALL_DECIMAL_US # '_' -> (SMALL_DECIMAL, DECIMAL)
1571: DECIMAL # [0-9]+ -> (DECIMAL, DECIMAL_US, EXP_E, END_SPACE)
1572: DECIMAL_US # '_' -> (DECIMAL)
1573: EXP_E # [eE] -> (EXP_SIGN, EXP)
1574: EXP_SIGN # [+-] -> (EXP)
1575: EXP # [0-9]+ -> (EXP_US, END_SPACE)
1576: EXP_US # '_' -> (EXP)
1577: END_SPACE # '\s'+
1578: SMALL_END_SPACE # '\s'+
1579:
1580: # 2) "NOM / DENOM" syntax
1581: DENOM_START # '/' -> (DENOM_SIGN, SMALL_DENOM)
1582: DENOM_SIGN # [+-] -> (SMALL_DENOM)
1583: SMALL_DENOM # [0-9]+ -> (SMALL_DENOM, SMALL_DENOM_US, DENOM, DENOM_SPACE)
1584: SMALL_DENOM_US # '_' -> (SMALL_DENOM)
1585: DENOM # [0-9]+ -> (DENOM, DENOM_US, DENOM_SPACE)
1586: DENOM_US # '_' -> (DENOM)
1587: DENOM_SPACE # '\s'+
1588:
1589:
+1590: cdef _raise_invalid_input(s):
static PyObject *__pyx_f_10quicktions__raise_invalid_input(PyObject *__pyx_v_s) { PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_s); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions._raise_invalid_input", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __Pyx_XDECREF(__pyx_v_s); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1591: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1592: if s[:2] in ('b"', "b'"):
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 0, 2, NULL, NULL, &__pyx_slice__16, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s_b_2, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1592, __pyx_L1_error) if (!__pyx_t_3) { } else { __pyx_t_2 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s_b_3, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1592, __pyx_L1_error) __pyx_t_2 = __pyx_t_3; __pyx_L4_bool_binop_done:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = __pyx_t_2; if (__pyx_t_3) { /* … */ __pyx_slice__16 = PySlice_New(Py_None, __pyx_int_2, Py_None); if (unlikely(!__pyx_slice__16)) __PYX_ERR(0, 1592, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__16); __Pyx_GIVEREF(__pyx_slice__16); /* … */ goto __pyx_L3; }
+1593: s = s[1:]
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 1, 0, NULL, NULL, &__pyx_slice__17, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_slice__17 = PySlice_New(__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_slice__17)) __PYX_ERR(0, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__17); __Pyx_GIVEREF(__pyx_slice__17);
+1594: elif PY_MAJOR_VERSION ==2 and s[:2] in ('u"', "u'"):
__pyx_t_2 = (PY_MAJOR_VERSION == 2); if (__pyx_t_2) { } else { __pyx_t_3 = __pyx_t_2; goto __pyx_L6_bool_binop_done; } __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 0, 2, NULL, NULL, &__pyx_slice__16, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s_u, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 1594, __pyx_L1_error) if (!__pyx_t_4) { } else { __pyx_t_2 = __pyx_t_4; goto __pyx_L8_bool_binop_done; } __pyx_t_4 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_kp_s_u_2, Py_EQ)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 1594, __pyx_L1_error) __pyx_t_2 = __pyx_t_4; __pyx_L8_bool_binop_done:; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __pyx_t_2; __pyx_t_3 = __pyx_t_4; __pyx_L6_bool_binop_done:; if (__pyx_t_3) { /* … */ } __pyx_L3:;
+1595: s = s[1:]
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 1, 0, NULL, NULL, &__pyx_slice__17, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1596: raise ValueError(f'Invalid literal for Fraction: {s}') from None
__pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_s, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Invalid_literal_for_Fraction, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 1596, __pyx_L1_error)
1597:
1598:
+1599: cdef _raise_parse_overflow(s):
static PyObject *__pyx_f_10quicktions__raise_parse_overflow(PyObject *__pyx_v_s) { PyObject *__pyx_r = NULL; __Pyx_INCREF(__pyx_v_s); /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_3); __Pyx_AddTraceback("quicktions._raise_parse_overflow", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __Pyx_XDECREF(__pyx_v_s); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1600: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1600, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1601: if s[0] == 'b':
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_s, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = (__Pyx_PyString_Equals(__pyx_t_1, __pyx_n_s_b, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1601, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1602: s = s[1:]
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 1, 0, NULL, NULL, &__pyx_slice__17, 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1602, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1603: raise OverflowError(f"Exponent too large for Fraction: {s!s}") from None
__pyx_t_1 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Unicode(__pyx_v_s), __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1603, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Exponent_too_large_for_Fraction, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1603, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_OverflowError, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1603, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 1603, __pyx_L1_error)
1604:
1605:
1606: cdef extern from *:
1607: """
1608: static CYTHON_INLINE int __QUICKTIONS_unpack_string(
1609: PyObject* string, Py_ssize_t *length, void** data, int *kind) {
1610: if (PyBytes_Check(string)) {
1611: *kind = 1;
1612: *length = PyBytes_GET_SIZE(string);
1613: *data = PyBytes_AS_STRING(string);
1614: } else {
1615: #if CYTHON_PEP393_ENABLED
1616: if (PyUnicode_READY(string) < 0) return -1;
1617: *kind = PyUnicode_KIND(string);
1618: *length = PyUnicode_GET_LENGTH(string);
1619: *data = PyUnicode_DATA(string);
1620: #else
1621: *kind = 0;
1622: *length = PyUnicode_GET_SIZE(string);
1623: *data = (void*)PyUnicode_AS_UNICODE(string);
1624: #endif
1625: }
1626: return 0;
1627: }
1628: #if PY_MAJOR_VERSION < 3
1629: #define PyUnicode_READ(k, d, i) ((Py_UCS4) ((Py_UNICODE*) d) [i])
1630: #endif
1631: #define __QUICKTIONS_char_at(data, kind, index) \
1632: (((kind == 1) ? (Py_UCS4) ((char*) data)[index] : (Py_UCS4) PyUnicode_READ(kind, data, index)))
1633: """
1634: int _unpack_string "__QUICKTIONS_unpack_string" (
1635: object string, Py_ssize_t *length, void **data, int *kind) except -1
1636: Py_UCS4 _char_at "__QUICKTIONS_char_at" (void *data, int kind, Py_ssize_t index)
1637: Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)
1638:
1639:
+1640: cdef inline int _parse_digit(char** c_digits, Py_UCS4 c, int allow_unicode):
static CYTHON_INLINE int __pyx_f_10quicktions__parse_digit(char **__pyx_v_c_digits, Py_UCS4 __pyx_v_c, int __pyx_v_allow_unicode) { unsigned int __pyx_v_unum; int __pyx_v_num; int __pyx_r; /* … */ /* function exit code */ __pyx_L0:; return __pyx_r; }
1641: cdef unsigned int unum
1642: cdef int num
+1643: unum = (<unsigned int> c) - <unsigned int> '0' # Relies on integer underflow for dots etc.
__pyx_v_unum = (((unsigned int)__pyx_v_c) - ((unsigned int)'0'));
+1644: if unum > 9:
__pyx_t_1 = (__pyx_v_unum > 9); if (__pyx_t_1) { /* … */ }
+1645: if not allow_unicode:
__pyx_t_1 = (!(__pyx_v_allow_unicode != 0)); if (__pyx_t_1) { /* … */ }
+1646: return -1
__pyx_r = -1; goto __pyx_L0;
+1647: num = Py_UNICODE_TODECIMAL(c)
__pyx_v_num = Py_UNICODE_TODECIMAL(__pyx_v_c);
+1648: if num == -1:
__pyx_t_1 = (__pyx_v_num == -1L); if (__pyx_t_1) { /* … */ }
+1649: return -1
__pyx_r = -1; goto __pyx_L0;
+1650: unum = <unsigned int> num
__pyx_v_unum = ((unsigned int)__pyx_v_num);
+1651: c = <Py_UCS4> (num + c'0')
__pyx_v_c = ((Py_UCS4)(__pyx_v_num + '0'));
+1652: if c_digits:
__pyx_t_1 = (__pyx_v_c_digits != 0); if (__pyx_t_1) { /* … */ }
+1653: c_digits[0][0] = <char> c
((__pyx_v_c_digits[0])[0]) = ((char)__pyx_v_c);
+1654: c_digits[0] += 1
__pyx_t_2 = 0; (__pyx_v_c_digits[__pyx_t_2]) = ((__pyx_v_c_digits[__pyx_t_2]) + 1);
+1655: return <int> unum
__pyx_r = ((int)__pyx_v_unum); goto __pyx_L0;
1656:
1657:
+1658: cdef inline object _parse_pylong(char* c_digits_start, char** c_digits_end):
static CYTHON_INLINE PyObject *__pyx_f_10quicktions__parse_pylong(char *__pyx_v_c_digits_start, char **__pyx_v_c_digits_end) { PyObject *__pyx_v_py_number = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("quicktions._parse_pylong", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_py_number); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1659: c_digits_end[0][0] = 0
((__pyx_v_c_digits_end[0])[0]) = 0;
+1660: py_number = PyLong_FromString(c_digits_start, NULL, 10)
__pyx_t_1 = PyLong_FromString(__pyx_v_c_digits_start, NULL, 10); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1660, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_py_number = __pyx_t_1; __pyx_t_1 = 0;
+1661: c_digits_end[0] = c_digits_start # reset
(__pyx_v_c_digits_end[0]) = __pyx_v_c_digits_start;
+1662: return py_number
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_py_number); __pyx_r = __pyx_v_py_number; goto __pyx_L0;
1663:
1664:
1665: @cython.cdivision(True)
+1666: cdef tuple _parse_fraction(AnyString s, Py_ssize_t s_len):
static PyObject *__pyx_fuse_0__pyx_f_10quicktions__parse_fraction(PyObject *__pyx_v_s, Py_ssize_t __pyx_v_s_len) { Py_ssize_t __pyx_v_pos; Py_ssize_t __pyx_v_decimal_len; Py_UCS4 __pyx_v_c; enum __pyx_t_10quicktions_ParserState __pyx_v_state; int __pyx_v_is_neg; int __pyx_v_exp_is_neg; int __pyx_v_digit; PY_LONG_LONG __pyx_v_inum; CYTHON_UNUSED PY_LONG_LONG __pyx_v_idecimal; PY_LONG_LONG __pyx_v_idenom; PY_LONG_LONG __pyx_v_iexp; __pyx_t_10quicktions_ullong __pyx_v_igcd; PyObject *__pyx_v_num = 0; PyObject *__pyx_v_denom = 0; Py_ssize_t __pyx_v_max_decimal_len; int __pyx_v_allow_unicode; int __pyx_v_s_kind; void *__pyx_v_s_data; char *__pyx_v_cdata; PyObject *__pyx_v_digits = 0; char *__pyx_v_c_digits_start; char *__pyx_v_c_digits; PyObject *__pyx_v_is_normalised = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_9); __Pyx_AddTraceback("quicktions._parse_fraction", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_num); __Pyx_XDECREF(__pyx_v_denom); __Pyx_XDECREF(__pyx_v_digits); __Pyx_XDECREF(__pyx_v_is_normalised); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_fuse_1__pyx_f_10quicktions__parse_fraction(__pyx_t_10quicktions_charptr __pyx_v_s, Py_ssize_t __pyx_v_s_len) { Py_ssize_t __pyx_v_pos; Py_ssize_t __pyx_v_decimal_len; Py_UCS4 __pyx_v_c; enum __pyx_t_10quicktions_ParserState __pyx_v_state; int __pyx_v_is_neg; int __pyx_v_exp_is_neg; int __pyx_v_digit; PY_LONG_LONG __pyx_v_inum; CYTHON_UNUSED PY_LONG_LONG __pyx_v_idecimal; PY_LONG_LONG __pyx_v_idenom; PY_LONG_LONG __pyx_v_iexp; __pyx_t_10quicktions_ullong __pyx_v_igcd; PyObject *__pyx_v_num = 0; PyObject *__pyx_v_denom = 0; Py_ssize_t __pyx_v_max_decimal_len; int __pyx_v_allow_unicode; int __pyx_v_s_kind; void *__pyx_v_s_data; char *__pyx_v_cdata; PyObject *__pyx_v_digits = 0; char *__pyx_v_c_digits_start; char *__pyx_v_c_digits; PyObject *__pyx_v_is_normalised = NULL; PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions._parse_fraction", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XDECREF(__pyx_v_num); __Pyx_XDECREF(__pyx_v_denom); __Pyx_XDECREF(__pyx_v_digits); __Pyx_XDECREF(__pyx_v_is_normalised); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
1667: """
1668: Parse a string into a number tuple: (numerator, denominator, is_normalised)
1669: """
+1670: cdef Py_ssize_t pos, decimal_len = 0
__pyx_v_decimal_len = 0; /* … */ __pyx_v_decimal_len = 0;
1671: cdef Py_UCS4 c
+1672: cdef ParserState state = BEGIN_SPACE
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE;
1673:
+1674: cdef bint is_neg = False, exp_is_neg = False
__pyx_v_is_neg = 0; __pyx_v_exp_is_neg = 0; /* … */ __pyx_v_is_neg = 0; __pyx_v_exp_is_neg = 0;
1675: cdef int digit
1676: cdef unsigned int udigit
+1677: cdef long long inum = 0, idecimal = 0, idenom = 0, iexp = 0
__pyx_v_inum = 0; __pyx_v_idecimal = 0; __pyx_v_idenom = 0; __pyx_v_iexp = 0; /* … */ __pyx_v_inum = 0; __pyx_v_idecimal = 0; __pyx_v_idenom = 0; __pyx_v_iexp = 0;
1678: cdef ullong igcd
+1679: cdef object num = None, decimal, denom
__Pyx_INCREF(Py_None); __pyx_v_num = Py_None; /* … */ __Pyx_INCREF(Py_None); __pyx_v_num = Py_None;
1680: # 2^n > 10^(n * 5/17)
+1681: cdef Py_ssize_t max_decimal_len = <Py_ssize_t> (sizeof(inum) * 8) * 5 // 17
__pyx_v_max_decimal_len = ((((Py_ssize_t)((sizeof(__pyx_v_inum)) * 8)) * 5) / 17); /* … */ __pyx_v_max_decimal_len = ((((Py_ssize_t)((sizeof(__pyx_v_inum)) * 8)) * 5) / 17);
1682:
1683: # Incremental Unicode iteration isn't in Cython yet.
+1684: cdef int allow_unicode = AnyString is unicode
__pyx_v_allow_unicode = 1; /* … */ __pyx_v_allow_unicode = 0;
+1685: cdef int s_kind = 1
__pyx_v_s_kind = 1; /* … */ __pyx_v_s_kind = 1;
+1686: cdef void* s_data = NULL
__pyx_v_s_data = NULL; /* … */ __pyx_v_s_data = NULL;
+1687: cdef char* cdata = NULL
__pyx_v_cdata = NULL; /* … */ __pyx_v_cdata = NULL;
1688:
1689: if AnyString is unicode:
+1690: _unpack_string(s, &s_len, &s_data, &s_kind)
__pyx_t_1 = __QUICKTIONS_unpack_string(__pyx_v_s, (&__pyx_v_s_len), (&__pyx_v_s_data), (&__pyx_v_s_kind)); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1690, __pyx_L1_error)
+1691: if s_kind == 1:
__pyx_t_2 = (__pyx_v_s_kind == 1); if (__pyx_t_2) { /* … */ }
+1692: return _parse_fraction(<char*> s_data, s_len)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_fuse_1__pyx_f_10quicktions__parse_fraction(((char *)__pyx_v_s_data), __pyx_v_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0;
+1693: cdata = <char*> s_data
__pyx_v_cdata = ((char *)__pyx_v_s_data);
+1694: cdata += 0 # mark used
__pyx_v_cdata = (__pyx_v_cdata + 0);
1695: else:
+1696: cdata = s
__pyx_v_cdata = __pyx_v_s;
1697:
1698: # We collect the digits in inum / idenum as long as the value fits their integer size
1699: # and additionally in a char* buffer in case it grows too large.
+1700: cdef bytes digits = b'\0' * s_len
__pyx_t_3 = __Pyx_PySequence_Multiply(__pyx_kp_b__18, __pyx_v_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1700, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_digits = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PySequence_Multiply(__pyx_kp_b__18, __pyx_v_s_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1700, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_digits = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1701: cdef char* c_digits_start = digits
__pyx_t_4 = __Pyx_PyBytes_AsWritableString(__pyx_v_digits); if (unlikely((!__pyx_t_4) && PyErr_Occurred())) __PYX_ERR(0, 1701, __pyx_L1_error) __pyx_v_c_digits_start = __pyx_t_4; /* … */ __pyx_t_2 = __Pyx_PyBytes_AsWritableString(__pyx_v_digits); if (unlikely((!__pyx_t_2) && PyErr_Occurred())) __PYX_ERR(0, 1701, __pyx_L1_error) __pyx_v_c_digits_start = __pyx_t_2;
+1702: cdef char* c_digits = c_digits_start
__pyx_v_c_digits = __pyx_v_c_digits_start; /* … */ __pyx_v_c_digits = __pyx_v_c_digits_start;
1703:
+1704: pos = 0
__pyx_v_pos = 0; /* … */ __pyx_v_pos = 0;
+1705: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1706: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
if (1) { __pyx_t_5 = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); } else { __pyx_t_5 = (__pyx_v_cdata[__pyx_v_pos]); } __pyx_v_c = __pyx_t_5; /* … */ if (0) { __pyx_t_4 = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); } else { __pyx_t_4 = (__pyx_v_cdata[__pyx_v_pos]); } __pyx_v_c = __pyx_t_4;
+1707: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1708: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1708, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1708, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1709: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+1710: if c == u'/':
switch (__pyx_v_c) { case 47: /* … */ break; case 46: /* … */ switch (__pyx_v_c) { case 47: /* … */ break; case 46:
+1711: if state == SMALL_NUM:
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: /* … */ break; case __pyx_e_10quicktions_NUM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1712: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1712, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1712, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1713: elif state in (NUM, NUM_SPACE):
case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; default: /* … */ case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; default:
+1714: num = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_3 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1714, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1714, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1715: else:
+1716: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; }
+1717: state = DENOM_START
__pyx_v_state = __pyx_e_10quicktions_DENOM_START; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_START;
+1718: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1719: elif c == u'.':
break; case 69: /* … */ break; case 69:
+1720: if state in (BEGIN_SPACE, BEGIN_SIGN):
switch (__pyx_v_state) { case __pyx_e_10quicktions_BEGIN_SPACE: case __pyx_e_10quicktions_BEGIN_SIGN: /* … */ break; case __pyx_e_10quicktions_SMALL_NUM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_BEGIN_SPACE: case __pyx_e_10quicktions_BEGIN_SIGN: /* … */ break; case __pyx_e_10quicktions_SMALL_NUM:
+1721: state = START_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
+1722: elif state == SMALL_NUM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1723: state = SMALL_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
+1724: elif state == NUM:
break; default: /* … */ break; default:
+1725: state = DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
1726: else:
+1727: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1728: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1729: elif c in u'eE':
case 0x65: /* … */ break; case 43: /* … */ case 0x65: /* … */ break; case 43:
+1730: if state == SMALL_NUM:
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: /* … */ break; case __pyx_e_10quicktions_NUM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1731: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1732: elif state == NUM:
break; default: /* … */ break; default:
+1733: num = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_3 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1734: else:
+1735: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1735, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; }
+1736: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1737: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1738: elif c in u'-+':
case 45: /* … */ break; case 95: /* … */ case 45: /* … */ break; case 95:
+1739: if state == BEGIN_SPACE:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_BEGIN_SPACE); if (__pyx_t_2) { /* … */ goto __pyx_L7; } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_BEGIN_SPACE); if (__pyx_t_3) { /* … */ goto __pyx_L6; }
+1740: is_neg = c == u'-'
__pyx_v_is_neg = (__pyx_v_c == 45); /* … */ __pyx_v_is_neg = (__pyx_v_c == 45);
+1741: state = BEGIN_SIGN
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
1742: else:
+1743: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L7:; /* … */ /*else*/ { __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L6:;
+1744: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
+1745: elif c == u'_':
break; default: /* … */ break; default:
+1746: if state == SMALL_NUM:
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: /* … */ break; case __pyx_e_10quicktions_NUM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1747: state = SMALL_NUM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
+1748: elif state == NUM:
break; default: /* … */ break; default:
+1749: state = NUM_US
__pyx_v_state = __pyx_e_10quicktions_NUM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_US;
1750: else:
+1751: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1751, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1751, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1751, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; }
+1752: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
1753: else:
+1754: if c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1755: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1756: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1757: if not c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_7 = (!__pyx_t_3); if (__pyx_t_7) { /* … */ }
+1758: break
goto __pyx_L10_break; /* … */ goto __pyx_L9_break;
+1759: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L10_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L9_break:;
1760:
+1761: if state in (BEGIN_SPACE, NUM_SPACE):
switch (__pyx_v_state) { case __pyx_e_10quicktions_BEGIN_SPACE: case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; case __pyx_e_10quicktions_SMALL_NUM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_BEGIN_SPACE: case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; case __pyx_e_10quicktions_SMALL_NUM:
+1762: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
+1763: elif state == SMALL_NUM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1764: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1764, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1764, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+1765: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
+1766: elif state == NUM:
break; default: /* … */ break; default:
+1767: num = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_3 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1767, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1767, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+1768: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
1769: else:
+1770: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1770, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1770, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1770, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1771: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
1772:
+1773: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1773, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1773, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1773, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+1774: continue
goto __pyx_L4_continue; break; } /* … */ goto __pyx_L3_continue; break; }
1775:
1776: # normal digit found
+1777: if state in (BEGIN_SPACE, BEGIN_SIGN, SMALL_NUM, SMALL_NUM_US):
switch (__pyx_v_state) { case __pyx_e_10quicktions_BEGIN_SPACE: case __pyx_e_10quicktions_BEGIN_SIGN: case __pyx_e_10quicktions_SMALL_NUM: case __pyx_e_10quicktions_SMALL_NUM_US: /* … */ break; case __pyx_e_10quicktions_NUM_US: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_BEGIN_SPACE: case __pyx_e_10quicktions_BEGIN_SIGN: case __pyx_e_10quicktions_SMALL_NUM: case __pyx_e_10quicktions_SMALL_NUM_US: /* … */ break; case __pyx_e_10quicktions_NUM_US:
+1778: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1779: state = SMALL_NUM
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
1780:
1781: # fast-path for consecutive digits
+1782: while pos < s_len and inum <= MAX_SMALL_NUMBER:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_2) { } else { __pyx_t_6 = __pyx_t_2; goto __pyx_L14_bool_binop_done; } __pyx_t_2 = (__pyx_v_inum <= (PY_LLONG_MAX / 100)); __pyx_t_6 = __pyx_t_2; __pyx_L14_bool_binop_done:; if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_3) { } else { __pyx_t_7 = __pyx_t_3; goto __pyx_L13_bool_binop_done; } __pyx_t_3 = (__pyx_v_inum <= (PY_LLONG_MAX / 100)); __pyx_t_7 = __pyx_t_3; __pyx_L13_bool_binop_done:; if (!__pyx_t_7) break;
+1783: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1784: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1784, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1784, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1785: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_digit == -1L); if (__pyx_t_7) { /* … */ }
+1786: break
goto __pyx_L13_break; /* … */ goto __pyx_L12_break;
+1787: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1788: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L13_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L12_break:;
1789:
+1790: if inum > MAX_SMALL_NUMBER:
__pyx_t_6 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (__pyx_t_7) { /* … */ }
+1791: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM;
+1792: elif state == NUM_US:
break; default: break; } /* … */ break; default: break; }
+1793: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM;
1794:
1795: # We might have switched to NUM above, so continue right here in that case.
+1796: if state == SMALL_NUM:
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: break; case __pyx_e_10quicktions_NUM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: break; case __pyx_e_10quicktions_NUM:
1797: pass # handled above
+1798: elif state == NUM:
break; default: /* … */ break; default:
1799: # fast-path for consecutive digits
+1800: while pos < s_len:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_7) break;
+1801: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1802: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1802, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1802, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1803: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_digit == -1L); if (__pyx_t_7) { /* … */ }
+1804: break
goto __pyx_L19_break; /* … */ goto __pyx_L18_break;
+1805: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L19_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L18_break:;
1806: else:
+1807: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } __pyx_L4_continue:; } __pyx_L5_break:; /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1807, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L3_continue:; } __pyx_L4_break:;
1808:
+1809: if state == DENOM_START:
switch (__pyx_v_state) { case __pyx_e_10quicktions_DENOM_START: /* … */ break; case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DENOM_START: /* … */ break; case __pyx_e_10quicktions_SMALL_DECIMAL_DOT:
1810: # NUM '/' | SMALL_NUM '/'
+1811: while pos < s_len:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_7) break;
+1812: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1813: if not c.isspace():
__pyx_t_6 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_2 = (!__pyx_t_6); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_7 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_3 = (!__pyx_t_7); if (__pyx_t_3) { /* … */ }
+1814: break
goto __pyx_L22_break; /* … */ goto __pyx_L21_break;
+1815: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L22_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L21_break:;
1816:
+1817: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1818: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1819: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1820: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1820, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1820, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1821: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+1822: if c in u'-+':
switch (__pyx_v_c) { case 43: case 45: /* … */ break; case 95: /* … */ switch (__pyx_v_c) { case 43: case 45: /* … */ break; case 95:
+1823: if state == DENOM_START:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_DENOM_START); if (__pyx_t_2) { /* … */ goto __pyx_L27; } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_DENOM_START); if (__pyx_t_3) { /* … */ goto __pyx_L26; }
+1824: is_neg ^= (c == u'-')
__pyx_v_is_neg = (__pyx_v_is_neg ^ (__pyx_v_c == 45)); /* … */ __pyx_v_is_neg = (__pyx_v_is_neg ^ (__pyx_v_c == 45));
+1825: state = DENOM_SIGN
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
1826: else:
+1827: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1827, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L27:; /* … */ /*else*/ { __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1827, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1827, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __pyx_L26:;
+1828: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
+1829: elif c == u'_':
break; default: /* … */ break; default:
+1830: if state == SMALL_DENOM:
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DENOM: /* … */ break; case __pyx_e_10quicktions_DENOM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DENOM: /* … */ break; case __pyx_e_10quicktions_DENOM:
+1831: state = SMALL_DENOM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
+1832: elif state == DENOM:
break; default: /* … */ break; default:
+1833: state = DENOM_US
__pyx_v_state = __pyx_e_10quicktions_DENOM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_US;
1834: else:
+1835: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1835, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1835, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1835, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1836: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
1837: else:
+1838: if c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1839: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1840: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1841: if not c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_7 = (!__pyx_t_3); if (__pyx_t_7) { /* … */ }
+1842: break
goto __pyx_L30_break; /* … */ goto __pyx_L29_break;
+1843: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L30_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L29_break:;
1844:
+1845: if state in (DENOM_START, DENOM_SPACE):
switch (__pyx_v_state) { case __pyx_e_10quicktions_DENOM_START: case __pyx_e_10quicktions_DENOM_SPACE: break; case __pyx_e_10quicktions_SMALL_DENOM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DENOM_START: case __pyx_e_10quicktions_DENOM_SPACE: break; case __pyx_e_10quicktions_SMALL_DENOM:
1846: pass
+1847: elif state == SMALL_DENOM:
break; case __pyx_e_10quicktions_DENOM: /* … */ break; case __pyx_e_10quicktions_DENOM:
+1848: denom = idenom
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
+1849: elif state == DENOM:
break; default: /* … */ break; default:
+1850: denom = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_3 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
1851: else:
+1852: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; }
+1853: state = DENOM_SPACE
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
+1854: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
1855:
+1856: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1857: continue
goto __pyx_L24_continue; break; } /* … */ goto __pyx_L23_continue; break; }
1858:
1859: # normal digit found
+1860: if state in (DENOM_START, DENOM_SIGN, SMALL_DENOM, SMALL_DENOM_US):
switch (__pyx_v_state) { case __pyx_e_10quicktions_DENOM_START: case __pyx_e_10quicktions_DENOM_SIGN: case __pyx_e_10quicktions_SMALL_DENOM: case __pyx_e_10quicktions_SMALL_DENOM_US: /* … */ break; case __pyx_e_10quicktions_DENOM_US: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DENOM_START: case __pyx_e_10quicktions_DENOM_SIGN: case __pyx_e_10quicktions_SMALL_DENOM: case __pyx_e_10quicktions_SMALL_DENOM_US: /* … */ break; case __pyx_e_10quicktions_DENOM_US:
+1861: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit); /* … */ __pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+1862: state = SMALL_DENOM
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
1863:
1864: # fast-path for consecutive digits
+1865: while pos < s_len and idenom <= MAX_SMALL_NUMBER:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_2) { } else { __pyx_t_6 = __pyx_t_2; goto __pyx_L34_bool_binop_done; } __pyx_t_2 = (__pyx_v_idenom <= (PY_LLONG_MAX / 100)); __pyx_t_6 = __pyx_t_2; __pyx_L34_bool_binop_done:; if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_3) { } else { __pyx_t_7 = __pyx_t_3; goto __pyx_L33_bool_binop_done; } __pyx_t_3 = (__pyx_v_idenom <= (PY_LLONG_MAX / 100)); __pyx_t_7 = __pyx_t_3; __pyx_L33_bool_binop_done:; if (!__pyx_t_7) break;
+1866: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1867: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1867, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1867, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1868: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_digit == -1L); if (__pyx_t_7) { /* … */ }
+1869: break
goto __pyx_L33_break; /* … */ goto __pyx_L32_break;
+1870: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit); /* … */ __pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+1871: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L33_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L32_break:;
1872:
+1873: if idenom > MAX_SMALL_NUMBER:
__pyx_t_6 = (__pyx_v_idenom > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_idenom > (PY_LLONG_MAX / 100)); if (__pyx_t_7) { /* … */ }
+1874: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM;
+1875: elif state == DENOM_US:
break; default: break; } /* … */ break; default: break; }
+1876: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM;
1877:
1878: # We might have switched to DENOM above, so continue right here in that case.
+1879: if state == SMALL_DENOM:
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DENOM: break; case __pyx_e_10quicktions_DENOM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DENOM: break; case __pyx_e_10quicktions_DENOM:
1880: pass # handled above
+1881: elif state == DENOM:
break; default: /* … */ break; default:
1882: # fast-path for consecutive digits
+1883: while pos < s_len:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_7) break;
+1884: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1885: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1885, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1885, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1886: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_digit == -1L); if (__pyx_t_7) { /* … */ }
+1887: break
goto __pyx_L39_break; /* … */ goto __pyx_L38_break;
+1888: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L39_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L38_break:;
1889: else:
+1890: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1890, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } __pyx_L24_continue:; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1890, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1890, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; } __pyx_L23_continue:; }
1891:
+1892: elif state in (SMALL_DECIMAL_DOT, START_DECIMAL_DOT):
case __pyx_e_10quicktions_START_DECIMAL_DOT: /* … */ break; default: break; } /* … */ case __pyx_e_10quicktions_START_DECIMAL_DOT: /* … */ break; default: break; }
1893: # SMALL_NUM '.' | '.'
+1894: while pos < s_len:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_7) break;
+1895: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1896: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1897: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1897, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1897, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1898: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_digit == -1L); if (__pyx_t_7) { /* … */ }
+1899: if c == u'_':
switch (__pyx_v_c) { case 95: /* … */ break; case 69: /* … */ switch (__pyx_v_c) { case 95: /* … */ break; case 69:
+1900: if state == SMALL_DECIMAL:
__pyx_t_6 = (__pyx_v_state == __pyx_e_10quicktions_SMALL_DECIMAL); if (__pyx_t_6) { /* … */ goto __pyx_L44; } /* … */ __pyx_t_7 = (__pyx_v_state == __pyx_e_10quicktions_SMALL_DECIMAL); if (__pyx_t_7) { /* … */ goto __pyx_L43; }
+1901: state = SMALL_DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
1902: else:
+1903: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1903, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L44:; /* … */ /*else*/ { __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1903, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1903, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L43:;
+1904: continue
goto __pyx_L41_continue; /* … */ goto __pyx_L40_continue;
+1905: elif c in u'eE':
case 0x65: /* … */ break; default: /* … */ case 0x65: /* … */ break; default:
+1906: if state in (SMALL_DECIMAL_DOT, SMALL_DECIMAL):
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_DECIMAL: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_DECIMAL: /* … */ break; default:
+1907: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1907, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1907, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1908: else:
+1909: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1909, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1909, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1909, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; }
+1910: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1911: break
goto __pyx_L42_break; /* … */ goto __pyx_L41_break;
1912: else:
+1913: if c.isspace():
__pyx_t_6 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_7) { /* … */ }
+1914: while pos < s_len:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_7) break;
+1915: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1916: if not c.isspace():
__pyx_t_6 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_2 = (!__pyx_t_6); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_7 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_3 = (!__pyx_t_7); if (__pyx_t_3) { /* … */ }
+1917: break
goto __pyx_L47_break; /* … */ goto __pyx_L46_break;
+1918: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L47_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L46_break:;
1919:
+1920: if state in (SMALL_DECIMAL, SMALL_DECIMAL_DOT):
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DECIMAL: case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_DECIMAL: case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: /* … */ break; default:
+1921: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1921, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1921, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+1922: state = SMALL_END_SPACE
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
1923: else:
+1924: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1924, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1924, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1924, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1925: continue
goto __pyx_L41_continue; /* … */ goto __pyx_L40_continue;
1926:
+1927: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1927, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1927, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1927, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+1928: continue
goto __pyx_L41_continue; break; } /* … */ goto __pyx_L40_continue; break; }
1929:
1930: # normal digit found
+1931: if state in (START_DECIMAL_DOT, SMALL_DECIMAL_DOT, SMALL_DECIMAL, SMALL_DECIMAL_US):
switch (__pyx_v_state) { case __pyx_e_10quicktions_START_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_DECIMAL: case __pyx_e_10quicktions_SMALL_DECIMAL_US: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_START_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_DECIMAL: case __pyx_e_10quicktions_SMALL_DECIMAL_US: /* … */ break; default:
+1932: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1933: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1934: state = SMALL_DECIMAL
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
1935:
1936: # fast-path for consecutive digits
+1937: while pos < s_len and inum <= MAX_SMALL_NUMBER and decimal_len < max_decimal_len:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { } else { __pyx_t_2 = __pyx_t_6; goto __pyx_L51_bool_binop_done; } __pyx_t_6 = (__pyx_v_inum <= (PY_LLONG_MAX / 100)); if (__pyx_t_6) { } else { __pyx_t_2 = __pyx_t_6; goto __pyx_L51_bool_binop_done; } __pyx_t_6 = (__pyx_v_decimal_len < __pyx_v_max_decimal_len); __pyx_t_2 = __pyx_t_6; __pyx_L51_bool_binop_done:; if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L50_bool_binop_done; } __pyx_t_7 = (__pyx_v_inum <= (PY_LLONG_MAX / 100)); if (__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L50_bool_binop_done; } __pyx_t_7 = (__pyx_v_decimal_len < __pyx_v_max_decimal_len); __pyx_t_3 = __pyx_t_7; __pyx_L50_bool_binop_done:; if (!__pyx_t_3) break;
+1938: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1939: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1939, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1939, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1940: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+1941: break
goto __pyx_L50_break; /* … */ goto __pyx_L49_break;
+1942: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1943: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1944: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L50_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L49_break:;
1945:
+1946: if inum > MAX_SMALL_NUMBER or decimal_len >= max_decimal_len:
__pyx_t_6 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (!__pyx_t_6) { } else { __pyx_t_2 = __pyx_t_6; goto __pyx_L56_bool_binop_done; } __pyx_t_6 = (__pyx_v_decimal_len >= __pyx_v_max_decimal_len); __pyx_t_2 = __pyx_t_6; __pyx_L56_bool_binop_done:; if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (!__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L55_bool_binop_done; } __pyx_t_7 = (__pyx_v_decimal_len >= __pyx_v_max_decimal_len); __pyx_t_3 = __pyx_t_7; __pyx_L55_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1947: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL;
+1948: break
goto __pyx_L42_break; /* … */ goto __pyx_L41_break;
1949: else:
+1950: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1950, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } __pyx_L41_continue:; } __pyx_L42_break:; /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1950, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1950, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L40_continue:; } __pyx_L41_break:;
1951:
+1952: if state in (DECIMAL_DOT, DECIMAL):
switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL_DOT: case __pyx_e_10quicktions_DECIMAL: /* … */ break; default: break; } /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL_DOT: case __pyx_e_10quicktions_DECIMAL: /* … */ break; default: break; }
1953: # NUM '.' | SMALL_DECIMAL->DECIMAL
+1954: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1955: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1956: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1957: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1957, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1957, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1958: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+1959: if c == u'_':
switch (__pyx_v_c) { case 95: /* … */ break; case 69: /* … */ switch (__pyx_v_c) { case 95: /* … */ break; case 69:
+1960: if state == DECIMAL:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_DECIMAL); if (__pyx_t_2) { /* … */ goto __pyx_L61; } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_DECIMAL); if (__pyx_t_3) { /* … */ goto __pyx_L60; }
+1961: state = DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
1962: else:
+1963: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L61:; /* … */ /*else*/ { __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __pyx_L60:;
+1964: continue
goto __pyx_L58_continue; /* … */ goto __pyx_L57_continue;
+1965: elif c in u'eE':
case 0x65: /* … */ break; default: /* … */ case 0x65: /* … */ break; default:
+1966: if state in (DECIMAL_DOT, DECIMAL):
switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL_DOT: case __pyx_e_10quicktions_DECIMAL: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL_DOT: case __pyx_e_10quicktions_DECIMAL: /* … */ break; default:
+1967: num = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_3 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1967, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1967, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
1968: else:
+1969: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1969, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1969, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1969, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1970: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1971: break
goto __pyx_L59_break; /* … */ goto __pyx_L58_break;
1972: else:
+1973: if c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1974: if state in (DECIMAL, DECIMAL_DOT):
switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL: case __pyx_e_10quicktions_DECIMAL_DOT: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL: case __pyx_e_10quicktions_DECIMAL_DOT: /* … */ break; default:
+1975: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_END_SPACE;
1976: else:
+1977: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1977, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1977, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1977, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; }
+1978: break
goto __pyx_L59_break; /* … */ goto __pyx_L58_break;
1979:
+1980: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1981: continue
goto __pyx_L58_continue; break; } /* … */ goto __pyx_L57_continue; break; }
1982:
1983: # normal digit found
+1984: if state in (DECIMAL_DOT, DECIMAL, DECIMAL_US):
switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL_DOT: case __pyx_e_10quicktions_DECIMAL: case __pyx_e_10quicktions_DECIMAL_US: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_DECIMAL_DOT: case __pyx_e_10quicktions_DECIMAL: case __pyx_e_10quicktions_DECIMAL_US: /* … */ break; default:
+1985: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1986: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL;
1987:
1988: # fast-path for consecutive digits
+1989: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1990: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1991: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1991, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit((&__pyx_v_c_digits), __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 1991, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1992: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+1993: break
goto __pyx_L64_break; /* … */ goto __pyx_L63_break;
+1994: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1995: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L64_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L63_break:;
1996: else:
+1997: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1997, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } __pyx_L58_continue:; } __pyx_L59_break:; /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1997, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1997, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; } __pyx_L57_continue:; } __pyx_L58_break:;
1998:
+1999: if state == EXP_E:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_EXP_E); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_EXP_E); if (__pyx_t_3) { /* … */ }
2000: # (SMALL_) NUM ['.' DECIMAL] 'E'
+2001: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+2002: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+2003: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+2004: digit = _parse_digit(NULL, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit(NULL, __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2004, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit(NULL, __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2004, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2005: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+2006: if c in u'-+':
switch (__pyx_v_c) { case 43: case 45: /* … */ break; case 95: /* … */ switch (__pyx_v_c) { case 43: case 45: /* … */ break; case 95:
+2007: if state == EXP_E:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_EXP_E); if (__pyx_t_2) { /* … */ goto __pyx_L70; } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_EXP_E); if (__pyx_t_3) { /* … */ goto __pyx_L69; }
+2008: exp_is_neg = c == u'-'
__pyx_v_exp_is_neg = (__pyx_v_c == 45); /* … */ __pyx_v_exp_is_neg = (__pyx_v_c == 45);
+2009: state = EXP_SIGN
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
2010: else:
+2011: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2011, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L70:; /* … */ /*else*/ { __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2011, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2011, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L69:;
+2012: continue
goto __pyx_L67_continue; /* … */ goto __pyx_L66_continue;
+2013: elif c == u'_':
break; default: /* … */ break; default:
+2014: if state == EXP:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_EXP); if (__pyx_t_2) { /* … */ goto __pyx_L71; } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_EXP); if (__pyx_t_3) { /* … */ goto __pyx_L70; }
+2015: state = EXP_US
__pyx_v_state = __pyx_e_10quicktions_EXP_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_US;
2016: else:
+2017: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2017, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L71:; /* … */ /*else*/ { __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2017, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2017, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __pyx_L70:;
+2018: continue
goto __pyx_L67_continue; /* … */ goto __pyx_L66_continue;
2019: else:
+2020: if c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+2021: if state == EXP:
__pyx_t_2 = (__pyx_v_state == __pyx_e_10quicktions_EXP); if (__pyx_t_2) { /* … */ goto __pyx_L73; } /* … */ __pyx_t_3 = (__pyx_v_state == __pyx_e_10quicktions_EXP); if (__pyx_t_3) { /* … */ goto __pyx_L72; }
+2022: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2023: else:
+2024: _raise_invalid_input(s)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2024, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L73:; /* … */ /*else*/ { __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2024, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2024, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L72:;
+2025: break
goto __pyx_L68_break; /* … */ goto __pyx_L67_break;
2026:
+2027: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+2028: continue
goto __pyx_L67_continue; break; } /* … */ goto __pyx_L66_continue; break; }
2029:
2030: # normal digit found
+2031: if state in (EXP_E, EXP_SIGN, EXP, EXP_US):
switch (__pyx_v_state) { case __pyx_e_10quicktions_EXP_E: case __pyx_e_10quicktions_EXP_SIGN: case __pyx_e_10quicktions_EXP: case __pyx_e_10quicktions_EXP_US: /* … */ break; default: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_EXP_E: case __pyx_e_10quicktions_EXP_SIGN: case __pyx_e_10quicktions_EXP: case __pyx_e_10quicktions_EXP_US: /* … */ break; default:
+2032: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit); /* … */ __pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2033: state = EXP
__pyx_v_state = __pyx_e_10quicktions_EXP; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP;
2034:
2035: # fast-path for consecutive digits
+2036: while pos < s_len and iexp <= MAX_SMALL_NUMBER:
while (1) { __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { } else { __pyx_t_2 = __pyx_t_6; goto __pyx_L76_bool_binop_done; } __pyx_t_6 = (__pyx_v_iexp <= (PY_LLONG_MAX / 100)); __pyx_t_2 = __pyx_t_6; __pyx_L76_bool_binop_done:; if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L75_bool_binop_done; } __pyx_t_7 = (__pyx_v_iexp <= (PY_LLONG_MAX / 100)); __pyx_t_3 = __pyx_t_7; __pyx_L75_bool_binop_done:; if (!__pyx_t_3) break;
+2037: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+2038: digit = _parse_digit(NULL, c, allow_unicode)
__pyx_t_1 = __pyx_f_10quicktions__parse_digit(NULL, __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_1 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2038, __pyx_L1_error) __pyx_v_digit = __pyx_t_1; /* … */ __pyx_t_5 = __pyx_f_10quicktions__parse_digit(NULL, __pyx_v_c, __pyx_v_allow_unicode); if (unlikely(__pyx_t_5 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 2038, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2039: if digit == -1:
__pyx_t_2 = (__pyx_v_digit == -1L); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_digit == -1L); if (__pyx_t_3) { /* … */ }
+2040: break
goto __pyx_L75_break; /* … */ goto __pyx_L74_break;
+2041: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit); /* … */ __pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2042: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L75_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L74_break:;
2043:
+2044: if iexp > MAX_SMALL_NUMBER:
__pyx_t_2 = (__pyx_v_iexp > (PY_LLONG_MAX / 100)); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = (__pyx_v_iexp > (PY_LLONG_MAX / 100)); if (__pyx_t_3) { /* … */ }
+2045: _raise_parse_overflow(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2046: else:
+2047: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2047, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } __pyx_L67_continue:; } __pyx_L68_break:; /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2047, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2047, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; break; } __pyx_L66_continue:; } __pyx_L67_break:;
2048:
+2049: if state in (END_SPACE, SMALL_END_SPACE, DENOM_SPACE):
switch (__pyx_v_state) { case __pyx_e_10quicktions_END_SPACE: case __pyx_e_10quicktions_SMALL_END_SPACE: case __pyx_e_10quicktions_DENOM_SPACE: /* … */ break; default: break; } /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_END_SPACE: case __pyx_e_10quicktions_SMALL_END_SPACE: case __pyx_e_10quicktions_DENOM_SPACE: /* … */ break; default: break; }
+2050: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+2051: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+2052: if not c.isspace():
__pyx_t_2 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_7 = (!__pyx_t_3); if (__pyx_t_7) { /* … */ }
+2053: break
goto __pyx_L81_break; /* … */ goto __pyx_L80_break;
+2054: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L81_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L80_break:;
2055:
+2056: if pos < s_len :
__pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_7) { /* … */ }
+2057: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2058:
+2059: is_normalised = False
__Pyx_INCREF(Py_False); __pyx_v_is_normalised = Py_False; /* … */ __Pyx_INCREF(Py_False); __pyx_v_is_normalised = Py_False;
+2060: if state in (SMALL_NUM, SMALL_DECIMAL, SMALL_DECIMAL_DOT, SMALL_END_SPACE):
switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: case __pyx_e_10quicktions_SMALL_DECIMAL: case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_END_SPACE: /* … */ break; case __pyx_e_10quicktions_SMALL_DENOM: /* … */ switch (__pyx_v_state) { case __pyx_e_10quicktions_SMALL_NUM: case __pyx_e_10quicktions_SMALL_DECIMAL: case __pyx_e_10quicktions_SMALL_DECIMAL_DOT: case __pyx_e_10quicktions_SMALL_END_SPACE: /* … */ break; case __pyx_e_10quicktions_SMALL_DENOM:
2061: # Special case for 'small' numbers: normalise directly in C space.
+2062: if inum and decimal_len:
__pyx_t_2 = (__pyx_v_inum != 0); if (__pyx_t_2) { } else { __pyx_t_6 = __pyx_t_2; goto __pyx_L85_bool_binop_done; } __pyx_t_2 = (__pyx_v_decimal_len != 0); __pyx_t_6 = __pyx_t_2; __pyx_L85_bool_binop_done:; if (__pyx_t_6) { /* … */ goto __pyx_L84; } /* … */ __pyx_t_3 = (__pyx_v_inum != 0); if (__pyx_t_3) { } else { __pyx_t_7 = __pyx_t_3; goto __pyx_L84_bool_binop_done; } __pyx_t_3 = (__pyx_v_decimal_len != 0); __pyx_t_7 = __pyx_t_3; __pyx_L84_bool_binop_done:; if (__pyx_t_7) { /* … */ goto __pyx_L83; }
2063: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2064: if inum & 1 == 0 or inum % 5 == 0:
__pyx_t_2 = ((__pyx_v_inum & 1) == 0); if (!__pyx_t_2) { } else { __pyx_t_6 = __pyx_t_2; goto __pyx_L88_bool_binop_done; } __pyx_t_2 = ((__pyx_v_inum % 5) == 0); __pyx_t_6 = __pyx_t_2; __pyx_L88_bool_binop_done:; if (__pyx_t_6) { /* … */ goto __pyx_L87; } /* … */ __pyx_t_3 = ((__pyx_v_inum & 1) == 0); if (!__pyx_t_3) { } else { __pyx_t_7 = __pyx_t_3; goto __pyx_L87_bool_binop_done; } __pyx_t_3 = ((__pyx_v_inum % 5) == 0); __pyx_t_7 = __pyx_t_3; __pyx_L87_bool_binop_done:; if (__pyx_t_7) { /* … */ goto __pyx_L86; }
+2065: idenom = _c_pow10(decimal_len)
__pyx_t_7 = __pyx_f_10quicktions__c_pow10(__pyx_v_decimal_len); if (unlikely(__pyx_t_7 == ((unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 2065, __pyx_L1_error) __pyx_v_idenom = __pyx_t_7; /* … */ __pyx_t_8 = __pyx_f_10quicktions__c_pow10(__pyx_v_decimal_len); if (unlikely(__pyx_t_8 == ((unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 2065, __pyx_L1_error) __pyx_v_idenom = __pyx_t_8;
+2066: igcd = _c_gcd(inum, idenom)
__pyx_t_8 = __pyx_f_10quicktions__c_gcd(__pyx_v_inum, __pyx_v_idenom); if (unlikely(__pyx_t_8 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 2066, __pyx_L1_error) __pyx_v_igcd = __pyx_t_8; /* … */ __pyx_t_9 = __pyx_f_10quicktions__c_gcd(__pyx_v_inum, __pyx_v_idenom); if (unlikely(__pyx_t_9 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 2066, __pyx_L1_error) __pyx_v_igcd = __pyx_t_9;
+2067: if igcd > 1:
__pyx_t_6 = (__pyx_v_igcd > 1); if (__pyx_t_6) { /* … */ goto __pyx_L90; } /* … */ __pyx_t_7 = (__pyx_v_igcd > 1); if (__pyx_t_7) { /* … */ goto __pyx_L89; }
+2068: inum //= igcd
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd); /* … */ __pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
+2069: denom = idenom // igcd
__pyx_t_3 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG((__pyx_v_idenom / __pyx_v_igcd)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2069, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG((__pyx_v_idenom / __pyx_v_igcd)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2069, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2070: else:
+2071: denom = pow10(decimal_len)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2071, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_3); __pyx_t_3 = 0; } __pyx_L90:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2071, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L89:;
2072: else:
+2073: denom = pow10(decimal_len)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2073, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_3); __pyx_t_3 = 0; } __pyx_L87:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2073, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L86:;
2074: else:
+2075: denom = 1
/*else*/ { __Pyx_INCREF(__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_int_1); } __pyx_L84:; /* … */ /*else*/ { __Pyx_INCREF(__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_int_1); } __pyx_L83:;
+2076: if is_neg:
if (__pyx_v_is_neg) { /* … */ } /* … */ if (__pyx_v_is_neg) { /* … */ }
+2077: inum = -inum
__pyx_v_inum = (-__pyx_v_inum); /* … */ __pyx_v_inum = (-__pyx_v_inum);
+2078: return inum, denom, True
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2078, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2078, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_3)) __PYX_ERR(0, 2078, __pyx_L1_error); __Pyx_INCREF(__pyx_v_denom); __Pyx_GIVEREF(__pyx_v_denom); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_v_denom)) __PYX_ERR(0, 2078, __pyx_L1_error); __Pyx_INCREF(Py_True); __Pyx_GIVEREF(Py_True); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, Py_True)) __PYX_ERR(0, 2078, __pyx_L1_error); __pyx_t_3 = 0; __pyx_r = ((PyObject*)__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L0; /* … */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2078, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2078, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1)) __PYX_ERR(0, 2078, __pyx_L1_error); __Pyx_INCREF(__pyx_v_denom); __Pyx_GIVEREF(__pyx_v_denom); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_v_denom)) __PYX_ERR(0, 2078, __pyx_L1_error); __Pyx_INCREF(Py_True); __Pyx_GIVEREF(Py_True); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 2, Py_True)) __PYX_ERR(0, 2078, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = ((PyObject*)__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L0;
2079:
+2080: elif state == SMALL_DENOM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+2081: denom = idenom
__pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_t_6 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_6); __pyx_t_6 = 0;
+2082: elif state in (NUM, DECIMAL, DECIMAL_DOT):
case __pyx_e_10quicktions_DECIMAL: case __pyx_e_10quicktions_DECIMAL_DOT: /* … */ break; case __pyx_e_10quicktions_DENOM: /* … */ case __pyx_e_10quicktions_DECIMAL: case __pyx_e_10quicktions_DECIMAL_DOT: /* … */ break; case __pyx_e_10quicktions_DENOM:
+2083: is_normalised = True # will be repaired below for iexp < 0
__Pyx_INCREF(Py_True); __Pyx_DECREF_SET(__pyx_v_is_normalised, Py_True); /* … */ __Pyx_INCREF(Py_True); __Pyx_DECREF_SET(__pyx_v_is_normalised, Py_True);
+2084: denom = 1
__Pyx_INCREF(__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_int_1); /* … */ __Pyx_INCREF(__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_int_1);
+2085: num = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_9 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2085, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_t_6 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2085, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+2086: elif state == DENOM:
break; case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; case __pyx_e_10quicktions_NUM_SPACE:
+2087: denom = _parse_pylong(c_digits_start, &c_digits)
__pyx_t_9 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_t_6 = __pyx_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_6); __pyx_t_6 = 0;
+2088: elif state in (NUM_SPACE, EXP, END_SPACE):
case __pyx_e_10quicktions_EXP: case __pyx_e_10quicktions_END_SPACE: /* … */ break; case __pyx_e_10quicktions_DENOM_SPACE: /* … */ case __pyx_e_10quicktions_EXP: case __pyx_e_10quicktions_END_SPACE: /* … */ break; case __pyx_e_10quicktions_DENOM_SPACE:
+2089: is_normalised = True
__Pyx_INCREF(Py_True); __Pyx_DECREF_SET(__pyx_v_is_normalised, Py_True); /* … */ __Pyx_INCREF(Py_True); __Pyx_DECREF_SET(__pyx_v_is_normalised, Py_True);
+2090: denom = 1
__Pyx_INCREF(__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_int_1); /* … */ __Pyx_INCREF(__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_int_1);
+2091: elif state == DENOM_SPACE:
break; default: /* … */ break; default:
2092: pass
2093: else:
+2094: _raise_invalid_input(s)
__pyx_t_9 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2094, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; break; } /* … */ __pyx_t_6 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2094, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2094, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
2095:
+2096: if decimal_len > MAX_SMALL_NUMBER:
__pyx_t_6 = (__pyx_v_decimal_len > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_7 = (__pyx_v_decimal_len > (PY_LLONG_MAX / 100)); if (__pyx_t_7) { /* … */ }
+2097: _raise_parse_overflow(s)
__pyx_t_9 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_s); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_t_1 = __Pyx_PyBytes_FromString(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_t_1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
+2098: if exp_is_neg:
if (__pyx_v_exp_is_neg) { /* … */ } /* … */ if (__pyx_v_exp_is_neg) { /* … */ }
+2099: iexp = -iexp
__pyx_v_iexp = (-__pyx_v_iexp); /* … */ __pyx_v_iexp = (-__pyx_v_iexp);
+2100: iexp -= decimal_len
__pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len); /* … */ __pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len);
2101:
+2102: if iexp > 0:
__pyx_t_6 = (__pyx_v_iexp > 0); if (__pyx_t_6) { /* … */ goto __pyx_L94; } /* … */ __pyx_t_7 = (__pyx_v_iexp > 0); if (__pyx_t_7) { /* … */ goto __pyx_L93; }
+2103: num *= pow10(iexp)
__pyx_t_9 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_3 = PyNumber_InPlaceMultiply(__pyx_v_num, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_1 = PyNumber_InPlaceMultiply(__pyx_v_num, __pyx_t_6); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+2104: elif iexp < 0:
__pyx_t_6 = (__pyx_v_iexp < 0); if (__pyx_t_6) { /* … */ } __pyx_L94:; /* … */ __pyx_t_7 = (__pyx_v_iexp < 0); if (__pyx_t_7) { /* … */ } __pyx_L93:;
2105: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2106: is_normalised = num & 1 and num % 5
__pyx_t_9 = __Pyx_PyInt_AndObjC(__pyx_v_num, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 2106, __pyx_L1_error) if (__pyx_t_6) { __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } else { __Pyx_INCREF(__pyx_t_9); __pyx_t_3 = __pyx_t_9; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L95_bool_binop_done; } __pyx_t_9 = __Pyx_PyInt_RemainderObjC(__pyx_v_num, __pyx_int_5, 5, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_INCREF(__pyx_t_9); __pyx_t_3 = __pyx_t_9; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_L95_bool_binop_done:; __Pyx_DECREF_SET(__pyx_v_is_normalised, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_6 = __Pyx_PyInt_AndObjC(__pyx_v_num, __pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 2106, __pyx_L1_error) if (__pyx_t_7) { __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } else { __Pyx_INCREF(__pyx_t_6); __pyx_t_1 = __pyx_t_6; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L94_bool_binop_done; } __pyx_t_6 = __Pyx_PyInt_RemainderObjC(__pyx_v_num, __pyx_int_5, 5, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_INCREF(__pyx_t_6); __pyx_t_1 = __pyx_t_6; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_L94_bool_binop_done:; __Pyx_DECREF_SET(__pyx_v_is_normalised, __pyx_t_1); __pyx_t_1 = 0;
+2107: denom = pow10(-iexp)
__pyx_t_3 = __pyx_f_10quicktions_pow10((-__pyx_v_iexp)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions_pow10((-__pyx_v_iexp)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2107, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2108:
+2109: if is_neg:
if (__pyx_v_is_neg) { /* … */ } /* … */ if (__pyx_v_is_neg) { /* … */ }
+2110: num = -num
__pyx_t_3 = PyNumber_Negative(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = PyNumber_Negative(__pyx_v_num); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2110, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2111:
+2112: return num, denom, is_normalised
__Pyx_XDECREF(__pyx_r); if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2112, __pyx_L1_error) } __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2112, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_v_num); __Pyx_GIVEREF(__pyx_v_num); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_v_num)) __PYX_ERR(0, 2112, __pyx_L1_error); __Pyx_INCREF(__pyx_v_denom); __Pyx_GIVEREF(__pyx_v_denom); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_v_denom)) __PYX_ERR(0, 2112, __pyx_L1_error); __Pyx_INCREF(__pyx_v_is_normalised); __Pyx_GIVEREF(__pyx_v_is_normalised); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_v_is_normalised)) __PYX_ERR(0, 2112, __pyx_L1_error); __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0; /* … */ __Pyx_XDECREF(__pyx_r); if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2112, __pyx_L1_error) } __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2112, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_num); __Pyx_GIVEREF(__pyx_v_num); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_num)) __PYX_ERR(0, 2112, __pyx_L1_error); __Pyx_INCREF(__pyx_v_denom); __Pyx_GIVEREF(__pyx_v_denom); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_denom)) __PYX_ERR(0, 2112, __pyx_L1_error); __Pyx_INCREF(__pyx_v_is_normalised); __Pyx_GIVEREF(__pyx_v_is_normalised); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_is_normalised)) __PYX_ERR(0, 2112, __pyx_L1_error); __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;