Generated by Cython 3.0.11
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_3 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (PyDict_SetItem(__pyx_t_3, __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_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 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.19'
if (PyDict_SetItem(__pyx_d, __pyx_n_s_version, __pyx_kp_s_1_19) < 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.long cimport PyLong_FromString
0034:
0035: cdef extern from *:
0036: cdef long LONG_MAX, INT_MAX
0037: cdef long long PY_LLONG_MIN, PY_LLONG_MAX
0038: cdef long long MAX_SMALL_NUMBER "(PY_LLONG_MAX / 100)"
0039:
0040: cdef object Rational, Integral, Real, Complex, Decimal, math, operator, re, sys
+0041: 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, 41, __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;
0042:
+0043: from numbers import Rational, Integral, Real, Complex
__pyx_t_2 = PyList_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __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, 43, __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, 43, __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, 43, __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, 43, __pyx_L1_error); __pyx_t_3 = __Pyx_Import(__pyx_n_s_numbers, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 43, __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, 43, __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, 43, __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, 43, __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, 43, __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;
+0044: from decimal import Decimal
__pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 44, __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, 44, __pyx_L1_error); __pyx_t_2 = __Pyx_Import(__pyx_n_s_decimal, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __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, 44, __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;
+0045: import math
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_math, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __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;
+0046: import operator
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_operator, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 46, __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;
+0047: import re
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_re, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __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;
+0048: import sys
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_sys, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __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;
0049:
+0050: 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, 50, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_10quicktions__decimal_supports_integer_ratio = __pyx_t_4;
+0051: 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, 51, __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;
0052: cdef object math_gcd
+0053: 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:; }
+0054: 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, 54, __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;
+0055: 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;
0056: pass
0057:
0058:
0059: # Cache widely used 10**x int objects.
0060: DEF CACHED_POW10 = 64 # sys.getsizeof(tuple[58]) == 512 bytes in Py3.7
0061:
+0062: 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; }
0063: cdef int i
+0064: in_ull = True
__pyx_v_in_ull = 1;
+0065: l = []
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 65, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_l = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+0066: x = 1
__Pyx_INCREF(__pyx_int_1);
__pyx_v_x = __pyx_int_1;
+0067: 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;
+0068: 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, 68, __pyx_L1_error)
+0069: if in_ull:
if (__pyx_v_in_ull) { /* … */ }
+0070: 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:; }
+0071: _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, 71, __pyx_L6_error) (__pyx_v_10quicktions__C_POW_10[__pyx_v_i]) = __pyx_t_7;
+0072: 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, 72, __pyx_L8_except_error) __Pyx_XGOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_10);
+0073: 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;
+0074: 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, 74, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_10); __pyx_t_10 = 0; }
+0075: return tuple(l)
__Pyx_XDECREF(__pyx_r); __pyx_t_10 = PyList_AsTuple(__pyx_v_l); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 75, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_r = ((PyObject*)__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L0;
0076:
0077: cdef unsigned long long[CACHED_POW10] _C_POW_10
+0078: cdef tuple POW_10 = _cache_pow10()
__pyx_t_2 = __pyx_f_10quicktions__cache_pow10(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __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;
0079:
0080:
+0081: 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; }
+0082: return _C_POW_10[i]
__pyx_r = (__pyx_v_10quicktions__C_POW_10[__pyx_v_i]); goto __pyx_L0;
0083:
0084:
+0085: 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; }
+0086: 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) { /* … */ }
+0087: 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, 87, __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, 87, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0088: else:
+0089: 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, 89, __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, 89, __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; }
0090:
0091:
0092: # Half-private GCD implementation.
0093:
0094: cdef extern from *:
0095: """
0096: #if PY_VERSION_HEX >= 0x030c00a5 && defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
0097: #define __Quicktions_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) (x))
0098: #if CYTHON_COMPILING_IN_CPYTHON
0099: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) (((PyLongObject*)x)->long_value.ob_digit[0]))
0100: #else
0101: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) PyUnstable_Long_CompactValue((PyLongObject*) (x))))
0102: #endif
0103: #elif PY_VERSION_HEX < 0x030c0000 && CYTHON_COMPILING_IN_CPYTHON
0104: #define __Quicktions_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
0105: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) ((Py_SIZE(x) == 0) ? 0 : (((PyLongObject*)x)->ob_digit)[0]))
0106: #else
0107: #define __Quicktions_PyLong_IsCompact(x) (0)
0108: #define __Quicktions_PyLong_CompactValueUnsigned(x) (0U)
0109: #endif
0110: #if PY_VERSION_HEX < 0x030500F0 || PY_VERSION_HEX >= 0x030d0000 || !CYTHON_COMPILING_IN_CPYTHON
0111: #define _PyLong_GCD(a, b) (NULL)
0112: #endif
0113:
0114: #ifdef __GCC__
0115: #define __Quicktions_IS_GCC 1
0116: #define __Quicktions_trailing_zeros_uint(x) __builtin_ctz(x)
0117: #define __Quicktions_trailing_zeros_ulong(x) __builtin_ctzl(x)
0118: #define __Quicktions_trailing_zeros_ullong(x) __builtin_ctzll(x)
0119: #else
0120: #define __Quicktions_IS_GCC 0
0121: #define __Quicktions_trailing_zeros_uint(x) (0)
0122: #define __Quicktions_trailing_zeros_ulong(x) (0)
0123: #define __Quicktions_trailing_zeros_ullong(x) (0)
0124: #endif
0125: """
0126: bint PyLong_IsCompact "__Quicktions_PyLong_IsCompact" (x)
0127: Py_ssize_t PyLong_CompactValueUnsigned "__Quicktions_PyLong_CompactValueUnsigned" (x)
0128:
0129: # CPython 3.5-3.12 has a fast PyLong GCD implementation that we can use.
0130: # In CPython 3.13, math.gcd() is fast enough to call it directly.
0131: int PY_VERSION_HEX
0132: int HAS_PYLONG_GCD "(CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000)"
0133: _PyLong_GCD(a, b)
0134:
0135: bint IS_GCC "__Quicktions_IS_GCC"
0136: int trailing_zeros_uint "__Quicktions_trailing_zeros_uint" (unsigned int x)
0137: int trailing_zeros_ulong "__Quicktions_trailing_zeros_ulong" (unsigned long x)
0138: int trailing_zeros_ullong "__Quicktions_trailing_zeros_ullong" (unsigned long long x)
0139:
0140:
+0141: 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, 141, __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, 141, __pyx_L3_error) else { __Pyx_RaiseArgtupleInvalid("_gcd", 1, 2, 2, 1); __PYX_ERR(0, 141, __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, 141, __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, 141, __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, 141, __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, 141, __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, 141, __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, 141, __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, 141, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 141, __pyx_L1_error)
0142: """Calculate the Greatest Common Divisor of a and b as a non-negative number.
0143: """
+0144: 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) { /* … */ }
+0145: 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, 145, __pyx_L1_error) __pyx_t_4 = __Pyx_PyInt_From_unsigned_PY_LONG_LONG(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0146: if PY_VERSION_HEX >= 0x030d0000:
__pyx_t_1 = (PY_VERSION_HEX >= 0x030d0000); if (__pyx_t_1) { /* … */ }
+0147: 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, 147, __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;
+0148: 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) { /* … */ }
+0149: 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, 149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0150: 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, 150, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0151:
0152:
+0153: ctypedef unsigned long long ullong
typedef unsigned PY_LONG_LONG __pyx_t_10quicktions_ullong;
+0154: ctypedef unsigned long ulong
typedef unsigned long __pyx_t_10quicktions_ulong;
0155: ctypedef unsigned int uint
0156:
0157: ctypedef fused cunumber:
0158: ullong
0159: ulong
0160: uint
0161:
0162:
+0163: 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; }
+0164: if x == PY_LLONG_MIN:
__pyx_t_1 = (__pyx_v_x == PY_LLONG_MIN); if (__pyx_t_1) { /* … */ }
+0165: return (<ullong>PY_LLONG_MAX) + 1
__pyx_r = (((__pyx_t_10quicktions_ullong)PY_LLONG_MAX) + 1); goto __pyx_L0;
+0166: return abs(x)
__pyx_t_2 = __Pyx_abs_longlong(__pyx_v_x); __pyx_r = __pyx_t_2; goto __pyx_L0;
0167:
0168:
+0169: 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; }
0170: """Euclid's GCD algorithm"""
+0171: if IS_GCC:
if (__Quicktions_IS_GCC) { /* … */ } /* … */ if (__Quicktions_IS_GCC) { /* … */ } /* … */ if (__Quicktions_IS_GCC) { /* … */ }
+0172: 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, 172, __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, 172, __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, 172, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0;
0173: else:
+0174: 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, 174, __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, 174, __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, 174, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; }
0175:
0176:
+0177: 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; }
0178: """Euclid's GCD algorithm"""
+0179: 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;
+0180: 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, 180, __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, 180, __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, 180, __pyx_L1_error) } __pyx_t_3 = (__pyx_v_a % __pyx_v_b); __pyx_v_a = __pyx_t_2; __pyx_v_b = __pyx_t_3; }
+0181: 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;
0182:
0183:
+0184: 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; }
0185: if cunumber is uint:
+0186: return trailing_zeros_uint(x)
__pyx_r = __Quicktions_trailing_zeros_uint(__pyx_v_x); goto __pyx_L0;
0187: elif cunumber is ulong:
+0188: return trailing_zeros_ulong(x)
__pyx_r = __Quicktions_trailing_zeros_ulong(__pyx_v_x); goto __pyx_L0;
0189: else:
+0190: return trailing_zeros_ullong(x)
__pyx_r = __Quicktions_trailing_zeros_ullong(__pyx_v_x); goto __pyx_L0;
0191:
0192:
+0193: 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; }
0194: # See https://en.wikipedia.org/wiki/Binary_GCD_algorithm
+0195: 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) { /* … */ }
+0196: 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;
+0197: 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) { /* … */ }
+0198: 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;
0199:
+0200: 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, 200, __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, 200, __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, 200, __pyx_L1_error) __pyx_v_i = __pyx_t_2;
+0201: 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);
+0202: 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, 202, __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, 202, __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, 202, __pyx_L1_error) __pyx_v_j = __pyx_t_2;
+0203: 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);
0204:
+0205: 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;
0206:
+0207: while True:
while (1) { /* … */ while (1) { /* … */ while (1) {
+0208: 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) { /* … */ }
+0209: 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;
+0210: 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);
+0211: 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) { /* … */ }
+0212: 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;
+0213: 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, 213, __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, 213, __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, 213, __pyx_L1_error) __pyx_v_b = (__pyx_v_b >> __pyx_t_4); }
0214:
0215:
+0216: 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; }
+0217: 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) { /* … */ }
+0218: 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, 218, __pyx_L1_error) __pyx_t_4 = __Pyx_PyInt_From_int(((int)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 218, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0219: 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) { /* … */ }
+0220: 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, 220, __pyx_L1_error) __pyx_t_4 = __Pyx_PyInt_From_long(((long)__pyx_t_5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0221: elif b:
__pyx_t_1 = (__pyx_v_b != 0); if (__pyx_t_1) { /* … */ }
+0222: 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, 222, __pyx_L1_error)
__pyx_v_a = __pyx_t_6;
+0223: 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, 223, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0224:
0225:
+0226: 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;
}
+0227: 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) { /* … */ }
+0228: 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, 228, __pyx_L1_error)
__pyx_r = __pyx_t_3;
goto __pyx_L0;
+0229: 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) { /* … */ }
+0230: 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, 230, __pyx_L1_error)
__pyx_r = __pyx_t_4;
goto __pyx_L0;
0231: else:
+0232: 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, 232, __pyx_L1_error)
__pyx_r = __pyx_t_5;
goto __pyx_L0;
}
0233:
0234:
+0235: 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; }
0236: """Fallback GCD implementation if _PyLong_GCD() is not available.
0237: """
0238: # Try doing the computation in C space. If the numbers are too
0239: # large at the beginning, do object calculations until they are small enough.
0240: cdef ullong au, bu
0241: cdef long long ai, bi
0242:
0243: # Optimistically try to switch to C space.
+0244: 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); }
+0245: 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, 245, __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, 245, __pyx_L3_error) __pyx_v_ai = __pyx_t_4; __pyx_v_bi = __pyx_t_5;
+0246: 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;
0247: pass
0248: else:
+0249: 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, 249, __pyx_L5_except_error) __pyx_v_au = __pyx_t_6;
+0250: 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, 250, __pyx_L5_except_error) __pyx_v_bu = __pyx_t_6;
+0251: 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, 251, __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:;
0252:
0253: # Do object calculation until we reach the C space limit.
+0254: a = abs(a)
__pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_v_a); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 254, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_7); __pyx_t_7 = 0;
+0255: b = abs(b)
__pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_v_b); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 255, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_7); __pyx_t_7 = 0;
+0256: 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, 256, __pyx_L1_error) __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 256, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (!__pyx_t_9) break;
+0257: 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, 257, __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; }
+0258: 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, 258, __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, 258, __pyx_L1_error) __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 258, __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;
+0259: 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, 259, __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; }
+0260: if not b:
__pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_b); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 260, __pyx_L1_error) __pyx_t_11 = (!__pyx_t_9); if (__pyx_t_11) { /* … */ }
+0261: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_a); __pyx_r = __pyx_v_a; goto __pyx_L0;
+0262: 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, 262, __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, 262, __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, 262, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
0263:
0264:
0265: # Constants related to the hash implementation; hash(x) is based
0266: # on the reduction of x modulo the prime _PyHASH_MODULUS.
0267:
0268: cdef Py_hash_t _PyHASH_MODULUS
+0269: 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:; }
+0270: _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, 270, __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, 270, __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, 270, __pyx_L8_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_10quicktions__PyHASH_MODULUS = __pyx_t_8;
+0271: 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, 271, __pyx_L10_except_error) __Pyx_XGOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_9);
0272: # adapted from pyhash.h in Py3.4
+0273: _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;
0274:
0275:
0276: # Value to be used for rationals that reduce to infinity modulo
0277: # _PyHASH_MODULUS.
0278: cdef Py_hash_t _PyHASH_INF
+0279: 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:; }
+0280: _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, 280, __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, 280, __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, 280, __pyx_L16_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_10quicktions__PyHASH_INF = __pyx_t_8;
+0281: 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, 281, __pyx_L18_except_error) __Pyx_XGOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_3);
+0282: _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, 282, __pyx_L18_except_error) __pyx_t_12 = PyFloat_FromDouble(__pyx_t_11); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 282, __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, 282, __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;
0283:
0284:
0285: # Helpers for formatting
0286:
+0287: 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; };
0288: """Round a rational number to the nearest multiple of a given power of 10.
0289:
0290: Rounds the rational number n/d to the nearest integer multiple of
0291: 10**exponent, rounding to the nearest even integer multiple in the case of
0292: a tie. Returns a pair (sign: bool, significand: int) representing the
0293: rounded value (-1)**sign * significand * 10**exponent.
0294:
0295: If no_neg_zero is true, then the returned sign will always be False when
0296: the significand is zero. Otherwise, the sign reflects the sign of the
0297: input.
0298:
0299: d must be positive, but n and d need not be relatively prime.
0300: """
+0301: 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, 301, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 301, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0302: d *= 10**exponent
__pyx_t_1 = PyNumber_Power(__pyx_int_10, __pyx_v_exponent, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 302, __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, 302, __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;
0303: else:
+0304: n *= 10**-exponent
/*else*/ { __pyx_t_3 = PyNumber_Negative(__pyx_v_exponent); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 304, __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, 304, __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, 304, __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:;
0305:
0306: # The divmod quotient is correct for round-ties-towards-positive-infinity;
0307: # In the case of a tie, we zero out the least significant bit of q.
+0308: 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, 308, __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, 308, __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, 308, __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, 308, __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, 308, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 308, __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, 308, __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, 308, __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, 308, __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;
+0309: 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, 309, __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, 309, __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, 309, __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) { /* … */ }
+0310: 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, 310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_q, __pyx_t_3); __pyx_t_3 = 0;
0311:
+0312: 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, 312, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 312, __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, 312, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 312, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_7; } __pyx_v_sign = __pyx_t_2;
+0313: 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, 313, __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, 313, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 313, __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, 313, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4)) __PYX_ERR(0, 313, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0314:
0315:
+0316: 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; }
0317: """Round a rational number to a given number of significant figures.
0318:
0319: Rounds the rational number n/d to the given number of significant figures
0320: using the round-ties-to-even rule, and returns a triple
0321: (sign: bool, significand: int, exponent: int) representing the rounded
0322: value (-1)**sign * significand * 10**exponent.
0323:
0324: In the special case where n = 0, returns a significand of zero and
0325: an exponent of 1 - figures, for compatibility with formatting.
0326: Otherwise, the returned significand satisfies
0327: 10**(figures - 1) <= significand < 10**figures.
0328:
0329: d must be positive, but n and d need not be relatively prime.
0330: figures must be positive.
0331: """
0332: # Special case for n == 0.
+0333: 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, 333, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0334: 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, 334, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 334, __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, 334, __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, 334, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2)) __PYX_ERR(0, 334, __pyx_L1_error); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0335:
0336: cdef bint sign
0337:
0338: # Find integer m satisfying 10**(m - 1) <= abs(n)/d <= 10**m. (If abs(n)/d
0339: # is a power of 10, either of the two possible values for m is fine.)
+0340: 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, 340, __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, 340, __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, 340, __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;
+0341: 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, 341, __pyx_L1_error) __pyx_t_5 = PyObject_Length(__pyx_v_str_d); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 341, __pyx_L1_error) __pyx_t_3 = PyInt_FromSsize_t((__pyx_t_4 - __pyx_t_5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 341, __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, 341, __pyx_L1_error) __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 341, __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, 341, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_m = __pyx_t_5;
0342:
0343: # Round to a multiple of 10**(m - figures). The significand we get
0344: # satisfies 10**(figures - 1) <= significand <= 10**figures.
+0345: exponent = m - figures
__pyx_t_6 = PyInt_FromSsize_t((__pyx_v_m - __pyx_v_figures)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 345, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_v_exponent = __pyx_t_6; __pyx_t_6 = 0;
+0346: 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, 346, __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, 346, __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, 346, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 346, __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, 346, __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, 346, __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, 346, __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, 346, __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;
0347:
0348: # Adjust in the case where significand == 10**figures, to ensure that
0349: # 10**(figures - 1) <= significand < 10**figures.
+0350: if len(str(significand)) == figures + 1:
__pyx_t_6 = __Pyx_PyObject_Str(__pyx_v_significand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 350, __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, 350, __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) { /* … */ }
+0351: 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, 351, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_significand, __pyx_t_6); __pyx_t_6 = 0;
+0352: 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, 352, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_exponent, __pyx_t_6); __pyx_t_6 = 0;
0353:
+0354: 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, 354, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 354, __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, 354, __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, 354, __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, 354, __pyx_L1_error); __pyx_t_6 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0355:
0356:
0357: # Pattern for matching non-float-style format specifications.
+0358: 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, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); /* … */ __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 358, __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, 358, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_12); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_12)) __PYX_ERR(0, 358, __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, 358, __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;
0359: (?:
0360: (?P<fill>.)?
0361: (?P<align>[<>=^])
0362: )?
0363: (?P<sign>[-+ ]?)
0364: # Alt flag forces a slash and denominator in the output, even for
0365: # integer-valued Fraction objects.
0366: (?P<alt>\#)?
0367: # We don't implement the zeropad flag since there's no single obvious way
0368: # to interpret it.
0369: (?P<minimumwidth>0|[1-9][0-9]*)?
0370: (?P<thousands_sep>[,_])?
0371: $
+0372: """, 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, 372, __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, 372, __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, 372, __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, 372, __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;
0373:
0374:
0375: # Pattern for matching float-style format specifications;
0376: # supports 'e', 'E', 'f', 'F', 'g', 'G' and '%' presentation types.
+0377: 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, 377, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 377, __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, 377, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_9); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_9)) __PYX_ERR(0, 377, __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, 377, __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;
0378: (?:
0379: (?P<fill>.)?
0380: (?P<align>[<>=^])
0381: )?
0382: (?P<sign>[-+ ]?)
0383: (?P<no_neg_zero>z)?
0384: (?P<alt>\#)?
0385: # A '0' that's *not* followed by another digit is parsed as a minimum width
0386: # rather than a zeropad flag.
0387: (?P<zeropad>0(?=[0-9]))?
0388: (?P<minimumwidth>0|[1-9][0-9]*)?
0389: (?P<thousands_sep>[,_])?
0390: (?:\.(?P<precision>0|[1-9][0-9]*))?
0391: (?P<presentation_type>[eEfFgG%])
0392: $
+0393: """, 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, 393, __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, 393, __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, 393, __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, 393, __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;
0394:
+0395: cdef object NOINIT = object()
__pyx_t_3 = __Pyx_PyObject_CallNoArg(__pyx_builtin_object); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 395, __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;
0396:
0397:
+0398: 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;
0399: """A Rational number.
0400:
0401: Takes a string like '3/2' or '1.5', another Rational instance, a
0402: numerator/denominator pair, or a float.
0403:
0404: Examples
0405: --------
0406:
0407: >>> Fraction(10, -8)
0408: Fraction(-5, 4)
0409: >>> Fraction(Fraction(1, 7), 5)
0410: Fraction(1, 35)
0411: >>> Fraction(Fraction(1, 7), Fraction(2, 3))
0412: Fraction(3, 14)
0413: >>> Fraction('314')
0414: Fraction(314, 1)
0415: >>> Fraction('-35/4')
0416: Fraction(-35, 4)
0417: >>> Fraction('3.1415') # conversion from numeric string
0418: Fraction(6283, 2000)
0419: >>> Fraction('-47e-2') # string may include a decimal exponent
0420: Fraction(-47, 100)
0421: >>> Fraction(1.47) # direct construction from float (exact conversion)
0422: Fraction(6620291452234629, 4503599627370496)
0423: >>> Fraction(2.25)
0424: Fraction(9, 4)
0425: >>> from decimal import Decimal
0426: >>> Fraction(Decimal('1.47'))
0427: Fraction(147, 100)
0428:
0429: """
0430: cdef _numerator
0431: cdef _denominator
0432: cdef Py_hash_t _hash
0433:
+0434: 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, 434, __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, 434, __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, 434, __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, 434, __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_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_6); __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; }
+0435: self._hash = -1
__pyx_v_self->_hash = -1L;
+0436: if numerator is NOINIT:
__pyx_t_1 = (__pyx_v_numerator == __pyx_v_10quicktions_NOINIT); if (__pyx_t_1) { /* … */ }
+0437: return # fast-path for external initialisation
__pyx_r = 0; goto __pyx_L0;
0438:
+0439: cdef bint _normalize = True
__pyx_v__normalize = 1;
+0440: if denominator is None:
__pyx_t_1 = (__pyx_v_denominator == Py_None); if (__pyx_t_1) { /* … */ goto __pyx_L4; }
+0441: if type(numerator) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyInt_Type))); if (__pyx_t_1) { /* … */ }
+0442: 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;
+0443: 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;
+0444: return
__pyx_r = 0; goto __pyx_L0;
0445:
+0446: elif type(numerator) is float:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyFloat_Type))); if (__pyx_t_1) { /* … */ }
0447: # Exact conversion
+0448: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = NULL; __pyx_t_5 = 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_5 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; 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, 448, __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); } else { __pyx_t_3 = PyList_GET_ITEM(sequence, 0); __pyx_t_4 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_4); #else __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 448, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_6); index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_4 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_4)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 448, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 448, __pyx_L1_error) __pyx_L7_unpacking_done:; } __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; __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;
+0449: return
__pyx_r = 0; goto __pyx_L0;
0450:
+0451: elif type(numerator) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0452: self._numerator = (<Fraction>numerator)._numerator
__pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_numerator; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_2; __pyx_t_2 = 0;
+0453: self._denominator = (<Fraction>numerator)._denominator
__pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_denominator; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_2; __pyx_t_2 = 0;
+0454: return
__pyx_r = 0; goto __pyx_L0;
0455:
+0456: elif isinstance(numerator, unicode):
__pyx_t_1 = PyUnicode_Check(__pyx_v_numerator);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+0457: numerator, denominator, is_normalised = _parse_fraction(
__pyx_t_2 = __pyx_fuse_0__pyx_f_10quicktions__parse_fraction(((PyObject*)__pyx_v_numerator), __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (likely(__pyx_t_2 != Py_None)) { PyObject* sequence = __pyx_t_2; 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, 457, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_4 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_6); #else __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 457, __pyx_L1_error) } __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_3); __pyx_t_3 = 0; __pyx_v_is_normalised = __pyx_t_6; __pyx_t_6 = 0;
+0458: <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, 458, __pyx_L1_error) } __pyx_t_8 = __Pyx_PyUnicode_GET_LENGTH(((PyObject*)__pyx_v_numerator)); if (unlikely(__pyx_t_8 == ((Py_ssize_t)-1))) __PYX_ERR(0, 458, __pyx_L1_error)
+0459: if is_normalised:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_is_normalised); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 459, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0460: _normalize = False
__pyx_v__normalize = 0;
0461: # fall through to normalisation below
0462:
+0463: elif isinstance(numerator, float) or (
__pyx_t_9 = PyFloat_Check(__pyx_v_numerator);
if (!__pyx_t_9) {
} else {
__pyx_t_1 = __pyx_t_9;
goto __pyx_L9_bool_binop_done;
}
/* … */
if (__pyx_t_1) {
/* … */
}
+0464: not isinstance(numerator, type) and hasattr(numerator, 'as_integer_ratio')):
__pyx_t_9 = PyType_Check(__pyx_v_numerator); __pyx_t_10 = (!__pyx_t_9); if (__pyx_t_10) { } else { __pyx_t_1 = __pyx_t_10; goto __pyx_L9_bool_binop_done; } __pyx_t_10 = __Pyx_HasAttr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 464, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_L9_bool_binop_done:;
0465: # Exact conversion
+0466: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 466, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = NULL; __pyx_t_5 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_6))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); __pyx_t_5 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 466, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; 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, 466, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_6 = PyTuple_GET_ITEM(sequence, 0); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_6 = PyList_GET_ITEM(sequence, 0); __pyx_t_3 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(__pyx_t_3); #else __pyx_t_6 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 466, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 466, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 466, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_6 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); index = 1; __pyx_t_3 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 2) < 0) __PYX_ERR(0, 466, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L13_unpacking_done; __pyx_L12_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 466, __pyx_L1_error) __pyx_L13_unpacking_done:; } __Pyx_GIVEREF(__pyx_t_6); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_6; __pyx_t_6 = 0; __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;
+0467: return
__pyx_r = 0; goto __pyx_L0;
0468:
+0469: elif isinstance(numerator, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_2 = __pyx_v_10quicktions_Rational; __pyx_t_10 = __Pyx_TypeCheck(__pyx_v_numerator, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_10) { } else { __pyx_t_1 = __pyx_t_10; goto __pyx_L14_bool_binop_done; } __pyx_t_10 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_2); __pyx_t_1 = __pyx_t_10; __pyx_L14_bool_binop_done:; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+0470: self._numerator = numerator.numerator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 470, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_2; __pyx_t_2 = 0;
+0471: self._denominator = numerator.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 471, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_2; __pyx_t_2 = 0;
+0472: return
__pyx_r = 0; goto __pyx_L0;
0473:
+0474: elif isinstance(numerator, Decimal):
__pyx_t_2 = __pyx_v_10quicktions_Decimal; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_2); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 474, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (likely(__pyx_t_1)) { /* … */ }
+0475: if _decimal_supports_integer_ratio:
if (__pyx_v_10quicktions__decimal_supports_integer_ratio) { /* … */ goto __pyx_L16; }
0476: # Exact conversion
+0477: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = NULL; __pyx_t_5 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_3))) { __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_3); if (likely(__pyx_t_6)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_6); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_3, function); __pyx_t_5 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_2))) || (PyList_CheckExact(__pyx_t_2))) { PyObject* sequence = __pyx_t_2; 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, 477, __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_6 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_3 = PyList_GET_ITEM(sequence, 0); __pyx_t_6 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_6); #else __pyx_t_3 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { Py_ssize_t index = -1; __pyx_t_4 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 477, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_3)) goto __pyx_L17_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_6 = __pyx_t_7(__pyx_t_4); if (unlikely(!__pyx_t_6)) goto __pyx_L17_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_4), 2) < 0) __PYX_ERR(0, 477, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L18_unpacking_done; __pyx_L17_unpacking_failed:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 477, __pyx_L1_error) __pyx_L18_unpacking_done:; } __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; __Pyx_GIVEREF(__pyx_t_6); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_6; __pyx_t_6 = 0;
0478: else:
+0479: value = Fraction.from_decimal(numerator)
/*else*/ { __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_10quicktions_Fraction), __pyx_n_s_from_decimal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = NULL; __pyx_t_5 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_6))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_6); if (likely(__pyx_t_3)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_6, function); __pyx_t_5 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_numerator}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; } __pyx_v_value = __pyx_t_2; __pyx_t_2 = 0;
+0480: self._numerator = (<Fraction>value)._numerator
__pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_value)->_numerator; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_numerator); __Pyx_DECREF(__pyx_v_self->_numerator); __pyx_v_self->_numerator = __pyx_t_2; __pyx_t_2 = 0;
+0481: self._denominator = (<Fraction>value)._denominator
__pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_value)->_denominator; __Pyx_INCREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_2; __pyx_t_2 = 0; } __pyx_L16:;
+0482: return
__pyx_r = 0; goto __pyx_L0;
0483:
0484: else:
+0485: raise TypeError("argument should be a string or a Rational "
/*else*/ { __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple_, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_Raise(__pyx_t_2, 0, 0, 0); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __PYX_ERR(0, 485, __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, 485, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple_); __Pyx_GIVEREF(__pyx_tuple_);
0486: "instance or have the as_integer_ratio() method")
0487:
+0488: 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; }
0489: pass # *very* normal case
0490:
+0491: 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; }
0492: numerator, denominator = (
+0493: (<Fraction>numerator)._numerator * (<Fraction>denominator)._denominator,
__pyx_t_2 = PyNumber_Multiply(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_denominator)->_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 493, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+0494: (<Fraction>denominator)._numerator * (<Fraction>numerator)._denominator
__pyx_t_6 = PyNumber_Multiply(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_denominator)->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 494, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_6); __pyx_t_6 = 0;
0495: )
0496:
+0497: elif (isinstance(numerator, (Fraction, Rational)) and
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_6 = __pyx_v_10quicktions_Rational; __pyx_t_9 = __Pyx_TypeCheck(__pyx_v_numerator, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_9) { } else { __pyx_t_10 = __pyx_t_9; goto __pyx_L21_bool_binop_done; } __pyx_t_9 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_6); __pyx_t_10 = __pyx_t_9; __pyx_L21_bool_binop_done:; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_10) { } else { __pyx_t_1 = __pyx_t_10; goto __pyx_L19_bool_binop_done; } /* … */ if (likely(__pyx_t_1)) { /* … */ goto __pyx_L4; }
+0498: isinstance(denominator, (Fraction, Rational))):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_6 = __pyx_v_10quicktions_Rational; __pyx_t_9 = __Pyx_TypeCheck(__pyx_v_denominator, __pyx_ptype_10quicktions_Fraction); if (!__pyx_t_9) { } else { __pyx_t_10 = __pyx_t_9; goto __pyx_L23_bool_binop_done; } __pyx_t_9 = PyObject_IsInstance(__pyx_v_denominator, __pyx_t_6); __pyx_t_10 = __pyx_t_9; __pyx_L23_bool_binop_done:; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_1 = __pyx_t_10; __pyx_L19_bool_binop_done:;
0499: numerator, denominator = (
+0500: numerator.numerator * denominator.denominator,
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_numerator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_denominator, __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Multiply(__pyx_t_6, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+0501: denominator.numerator * numerator.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_denominator, __pyx_n_s_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 501, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_n_s_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 501, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = PyNumber_Multiply(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 501, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_4); __pyx_t_4 = 0;
0502: )
0503:
0504: else:
+0505: raise TypeError("both arguments should be "
/*else*/ { __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 505, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 505, __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, 505, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__2); __Pyx_GIVEREF(__pyx_tuple__2);
0506: "Rational instances")
0507:
+0508: 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, 508, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+0509: raise ZeroDivisionError(f'Fraction({numerator}, 0)')
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_8 = 0; __pyx_t_11 = 127; __Pyx_INCREF(__pyx_kp_u_Fraction); __pyx_t_8 += 9; __Pyx_GIVEREF(__pyx_kp_u_Fraction); PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_Fraction); __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_numerator, __pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_11 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) > __pyx_t_11) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) : __pyx_t_11; __pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_3); __pyx_t_3 = 0; __Pyx_INCREF(__pyx_kp_u_0); __pyx_t_8 += 4; __Pyx_GIVEREF(__pyx_kp_u_0); PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_0); __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_8, __pyx_t_11); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ZeroDivisionError, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 509, __pyx_L1_error)
+0510: if _normalize:
if (__pyx_v__normalize) { /* … */ }
+0511: if not isinstance(numerator, int):
__pyx_t_1 = PyInt_Check(__pyx_v_numerator);
__pyx_t_10 = (!__pyx_t_1);
if (__pyx_t_10) {
/* … */
}
+0512: numerator = int(numerator)
__pyx_t_4 = __Pyx_PyNumber_Int(__pyx_v_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_4); __pyx_t_4 = 0;
+0513: if not isinstance(denominator, int):
__pyx_t_10 = PyInt_Check(__pyx_v_denominator);
__pyx_t_1 = (!__pyx_t_10);
if (__pyx_t_1) {
/* … */
}
+0514: denominator = int(denominator)
__pyx_t_4 = __Pyx_PyNumber_Int(__pyx_v_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 514, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_4); __pyx_t_4 = 0;
+0515: g = _gcd(numerator, denominator)
__pyx_t_4 = __pyx_f_10quicktions__gcd(__pyx_v_numerator, __pyx_v_denominator, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 515, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g = __pyx_t_4; __pyx_t_4 = 0;
0516: # NOTE: 'is' tests on integers are generally a bad idea, but
0517: # they are fast and if they fail here, it'll still be correct
+0518: if denominator < 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_denominator, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 518, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 518, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+0519: if g is 1:
__pyx_t_1 = (__pyx_v_g == __pyx_int_1); if (__pyx_t_1) { /* … */ goto __pyx_L30; }
+0520: numerator = -numerator
__pyx_t_4 = PyNumber_Negative(__pyx_v_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 520, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_4); __pyx_t_4 = 0;
+0521: denominator = -denominator
__pyx_t_4 = PyNumber_Negative(__pyx_v_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 521, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_4); __pyx_t_4 = 0;
0522: else:
+0523: g = -g
/*else*/ { __pyx_t_4 = PyNumber_Negative(__pyx_v_g); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 523, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_g, __pyx_t_4); __pyx_t_4 = 0; } __pyx_L30:;
+0524: if g is not 1:
__pyx_t_1 = (__pyx_v_g != __pyx_int_1); if (__pyx_t_1) { /* … */ }
+0525: numerator //= g
__pyx_t_4 = PyNumber_InPlaceFloorDivide(__pyx_v_numerator, __pyx_v_g); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_4); __pyx_t_4 = 0;
+0526: denominator //= g
__pyx_t_4 = PyNumber_InPlaceFloorDivide(__pyx_v_denominator, __pyx_v_g); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_4); __pyx_t_4 = 0;
+0527: 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;
+0528: 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;
0529:
+0530: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_3from_number(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_number, "Converts a finite real number to a rational number, exactly.\n\n Beware that Fraction.from_number(0.3) != Fraction(3, 10).\n\n "); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_3from_number = {"from_number", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_3from_number, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_2from_number}; static PyObject *__pyx_pw_10quicktions_8Fraction_3from_number(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_number = 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_number (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_number,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_number)) != 0)) { (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); kw_args--; } else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 530, __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_number") < 0)) __PYX_ERR(0, 530, __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_number = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("from_number", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 530, __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_number", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_2from_number(((PyTypeObject*)__pyx_v_cls), __pyx_v_number); 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_number(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_number) { PyObject *__pyx_v_n = NULL; PyObject *__pyx_v_d = NULL; PyObject *__pyx_r = NULL; /* … */ /* 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_7); __Pyx_AddTraceback("quicktions.Fraction.from_number", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_n); __Pyx_XDECREF(__pyx_v_d); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_tuple__22 = PyTuple_Pack(4, __pyx_n_s_cls, __pyx_n_s_number, __pyx_n_s_n, __pyx_n_s_d); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(0, 530, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__22); __Pyx_GIVEREF(__pyx_tuple__22); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_3from_number, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_from_number, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_number, __pyx_t_3) < 0) __PYX_ERR(0, 530, __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_number); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 530, __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, 530, __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_number, __pyx_t_9) < 0) __PYX_ERR(0, 530, __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, 4, 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_number, 530, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(0, 530, __pyx_L1_error)
0531: def from_number(cls, number):
0532: """Converts a finite real number to a rational number, exactly.
0533:
0534: Beware that Fraction.from_number(0.3) != Fraction(3, 10).
0535:
0536: """
+0537: if type(number) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_number)) == ((PyObject *)(&PyInt_Type))); if (__pyx_t_1) { /* … */ }
+0538: return _fraction_from_coprime_ints(number, 1, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_3.__pyx_n = 1; __pyx_t_3.cls = ((PyObject *)__pyx_v_cls); __pyx_t_2 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_number, __pyx_int_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 538, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0539:
+0540: elif type(number) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_number)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0541: return _fraction_from_coprime_ints((<Fraction> number)._numerator, (<Fraction> number)._denominator, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_number)->_numerator; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_number)->_denominator; __Pyx_INCREF(__pyx_t_4); __pyx_t_3.__pyx_n = 1; __pyx_t_3.cls = ((PyObject *)__pyx_v_cls); __pyx_t_5 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_4, &__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 541, __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_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0542:
+0543: elif isinstance(number, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0544: n, d = number.as_integer_ratio()
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_4))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_4); if (likely(__pyx_t_2)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_4, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { PyObject* sequence = __pyx_t_5; 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, 544, __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_2 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_4 = PyList_GET_ITEM(sequence, 0); __pyx_t_2 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx_t_2); #else __pyx_t_4 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); #endif __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 544, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 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_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); index = 1; __pyx_t_2 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 544, __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, 544, __pyx_L1_error) __pyx_L5_unpacking_done:; } __pyx_v_n = __pyx_t_4; __pyx_t_4 = 0; __pyx_v_d = __pyx_t_2; __pyx_t_2 = 0;
+0545: return _fraction_from_coprime_ints(n, d, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_3.__pyx_n = 1; __pyx_t_3.cls = ((PyObject *)__pyx_v_cls); __pyx_t_5 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_n, __pyx_v_d, &__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 545, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0546:
+0547: elif isinstance(number, Rational):
__pyx_t_5 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = PyObject_IsInstance(__pyx_v_number, __pyx_t_5); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 547, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+0548: return _fraction_from_coprime_ints(number.numerator, number.denominator, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3.__pyx_n = 1; __pyx_t_3.cls = ((PyObject *)__pyx_v_cls); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_5, __pyx_t_2, &__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0549:
+0550: elif not isinstance(number, type) and hasattr(number, 'as_integer_ratio'):
__pyx_t_9 = PyType_Check(__pyx_v_number); __pyx_t_10 = (!__pyx_t_9); if (__pyx_t_10) { } else { __pyx_t_1 = __pyx_t_10; goto __pyx_L6_bool_binop_done; } __pyx_t_10 = __Pyx_HasAttr(__pyx_v_number, __pyx_n_s_as_integer_ratio); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 550, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_L6_bool_binop_done:; if (likely(__pyx_t_1)) { /* … */ }
+0551: n, d = number.as_integer_ratio()
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_n_s_as_integer_ratio); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (likely(PyMethod_Check(__pyx_t_2))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_2, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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, 551, __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_5 = PyTuple_GET_ITEM(sequence, 1); } else { __pyx_t_2 = PyList_GET_ITEM(sequence, 0); __pyx_t_5 = PyList_GET_ITEM(sequence, 1); } __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx_t_5); #else __pyx_t_2 = PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #endif __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); 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, 551, __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, 551, __pyx_L1_error) __pyx_L9_unpacking_done:; } __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_5; __pyx_t_5 = 0;
+0552: return _fraction_from_coprime_ints(n, d, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_3.__pyx_n = 1; __pyx_t_3.cls = ((PyObject *)__pyx_v_cls); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_n, __pyx_v_d, &__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 552, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0553:
0554: else:
+0555: raise TypeError("argument should be a Rational instance or "
/*else*/ { __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_TypeError, __pyx_tuple__3, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 555, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_Raise(__pyx_t_4, 0, 0, 0); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __PYX_ERR(0, 555, __pyx_L1_error) } /* … */ __pyx_tuple__3 = PyTuple_Pack(1, __pyx_kp_s_argument_should_be_a_Rational_in); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 555, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__3); __Pyx_GIVEREF(__pyx_tuple__3);
0556: "have the as_integer_ratio() method")
0557:
+0558: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_5from_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_4from_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_5from_float = {"from_float", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_5from_float, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_4from_float}; static PyObject *__pyx_pw_10quicktions_8Fraction_5from_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, 558, __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, 558, __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, 558, __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_4from_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_4from_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__24 = PyTuple_Pack(3, __pyx_n_s_cls, __pyx_n_s_f, __pyx_n_s_ratio); if (unlikely(!__pyx_tuple__24)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__24); __Pyx_GIVEREF(__pyx_tuple__24); /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_5from_float, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_from_float, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__25)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_float, __pyx_t_9) < 0) __PYX_ERR(0, 558, __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_float); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 558, __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, 558, __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_float, __pyx_t_3) < 0) __PYX_ERR(0, 558, __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, 3, 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_float, 558, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__25)) __PYX_ERR(0, 558, __pyx_L1_error)
0559: def from_float(cls, f):
0560: """Converts a finite float to a rational number, exactly.
0561:
0562: Beware that Fraction.from_float(0.3) != Fraction(3, 10).
0563:
0564: """
+0565: 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); }
+0566: 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, 566, __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, 566, __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;
+0567: except (ValueError, OverflowError, AttributeError):
__pyx_t_8 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); if (__pyx_t_8) { __Pyx_ErrRestore(0,0,0); goto __pyx_L4_exception_handled; } goto __pyx_L5_except_error;
0568: pass # not something we can convert, raise concrete exceptions below
0569: else:
+0570: 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, 570, __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, 570, __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;
0571:
+0572: if isinstance(f, Integral):
__pyx_t_5 = __pyx_v_10quicktions_Integral; __Pyx_INCREF(__pyx_t_5); __pyx_t_9 = PyObject_IsInstance(__pyx_v_f, __pyx_t_5); if (unlikely(__pyx_t_9 == ((int)-1))) __PYX_ERR(0, 572, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_9) { /* … */ }
+0573: 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, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+0574: elif not isinstance(f, float):
__pyx_t_9 = PyFloat_Check(__pyx_v_f);
__pyx_t_10 = (!__pyx_t_9);
if (unlikely(__pyx_t_10)) {
/* … */
}
+0575: 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, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_11 = 0; __pyx_t_12 = 127; __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_6 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_12; __pyx_t_11 += __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_11 += 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, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_12; __pyx_t_11 += __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__4); __pyx_t_11 += 2; __Pyx_GIVEREF(__pyx_kp_u__4); PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_kp_u__4); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_f)), __pyx_n_s_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 575, __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, 575, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __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_11 += __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__5); __pyx_t_11 += 1; __Pyx_GIVEREF(__pyx_kp_u__5); PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_kp_u__5); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_5, 6, __pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 575, __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, 575, __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, 575, __pyx_L1_error)
+0576: 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, 576, __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, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 576, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_t_10)) { /* … */ }
+0577: raise OverflowError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_11 = 0; __pyx_t_12 = 127; __Pyx_INCREF(__pyx_kp_u_Cannot_convert); __pyx_t_11 += 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, 577, __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_11 += __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_11 += 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, 577, __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, 577, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_12; __pyx_t_11 += __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__6); __pyx_t_11 += 1; __Pyx_GIVEREF(__pyx_kp_u__6); PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u__6); __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 577, __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, 577, __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, 577, __pyx_L1_error)
+0578: raise ValueError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_11 = 0; __pyx_t_12 = 127; __Pyx_INCREF(__pyx_kp_u_Cannot_convert); __pyx_t_11 += 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, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_12 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) > __pyx_t_12) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_6) : __pyx_t_12; __pyx_t_11 += __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_11 += 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, 578, __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, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __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_11 += __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__6); __pyx_t_11 += 1; __Pyx_GIVEREF(__pyx_kp_u__6); PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u__6); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_5, 5, __pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 578, __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, 578, __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, 578, __pyx_L1_error)
0579:
+0580: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_7from_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_6from_decimal, "Converts a finite Decimal instance to a rational number, exactly."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_7from_decimal = {"from_decimal", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_7from_decimal, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_6from_decimal}; static PyObject *__pyx_pw_10quicktions_8Fraction_7from_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, 580, __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, 580, __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, 580, __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_6from_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_6from_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__26 = 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__26)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__26); __Pyx_GIVEREF(__pyx_tuple__26); /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_7from_decimal, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_from_decimal, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__27)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_from_decimal, __pyx_t_3) < 0) __PYX_ERR(0, 580, __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_decimal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 580, __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, 580, __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_decimal, __pyx_t_9) < 0) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__27 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 7, 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_from_decimal, 580, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__27)) __PYX_ERR(0, 580, __pyx_L1_error)
0581: def from_decimal(cls, dec):
0582: """Converts a finite Decimal instance to a rational number, exactly."""
0583: cdef Py_ssize_t exp
+0584: 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, 584, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0585: dec = Decimal(int(dec))
__pyx_t_3 = __Pyx_PyNumber_Int(__pyx_v_dec); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 585, __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, 585, __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;
+0586: 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, 586, __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:;
+0587: raise TypeError(
__pyx_t_1 = __Pyx_PyObject_CallOneArg(__pyx_builtin_TypeError, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 587, __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, 587, __pyx_L1_error)
+0588: 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, 588, __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, 588, __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, 588, __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, 588, __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__4); __pyx_t_8 += 2; __Pyx_GIVEREF(__pyx_kp_u__4); PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_kp_u__4); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_dec)), __pyx_n_s_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 588, __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, 588, __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__5); __pyx_t_8 += 1; __Pyx_GIVEREF(__pyx_kp_u__5); PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_kp_u__5); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 6, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 588, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+0589: 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, 589, __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, 589, __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, 589, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0590: raise OverflowError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 590, __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, 590, __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, 590, __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, 590, __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__6); __pyx_t_8 += 1; __Pyx_GIVEREF(__pyx_kp_u__6); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__6); __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 590, __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, 590, __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, 590, __pyx_L1_error)
+0591: 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, 591, __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, 591, __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, 591, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0592: raise ValueError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_1 = PyTuple_New(5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __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, 592, __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, 592, __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, 592, __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__6); __pyx_t_8 += 1; __Pyx_GIVEREF(__pyx_kp_u__6); PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_kp_u__6); __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_1, 5, __pyx_t_8, __pyx_t_9); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 592, __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, 592, __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, 592, __pyx_L1_error)
0593:
+0594: if _decimal_supports_integer_ratio:
if (__pyx_v_10quicktions__decimal_supports_integer_ratio) { /* … */ }
+0595: 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, 595, __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, 595, __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, 595, __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, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __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, 595, __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, 595, __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, 595, __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;
+0596: 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, 596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0597:
+0598: 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, 598, __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, 598, __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, 598, __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, 598, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 598, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 598, __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, 598, __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, 598, __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, 598, __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, 598, __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;
+0599: digits = int(''.join(map(str, digits)))
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __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, 599, __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, 599, __pyx_L1_error); __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_map, __pyx_t_1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 599, __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__7, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __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, 599, __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;
+0600: if sign:
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_sign); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 600, __pyx_L1_error) if (__pyx_t_7) { /* … */ }
+0601: digits = -digits
__pyx_t_5 = PyNumber_Negative(__pyx_v_digits); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_digits, __pyx_t_5); __pyx_t_5 = 0;
+0602: if exp >= 0:
__pyx_t_7 = (__pyx_v_exp >= 0); if (__pyx_t_7) { /* … */ }
+0603: 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, 603, __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, 603, __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, 603, __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;
0604: else:
+0605: 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, 605, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 605, __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, 605, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_5); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5)) __PYX_ERR(0, 605, __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, 605, __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; }
0606:
+0607: def is_integer(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_9is_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_8is_integer, "Return True if the Fraction is an integer."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_9is_integer = {"is_integer", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_9is_integer, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_8is_integer}; static PyObject *__pyx_pw_10quicktions_8Fraction_9is_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_8is_integer(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_8is_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__28 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__28)) __PYX_ERR(0, 607, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__28); __Pyx_GIVEREF(__pyx_tuple__28); /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_9is_integer, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_is_integer, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__29)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 607, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_is_integer, __pyx_t_9) < 0) __PYX_ERR(0, 607, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__29 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_is_integer, 607, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__29)) __PYX_ERR(0, 607, __pyx_L1_error)
0608: """Return True if the Fraction is an integer."""
+0609: 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, 609, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0610:
+0611: def as_integer_ratio(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_11as_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_10as_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_11as_integer_ratio = {"as_integer_ratio", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_11as_integer_ratio, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_10as_integer_ratio}; static PyObject *__pyx_pw_10quicktions_8Fraction_11as_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_10as_integer_ratio(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_10as_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_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_11as_integer_ratio, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_as_integer_ratio, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__30)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_as_integer_ratio, __pyx_t_9) < 0) __PYX_ERR(0, 611, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__30 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_as_integer_ratio, 611, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__30)) __PYX_ERR(0, 611, __pyx_L1_error)
0612: """Return a pair of integers, whose ratio is equal to the original Fraction.
0613:
0614: The ratio is in lowest terms and has a positive denominator.
0615: """
+0616: return (self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 616, __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, 616, __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, 616, __pyx_L1_error); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0617:
+0618: def limit_denominator(self, max_denominator=1000000):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_13limit_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_12limit_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_13limit_denominator = {"limit_denominator", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_13limit_denominator, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_12limit_denominator}; static PyObject *__pyx_pw_10quicktions_8Fraction_13limit_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, 618, __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, 618, __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, 618, __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_12limit_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_12limit_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__31 = 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__31)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__31); __Pyx_GIVEREF(__pyx_tuple__31); __pyx_codeobj__32 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__31, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_limit_denominator, 618, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__32)) __PYX_ERR(0, 618, __pyx_L1_error) /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_13limit_denominator, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_limit_denominator, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__32)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_9, __pyx_tuple__33); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_limit_denominator, __pyx_t_9) < 0) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_tuple__33 = PyTuple_Pack(1, __pyx_int_1000000); if (unlikely(!__pyx_tuple__33)) __PYX_ERR(0, 618, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__33); __Pyx_GIVEREF(__pyx_tuple__33);
0619: """Closest Fraction to self with denominator at most max_denominator.
0620:
0621: >>> Fraction('3.141592653589793').limit_denominator(10)
0622: Fraction(22, 7)
0623: >>> Fraction('3.141592653589793').limit_denominator(100)
0624: Fraction(311, 99)
0625: >>> Fraction(4321, 8765).limit_denominator(10000)
0626: Fraction(4321, 8765)
0627:
0628: """
0629: # Algorithm notes: For any real number x, define a *best upper
0630: # approximation* to x to be a rational number p/q such that:
0631: #
0632: # (1) p/q >= x, and
0633: # (2) if p/q > r/s >= x then s > q, for any rational r/s.
0634: #
0635: # Define *best lower approximation* similarly. Then it can be
0636: # proved that a rational number is a best upper or lower
0637: # approximation to x if, and only if, it is a convergent or
0638: # semiconvergent of the (unique shortest) continued fraction
0639: # associated to x.
0640: #
0641: # To find a best rational approximation with denominator <= M,
0642: # we find the best upper and lower approximations with
0643: # denominator <= M and take whichever of these is closer to x.
0644: # In the event of a tie, the bound with smaller denominator is
0645: # chosen. If both denominators are equal (which can happen
0646: # only when max_denominator == 1 and self is midway between
0647: # two integers) the lower bound---i.e., the floor of self, is
0648: # taken.
0649:
+0650: 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, 650, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_2)) { /* … */ }
+0651: raise ValueError("max_denominator should be at least 1")
__pyx_t_1 = __Pyx_PyObject_Call(__pyx_builtin_ValueError, __pyx_tuple__8, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 651, __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, 651, __pyx_L1_error) /* … */ __pyx_tuple__8 = PyTuple_Pack(1, __pyx_kp_s_max_denominator_should_be_at_lea); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 651, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__8); __Pyx_GIVEREF(__pyx_tuple__8);
+0652: 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, 652, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 652, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0653: 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, 653, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0654:
+0655: 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;
+0656: 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;
+0657: while True:
while (1) {
+0658: a = n//d
__pyx_t_4 = PyNumber_FloorDivide(__pyx_v_n, __pyx_v_d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 658, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_4); __pyx_t_4 = 0;
+0659: q2 = q0+a*q1
__pyx_t_4 = PyNumber_Multiply(__pyx_v_a, __pyx_v_q1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 659, __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, 659, __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;
+0660: 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, 660, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 660, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_2) { /* … */ }
+0661: break
goto __pyx_L6_break;
+0662: 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, 662, __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, 662, __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;
+0663: 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, 663, __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, 663, __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:;
0664:
+0665: 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, 665, __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, 665, __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;
0666:
0667: # Determine which of the candidates (p0+k*p1)/(q0+k*q1) and p1/q1 is
0668: # closer to self. The distance between them is 1/(q1*(q0+k*q1)), while
0669: # the distance from p1/q1 to self is d/(q1*self._denominator). So we
0670: # need to compare 2*(q0+k*q1) with self._denominator/d.
+0671: 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, 671, __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, 671, __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, 671, __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, 671, __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, 671, __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, 671, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0672: 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, 672, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0673: else:
+0674: 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, 674, __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, 674, __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, 674, __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, 674, __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, 674, __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; }
0675:
+0676: @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; }
0677: def numerator(self):
+0678: return self._numerator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_numerator); __pyx_r = __pyx_v_self->_numerator; goto __pyx_L0;
0679:
+0680: @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; }
0681: def denominator(self):
+0682: return self._denominator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_denominator); __pyx_r = __pyx_v_self->_denominator; goto __pyx_L0;
0683:
+0684: def __repr__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_15__repr__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_14__repr__, "repr(self)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_14__repr__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_15__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_14__repr__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_14__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; }
0685: """repr(self)"""
+0686: 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, 686, __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, 686, __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, 686, __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, 686, __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, 686, __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, 686, __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, 686, __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;
0687: self._numerator, self._denominator)
0688:
+0689: def __str__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_17__str__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_16__str__, "str(self)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_16__str__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_17__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_16__str__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_16__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; }
0690: """str(self)"""
+0691: 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, 691, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0692: 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, 692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0693: else:
+0694: return f'{self._numerator}/{self._denominator}'
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 694, __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, 694, __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__9); __pyx_t_3 += 1; __Pyx_GIVEREF(__pyx_kp_u__9); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_kp_u__9); __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_self->_denominator, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 694, __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, 694, __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; }
0695:
0696: @cython.final
+0697: 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; }
0698: """Helper method for __format__.
0699:
0700: Handles fill, alignment, signs, and thousands separators in the
0701: case of no presentation type.
0702: """
0703: # Validate and parse the format specifier.
+0704: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 704, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_fill); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 704, __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, 704, __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__10); __pyx_t_1 = __pyx_kp_s__10; __pyx_L3_bool_binop_done:; __pyx_v_fill = __pyx_t_1; __pyx_t_1 = 0;
+0705: 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, 705, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __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, 705, __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__11); __pyx_t_1 = __pyx_kp_s__11; __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, 705, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_align = __pyx_t_4;
+0706: 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, 706, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__12, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 706, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__7); __pyx_t_1 = __pyx_kp_s__7; } else { if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 706, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 706, __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;
+0707: 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, 707, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_alt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 707, __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, 707, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_alternate_form = __pyx_t_3;
+0708: 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, 708, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_minimumwidth); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 708, __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, 708, __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, 708, __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, 708, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_minimumwidth = __pyx_t_5;
+0709: 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, 709, __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, 709, __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, 709, __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__7); __pyx_t_2 = __pyx_kp_s__7; __pyx_L9_bool_binop_done:; __pyx_v_thousands_sep = __pyx_t_2; __pyx_t_2 = 0;
0710:
+0711: if PY_VERSION_HEX < 0x03060000:
__pyx_t_3 = (PY_VERSION_HEX < 0x03060000); if (__pyx_t_3) { /* … */ }
+0712: 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__7; __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;
0713: cdef Py_ssize_t first_pos # Py2/3.5-only
0714:
0715: # Determine the body and sign representation.
+0716: 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;
+0717: 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, 717, __pyx_L1_error) } __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_legacy_thousands_sep); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 717, __pyx_L1_error) __pyx_t_3 = __pyx_t_6; __pyx_L13_bool_binop_done:; if (__pyx_t_3) { /* … */ goto __pyx_L12; }
0718: # Insert thousands separators if required.
+0719: body = str(abs(n))
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 719, __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, 719, __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;
+0720: 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, 720, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_5 - 1), 3));
+0721: 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, 721, __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, 721, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_10 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 721, __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, 721, __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;
+0722: legacy_thousands_sep + body[pos : pos + 3]
if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 722, __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, 722, __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, 722, __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, 721, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } /* exit inner scope */
+0723: 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, 723, __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;
0724: ])
+0725: 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, 725, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 725, __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) { /* … */ }
+0726: den = str(abs(d))
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 726, __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, 726, __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;
+0727: 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, 727, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_5 - 1), 3));
+0728: 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, 728, __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, 728, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_9 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 728, __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, 728, __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;
+0729: legacy_thousands_sep + den[pos: pos + 3]
if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 729, __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, 729, __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, 729, __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, 728, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } } /* exit inner scope */
+0730: 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, 730, __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;
0731: ])
+0732: body += "/" + den
__pyx_t_2 = PyNumber_Add(__pyx_kp_s__9, __pyx_v_den); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 732, __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, 732, __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;
+0733: 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, 733, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 733, __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; }
+0734: body = f"{abs(n):{thousands_sep}}/{d:{thousands_sep}}"
__pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 734, __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, 734, __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, 734, __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, 734, __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__9); __pyx_t_5 += 1; __Pyx_GIVEREF(__pyx_kp_u__9); PyTuple_SET_ITEM(__pyx_t_9, 1, __pyx_kp_u__9); __pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 734, __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, 734, __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, 734, __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;
0735: else:
+0736: body = f"{abs(n):{thousands_sep}}"
/*else*/ { __pyx_t_10 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 736, __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, 736, __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, 736, __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:;
+0737: 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, 737, __pyx_L1_error) __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 737, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__12); __pyx_t_1 = __pyx_kp_s__12; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_1 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_1; __pyx_t_1 = 0;
0738:
0739: # Pad with fill character if necessary and return.
+0740: 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, 740, __pyx_L1_error) __pyx_t_7 = PyObject_Length(__pyx_v_body); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 740, __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, 740, __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, 740, __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;
+0741: if align == u">":
switch (__pyx_v_align) { case 62: /* … */ break; case 60:
+0742: 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, 742, __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, 742, __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;
+0743: elif align == u"<":
break; case 94:
+0744: 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, 744, __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, 744, __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;
+0745: elif align == u"^":
break; default:
+0746: half = len(padding) // 2
__pyx_t_7 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 746, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_7, 2);
+0747: 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, 747, __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, 747, __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, 747, __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, 747, __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, 747, __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;
0748: else: # align == u"="
+0749: 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, 749, __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, 749, __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; }
0750:
0751: @cython.final
+0752: 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; }
0753: """Helper method for __format__; handles float presentation types."""
+0754: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 754, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_fill); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 754, __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, 754, __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__10); __pyx_t_1 = __pyx_kp_s__10; __pyx_L3_bool_binop_done:; __pyx_v_fill = __pyx_t_1; __pyx_t_1 = 0;
+0755: align = match["align"] or ">"
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 755, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 755, __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, 755, __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__11); __pyx_t_1 = __pyx_kp_s__11; __pyx_L5_bool_binop_done:; __pyx_v_align = __pyx_t_1; __pyx_t_1 = 0;
+0756: 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, 756, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = (__Pyx_PyString_Equals(__pyx_t_2, __pyx_kp_s__12, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 756, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_kp_s__7); __pyx_t_1 = __pyx_kp_s__7; } else { if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 756, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 756, __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;
+0757: 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, 757, __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, 757, __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, 757, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_no_neg_zero = __pyx_t_3;
+0758: 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, 758, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_alt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 758, __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, 758, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_alternate_form = __pyx_t_3;
+0759: cdef bint zeropad = match["zeropad"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 759, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_zeropad); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __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, 759, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_zeropad = __pyx_t_3;
+0760: 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, 760, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_minimumwidth); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 760, __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, 760, __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, 760, __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, 760, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_minimumwidth = __pyx_t_4;
+0761: thousands_sep = match["thousands_sep"]
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 761, __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, 761, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_thousands_sep = __pyx_t_2; __pyx_t_2 = 0;
+0762: 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, 762, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_n_s_precision); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 762, __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, 762, __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, 762, __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, 762, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_precision = __pyx_t_4;
+0763: 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, 763, __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, 763, __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, 763, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_presentation_type = __pyx_t_5;
+0764: 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;
+0765: cdef bint trim_point = not alternate_form
__pyx_v_trim_point = (!__pyx_v_alternate_form);
+0766: 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;
0767:
0768: cdef bint negative, scientific
0769: cdef Py_ssize_t exponent, figures
0770:
0771: # Round to get the digits we need, figure out where to place the point,
0772: # and decide whether to use scientific notation. 'point_pos' is the
0773: # relative to the _end_ of the digit string: that is, it's the number
0774: # of digits that should follow the point.
+0775: if presentation_type in u"fF%":
switch (__pyx_v_presentation_type) { case 37: case 70: case 0x66: /* … */ break; default:
+0776: exponent = -precision
__pyx_v_exponent = (-__pyx_v_precision);
+0777: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37); if (__pyx_t_3) { /* … */ }
+0778: exponent -= 2
__pyx_v_exponent = (__pyx_v_exponent - 2);
+0779: 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, 779, __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, 779, __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, 779, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 779, __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, 779, __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, 779, __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, 779, __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, 779, __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;
+0780: 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, 780, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8);
+0781: scientific = False
__pyx_v_scientific = 0;
+0782: point_pos = precision
__pyx_t_9 = PyInt_FromSsize_t(__pyx_v_precision); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_point_pos = __pyx_t_9; __pyx_t_9 = 0;
0783: else: # presentation_type in "eEgG"
0784: figures = (
+0785: 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:
+0786: if presentation_type in u"gG"
case 0x67:
+0787: else precision + 1
__pyx_t_4 = (__pyx_v_precision + 1); break; } __pyx_v_figures = __pyx_t_4;
0788: )
+0789: 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, 789, __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, 789, __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, 789, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 789, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 789, __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, 789, __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, 789, __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, 789, __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, 789, __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, 789, __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;
+0790: 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);
0791: scientific = (
+0792: 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; }
+0793: 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; }
+0794: 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;
0795: )
+0796: 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, 796, __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, 796, __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; }
0797:
0798: # Get the suffix - the part following the digits, if any.
+0799: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37); if (__pyx_t_3) { /* … */ goto __pyx_L21; }
+0800: suffix = "%"
__Pyx_INCREF(__pyx_kp_s__13);
__pyx_v_suffix = __pyx_kp_s__13;
+0801: elif scientific:
if (__pyx_v_scientific) { /* … */ goto __pyx_L21; }
0802: #suffix = f"{exponent_indicator}{exponent + point_pos:+03d}"
+0803: 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, 803, __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, 803, __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, 803, __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, 803, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1)) __PYX_ERR(0, 803, __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, 803, __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;
0804: else:
+0805: suffix = ""
/*else*/ {
__Pyx_INCREF(__pyx_kp_s__7);
__pyx_v_suffix = __pyx_kp_s__7;
}
__pyx_L21:;
0806:
0807: # String of output digits, padded sufficiently with zeros on the left
0808: # so that we'll have at least one digit before the decimal point.
+0809: digits = f"{significand:0{point_pos + 1}d}"
__pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 809, __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, 809, __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, 809, __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, 809, __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, 809, __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;
0810:
0811: # Before padding, the output has the form f"{sign}{leading}{trailing}",
0812: # where `leading` includes thousands separators if necessary and
0813: # `trailing` includes the decimal separator where appropriate.
+0814: sign = "-" if negative else pos_sign
if (__pyx_v_negative) { __Pyx_INCREF(__pyx_kp_s__12); __pyx_t_1 = __pyx_kp_s__12; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_1 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_1; __pyx_t_1 = 0;
+0815: 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, 815, __pyx_L1_error) __pyx_t_1 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 815, __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, 815, __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, 815, __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, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_leading = __pyx_t_9; __pyx_t_9 = 0;
+0816: 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, 816, __pyx_L1_error) __pyx_t_9 = PyInt_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 816, __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, 816, __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, 816, __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, 816, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_frac_part = __pyx_t_1; __pyx_t_1 = 0;
+0817: if trim_zeros:
if (__pyx_v_trim_zeros) { /* … */ }
+0818: 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, 818, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_frac_part, __pyx_t_1); __pyx_t_1 = 0;
+0819: 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, 819, __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__7); __pyx_t_1 = __pyx_kp_s__7; } else { __Pyx_INCREF(__pyx_kp_s__6); __pyx_t_1 = __pyx_kp_s__6; } __pyx_v_separator = __pyx_t_1; __pyx_t_1 = 0;
+0820: 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, 820, __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, 820, __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;
0821:
0822: # Do zero padding if required.
+0823: if zeropad:
if (__pyx_v_zeropad) { /* … */ }
+0824: 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, 824, __pyx_L1_error) __pyx_t_13 = PyObject_Length(__pyx_v_trailing); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 824, __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, 824, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_min_leading = __pyx_t_9; __pyx_t_9 = 0;
0825: # When adding thousands separators, they'll be added to the
0826: # zero-padded portion too, so we need to compensate.
+0827: 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, 827, __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;
+0828: 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, 828, __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, 828, __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, 828, __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, 828, __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; }
0829: )
0830:
0831: # Insert thousands separators if required.
+0832: if thousands_sep:
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_thousands_sep); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 832, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0833: 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, 833, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_13 - 1), 3));
+0834: 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, 834, __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, 834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); /* … */ __pyx_t_2 = __Pyx_PyString_Join(__pyx_kp_s__7, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 834, __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, 834, __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;
+0835: 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, 835, __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, 835, __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, 834, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } /* exit inner scope */
+0836: 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, 836, __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;
0837: ])
0838:
0839: # We now have a sign and a body. Pad with fill character if necessary
0840: # and return.
+0841: body = leading + trailing
__pyx_t_9 = PyNumber_Add(__pyx_v_leading, __pyx_v_trailing); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 841, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_body = __pyx_t_9; __pyx_t_9 = 0;
+0842: 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, 842, __pyx_L1_error) __pyx_t_4 = PyObject_Length(__pyx_v_body); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 842, __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, 842, __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, 842, __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;
+0843: if align == ">":
__pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_align, __pyx_kp_s__11, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 843, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0844: 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, 844, __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, 844, __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;
+0845: 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, 845, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0846: 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, 846, __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, 846, __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;
+0847: elif align == "^":
__pyx_t_3 = (__Pyx_PyString_Equals(__pyx_v_align, __pyx_kp_s__15, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 847, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0848: half = len(padding) // 2
__pyx_t_4 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 848, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_4, 2);
+0849: 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, 849, __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, 849, __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, 849, __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, 849, __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, 849, __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;
0850: else: # align == "="
+0851: 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, 851, __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, 851, __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; }
0852:
+0853: def __format__(self, format_spec, /):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_19__format__(PyObject *__pyx_v_self, PyObject *__pyx_v_format_spec); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_18__format__, "Format this fraction according to the given format specification."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_19__format__ = {"__format__", (PyCFunction)__pyx_pw_10quicktions_8Fraction_19__format__, METH_O, __pyx_doc_10quicktions_8Fraction_18__format__}; static PyObject *__pyx_pw_10quicktions_8Fraction_19__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_18__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_18__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__34 = 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__34)) __PYX_ERR(0, 853, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__34); __Pyx_GIVEREF(__pyx_tuple__34); /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_19__format__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___format, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__35)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 853, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_format, __pyx_t_9) < 0) __PYX_ERR(0, 853, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_codeobj__35 = (PyObject*)__Pyx_PyCode_New(2, 2, 0, 4, 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_format, 853, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__35)) __PYX_ERR(0, 853, __pyx_L1_error)
0854: """Format this fraction according to the given format specification."""
0855:
+0856: 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, 856, __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, 856, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+0857: 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, 857, __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, 857, __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, 857, __pyx_L1_error) __pyx_t_2 = __pyx_f_10quicktions_8Fraction__format_general(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 857, __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;
0858:
+0859: 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, 859, __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, 859, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_5) { /* … */ }
0860: # Refuse the temptation to guess if both alignment _and_
0861: # zero padding are specified.
+0862: 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, 862, __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, 862, __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;
+0863: 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, 863, __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, 863, __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) { /* … */ }
+0864: 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, 864, __pyx_L1_error) __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, 864, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0865:
+0866: raise ValueError(
__pyx_t_2 = __Pyx_PyObject_CallOneArg(__pyx_builtin_ValueError, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 866, __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, 866, __pyx_L1_error)
+0867: f"Invalid format specifier {format_spec!r} "
__pyx_t_2 = PyTuple_New(4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 867, __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, 867, __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, 867, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
+0868: 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, 868, __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, 868, __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;
0869: )
0870:
+0871: def __add__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_21__add__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_20__add__, "a + b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_20__add__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_21__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_20__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_20__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; }
0872: """a + b"""
+0873: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 873, __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;
0874:
+0875: def __radd__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_23__radd__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_22__radd__, "a + b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_22__radd__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_23__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_22__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_22__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; }
0876: """a + b"""
+0877: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 877, __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;
0878:
+0879: def __sub__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_25__sub__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_24__sub__, "a - b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_24__sub__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_25__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_24__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_24__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; }
0880: """a - b"""
+0881: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 881, __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;
0882:
+0883: def __rsub__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_27__rsub__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_26__rsub__, "a - b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_26__rsub__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_27__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_26__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_26__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; }
0884: """a - b"""
+0885: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 885, __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;
0886:
+0887: def __mul__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_29__mul__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_28__mul__, "a * b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_28__mul__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_29__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_28__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_28__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; }
0888: """a * b"""
+0889: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 889, __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;
0890:
+0891: def __rmul__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_31__rmul__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_30__rmul__, "a * b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_30__rmul__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_31__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_30__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_30__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; }
0892: """a * b"""
+0893: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 893, __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;
0894:
+0895: 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_33__div__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_32__div__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_32__div__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_33__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_32__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_32__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))*/
0896: """a / b"""
+0897: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 897, __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;
0898:
+0899: 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_35__rdiv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_34__rdiv__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_34__rdiv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_35__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_34__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_34__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))*/
0900: """a / b"""
+0901: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 901, __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;
0902:
+0903: def __truediv__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_37__truediv__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_36__truediv__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_36__truediv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_37__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_36__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_36__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; }
0904: """a / b"""
+0905: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 905, __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;
0906:
+0907: def __rtruediv__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_39__rtruediv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_38__rtruediv__, "a / b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_38__rtruediv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_39__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_38__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_38__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; }
0908: """a / b"""
+0909: 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, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 909, __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;
0910:
+0911: def __floordiv__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_41__floordiv__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_40__floordiv__, "a // b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_40__floordiv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_41__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_40__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_40__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; }
0912: """a // b"""
+0913: return forward(a, b, _floordiv, _math_op_floordiv, handle_complex=False)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_floordiv; __Pyx_INCREF(__pyx_t_1); __pyx_t_3.__pyx_n = 1; __pyx_t_3.handle_complex = Py_False; __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__floordiv, __pyx_t_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 913, __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;
0914:
+0915: def __rfloordiv__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_43__rfloordiv__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_42__rfloordiv__, "a // b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_42__rfloordiv__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_43__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_42__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_42__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; }
0916: """a // b"""
+0917: return reverse(a, b, _floordiv, _math_op_floordiv, handle_complex=False)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_floordiv; __Pyx_INCREF(__pyx_t_1); __pyx_t_3.__pyx_n = 1; __pyx_t_3.handle_complex = Py_False; __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__floordiv, __pyx_t_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 917, __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;
0918:
+0919: def __mod__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_45__mod__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_44__mod__, "a % b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_44__mod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_45__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_44__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_44__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; }
0920: """a % b"""
+0921: return forward(a, b, _mod, _math_op_mod, handle_complex=False)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_mod; __Pyx_INCREF(__pyx_t_1); __pyx_t_3.__pyx_n = 1; __pyx_t_3.handle_complex = Py_False; __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__mod, __pyx_t_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 921, __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;
0922:
+0923: def __rmod__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_47__rmod__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_46__rmod__, "a % b"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_46__rmod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_47__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_46__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_46__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; }
0924: """a % b"""
+0925: return reverse(a, b, _mod, _math_op_mod, handle_complex=False)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_mod; __Pyx_INCREF(__pyx_t_1); __pyx_t_3.__pyx_n = 1; __pyx_t_3.handle_complex = Py_False; __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__mod, __pyx_t_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 925, __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;
0926:
+0927: def __divmod__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_49__divmod__(PyObject *__pyx_v_a, PyObject *__pyx_v_b); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_48__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_48__divmod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_49__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_48__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_48__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; }
0928: """divmod(self, other): The pair (self // other, self % other).
0929:
0930: Sometimes this can be computed faster than the pair of
0931: operations.
0932: """
+0933: return forward(a, b, _divmod, _math_op_divmod, handle_complex=False)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_divmod; __Pyx_INCREF(__pyx_t_1); __pyx_t_3.__pyx_n = 1; __pyx_t_3.handle_complex = Py_False; __pyx_t_2 = __pyx_f_10quicktions_forward(((PyObject *)__pyx_v_a), __pyx_v_b, __pyx_f_10quicktions__divmod, __pyx_t_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 933, __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;
0934:
+0935: def __rdivmod__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_51__rdivmod__(PyObject *__pyx_v_b, PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_50__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_50__rdivmod__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_51__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_50__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_50__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; }
0936: """divmod(self, other): The pair (self // other, self % other).
0937:
0938: Sometimes this can be computed faster than the pair of
0939: operations.
0940: """
+0941: return reverse(a, b, _divmod, _math_op_divmod, handle_complex=False)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __pyx_v_10quicktions__math_op_divmod; __Pyx_INCREF(__pyx_t_1); __pyx_t_3.__pyx_n = 1; __pyx_t_3.handle_complex = Py_False; __pyx_t_2 = __pyx_f_10quicktions_reverse(__pyx_v_a, ((PyObject *)__pyx_v_b), __pyx_f_10quicktions__divmod, __pyx_t_1, &__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 941, __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;
0942:
+0943: def __pow__(a, b, x):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_53__pow__(PyObject *__pyx_v_a, PyObject *__pyx_v_b, PyObject *__pyx_v_x); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_52__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_52__pow__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_53__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_52__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_52__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; }
0944: """a ** b
0945:
0946: If b is not an integer, the result will be a float or complex
0947: since roots are generally irrational. If b is an integer, the
0948: result will be rational.
0949: """
+0950: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { /* … */ }
+0951: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
0952:
+0953: 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) { /* … */ }
+0954: 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, 954, __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, 954, __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, 954, __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;
+0955: 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) { /* … */ }
+0956: 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, 956, __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, 956, __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, 956, __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, 956, __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, 956, __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;
+0957: elif isinstance(b, (float, complex)):
__pyx_t_2 = PyFloat_Check(__pyx_v_b); if (!__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L9_bool_binop_done; } __pyx_t_2 = PyComplex_Check(__pyx_v_b); __pyx_t_1 = __pyx_t_2; __pyx_L9_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0958: return (a.numerator / a.denominator) ** b
__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, 958, __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, 958, __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, 958, __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, 958, __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;
0959: else:
+0960: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
0961:
+0962: def __rpow__(b, a, x):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_55__rpow__(PyObject *__pyx_v_b, PyObject *__pyx_v_a, PyObject *__pyx_v_x); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_54__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_54__rpow__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_55__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_54__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_54__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; }
0963: """a ** b
0964:
0965: If b is not an integer, the result will be a float or complex
0966: since roots are generally irrational. If b is an integer, the
0967: result will be rational.
0968: """
+0969: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { /* … */ }
+0970: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
0971:
+0972: 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, 972, __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, 972, __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;
+0973: 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, 973, __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, 973, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 973, __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) { /* … */ }
0974: # If a is an int, keep it that way if possible.
+0975: 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, 975, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0976:
+0977: 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) { /* … */ }
+0978: 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, 978, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+0979: 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) { /* … */ }
+0980: 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, 980, __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, 980, __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, 980, __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;
0981:
+0982: 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, 982, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0983: 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, 983, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0984:
+0985: 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, 985, __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, 985, __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;
0986:
+0987: def __pos__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_57__pos__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_56__pos__, "+a: Coerces a subclass instance to Fraction"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_56__pos__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_57__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_56__pos__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_56__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; }
0988: """+a: Coerces a subclass instance to Fraction"""
+0989: if type(a) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_a))) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0990: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_a); __pyx_r = ((PyObject *)__pyx_v_a); goto __pyx_L0;
+0991: 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, 991, __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;
0992:
+0993: def __neg__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_59__neg__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_58__neg__, "-a"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_58__neg__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_59__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_58__neg__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_58__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; }
0994: """-a"""
+0995: 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, 995, __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, 995, __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;
0996:
+0997: def __abs__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_61__abs__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_60__abs__, "abs(a)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_60__abs__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_61__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_60__abs__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_60__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; }
0998: """abs(a)"""
+0999: 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, 999, __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, 999, __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;
1000:
+1001: def __int__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_63__int__(PyObject *__pyx_v_a); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_62__int__, "int(a)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_62__int__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_63__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_62__int__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_62__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; }
1002: """int(a)"""
+1003: 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, 1003, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1003, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1004: 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, 1004, __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, 1004, __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, 1004, __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, 1004, __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;
1005: else:
+1006: 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, 1006, __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, 1006, __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; }
1007:
+1008: def __trunc__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_65__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_64__trunc__, "math.trunc(a)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_65__trunc__ = {"__trunc__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_65__trunc__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_64__trunc__}; static PyObject *__pyx_pw_10quicktions_8Fraction_65__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_64__trunc__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_64__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__36 = PyTuple_Pack(1, __pyx_n_s_a); if (unlikely(!__pyx_tuple__36)) __PYX_ERR(0, 1008, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__36); __Pyx_GIVEREF(__pyx_tuple__36); /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_65__trunc__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___trunc, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__37)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1008, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_trunc, __pyx_t_9) < 0) __PYX_ERR(0, 1008, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 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__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_trunc, 1008, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__37)) __PYX_ERR(0, 1008, __pyx_L1_error)
1009: """math.trunc(a)"""
+1010: 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, 1010, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1010, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1011: 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, 1011, __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, 1011, __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, 1011, __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;
1012: else:
+1013: 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, 1013, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
1014:
+1015: def __floor__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_67__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_66__floor__, "math.floor(a)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_67__floor__ = {"__floor__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_67__floor__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_66__floor__}; static PyObject *__pyx_pw_10quicktions_8Fraction_67__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_66__floor__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_66__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_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_67__floor__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___floor, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__38)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_floor, __pyx_t_9) < 0) __PYX_ERR(0, 1015, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__38 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_floor, 1015, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__38)) __PYX_ERR(0, 1015, __pyx_L1_error)
1016: """math.floor(a)"""
+1017: 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, 1017, __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, 1017, __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, 1017, __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;
1018:
+1019: def __ceil__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_69__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_68__ceil__, "math.ceil(a)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_69__ceil__ = {"__ceil__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_69__ceil__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_68__ceil__}; static PyObject *__pyx_pw_10quicktions_8Fraction_69__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_68__ceil__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_68__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_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_69__ceil__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___ceil, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__39)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1019, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_ceil, __pyx_t_9) < 0) __PYX_ERR(0, 1019, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__39 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__36, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_ceil, 1019, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__39)) __PYX_ERR(0, 1019, __pyx_L1_error)
1020: """math.ceil(a)"""
1021: # The negations cleverly convince floordiv to return the ceiling.
+1022: 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, 1022, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1022, __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, 1022, __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, 1022, __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, 1022, __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;
1023:
+1024: def __round__(self, ndigits=None):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_71__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_70__round__, "round(self, ndigits)\n\n Rounds half toward even.\n "); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_71__round__ = {"__round__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_71__round__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_70__round__}; static PyObject *__pyx_pw_10quicktions_8Fraction_71__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, 1024, __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, 1024, __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, 1024, __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_70__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_70__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__40 = 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__40)) __PYX_ERR(0, 1024, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__40); __Pyx_GIVEREF(__pyx_tuple__40); __pyx_codeobj__41 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__40, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_round_2, 1024, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__41)) __PYX_ERR(0, 1024, __pyx_L1_error) /* … */ __pyx_t_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_71__round__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___round, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__41)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1024, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_9, __pyx_tuple__42); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_round_2, __pyx_t_9) < 0) __PYX_ERR(0, 1024, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); __pyx_tuple__42 = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_tuple__42)) __PYX_ERR(0, 1024, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__42); __Pyx_GIVEREF(__pyx_tuple__42);
1025: """round(self, ndigits)
1026:
1027: Rounds half toward even.
1028: """
+1029: if ndigits is None:
__pyx_t_1 = (__pyx_v_ndigits == Py_None); if (__pyx_t_1) { /* … */ }
+1030: 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, 1030, __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, 1030, __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, 1030, __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, 1030, __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, 1030, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __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, 1030, __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, 1030, __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, 1030, __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;
+1031: 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, 1031, __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, 1031, __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, 1031, __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, 1031, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+1032: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
+1033: 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, 1033, __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, 1033, __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, 1033, __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, 1033, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1034: 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, 1034, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1035: # Deal with the half case:
+1036: 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, 1036, __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, 1036, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1037: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
1038: else:
+1039: 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, 1039, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1040: 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, 1040, __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, 1040, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_shift = __pyx_t_4; __pyx_t_4 = 0;
1041: # See _operator_fallbacks.forward to check that the results of
1042: # these operations will always be Fraction and therefore have
1043: # round().
+1044: 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, 1044, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1045: 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, 1045, __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, 1045, __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, 1045, __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, 1045, __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, 1045, __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, 1045, __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;
1046: else:
+1047: 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, 1047, __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, 1047, __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, 1047, __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, 1047, __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; }
1048:
+1049: def __float__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_73__float__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_72__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_72__float__; #endif static PyObject *__pyx_pw_10quicktions_8Fraction_73__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_72__float__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_72__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; }
1050: """float(self) = self.numerator / self.denominator
1051:
1052: It's important that this conversion use the integer's "true"
1053: division rather than casting one side to float before dividing
1054: so that ratios of huge integers convert without overflowing.
1055: """
+1056: 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, 1056, __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, 1056, __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, 1056, __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;
1057:
1058: # Concrete implementations of Complex abstract methods.
+1059: def __complex__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_75__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_74__complex__, "complex(self) == complex(float(self), 0)"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_75__complex__ = {"__complex__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_75__complex__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_74__complex__}; static PyObject *__pyx_pw_10quicktions_8Fraction_75__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_74__complex__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_74__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_9 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_75__complex__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___complex, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__43)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1059, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_complex, __pyx_t_9) < 0) __PYX_ERR(0, 1059, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 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__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_complex, 1059, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__43)) __PYX_ERR(0, 1059, __pyx_L1_error)
1060: """complex(self) == complex(float(self), 0)"""
+1061: 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, 1061, __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, 1061, __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;
1062:
1063: # == +self
+1064: real = property(__pos__, doc="Real numbers are their real component.")
__Pyx_GetNameInClass(__pyx_t_9, (PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_pos); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1064, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_3 = PyTuple_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1064, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_GIVEREF(__pyx_t_9); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_9)) __PYX_ERR(0, 1064, __pyx_L1_error); __pyx_t_9 = 0; __pyx_t_9 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1064, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); if (PyDict_SetItem(__pyx_t_9, __pyx_n_s_doc, __pyx_kp_s_Real_numbers_are_their_real_comp) < 0) __PYX_ERR(0, 1064, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_property, __pyx_t_3, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1064, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_10quicktions_Fraction, __pyx_n_s_real, __pyx_t_2) < 0) __PYX_ERR(0, 1064, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction);
1065:
1066: # == 0
+1067: @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; }
1068: def imag(self):
1069: "Real numbers have no imaginary component."
+1070: return 0
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_int_0); __pyx_r = __pyx_int_0; goto __pyx_L0;
1071:
+1072: def conjugate(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_77conjugate(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_76conjugate, "Conjugate is a no-op for Reals."); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_77conjugate = {"conjugate", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_77conjugate, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_76conjugate}; static PyObject *__pyx_pw_10quicktions_8Fraction_77conjugate(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_76conjugate(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_76conjugate(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_77conjugate, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction_conjugate, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__44)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1072, __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, 1072, __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__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_conjugate, 1072, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__44)) __PYX_ERR(0, 1072, __pyx_L1_error)
1073: """Conjugate is a no-op for Reals."""
+1074: return +self
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Positive(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1074, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1075:
+1076: def __hash__(self):
/* Python wrapper */ static Py_hash_t __pyx_pw_10quicktions_8Fraction_79__hash__(PyObject *__pyx_v_self); /*proto*/ PyDoc_STRVAR(__pyx_doc_10quicktions_8Fraction_78__hash__, "hash(self)"); #if CYTHON_UPDATE_DESCRIPTOR_DOC struct wrapperbase __pyx_wrapperbase_10quicktions_8Fraction_78__hash__; #endif static Py_hash_t __pyx_pw_10quicktions_8Fraction_79__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_78__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_78__hash__(struct __pyx_obj_10quicktions_Fraction *__pyx_v_self) { Py_hash_t __pyx_v_result; 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_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_AddTraceback("quicktions.Fraction.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = -1; __pyx_L0:; __Pyx_XDECREF(__pyx_v_dinv); if (unlikely(__pyx_r == -1) && !PyErr_Occurred()) __pyx_r = -2; __Pyx_RefNannyFinishContext(); return __pyx_r; }
1077: """hash(self)"""
+1078: if self._hash != -1:
__pyx_t_1 = (__pyx_v_self->_hash != -1L); if (__pyx_t_1) { /* … */ }
+1079: return self._hash
__pyx_r = __pyx_v_self->_hash; goto __pyx_L0;
1080:
1081: cdef Py_hash_t result
1082:
1083: # In order to make sure that the hash of a Fraction agrees
1084: # with the hash of a numerically equal integer, float or
1085: # Decimal instance, we follow the rules for numeric hashes
1086: # outlined in the documentation. (See library docs, 'Built-in
1087: # Types').
1088:
+1089: if PY_VERSION_HEX < 0x030800B1:
__pyx_t_1 = (PY_VERSION_HEX < 0x030800B1); if (__pyx_t_1) { /* … */ goto __pyx_L4; }
1090: # dinv is the inverse of self._denominator modulo the prime
1091: # _PyHASH_MODULUS, or 0 if self._denominator is divisible by
1092: # _PyHASH_MODULUS.
+1093: dinv = pow(self._denominator, _PyHASH_MODULUS - 2, _PyHASH_MODULUS)
__pyx_t_2 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_FromHash_t((__pyx_v_10quicktions__PyHASH_MODULUS - 2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1093, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyInt_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1093, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Power(__pyx_t_2, __pyx_t_3, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1093, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_v_dinv = __pyx_t_5; __pyx_t_5 = 0;
+1094: if not dinv:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dinv); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1094, __pyx_L1_error) __pyx_t_6 = (!__pyx_t_1); if (__pyx_t_6) { /* … */ goto __pyx_L5; }
+1095: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF;
1096: else:
+1097: result = abs(self._numerator) * dinv % _PyHASH_MODULUS
/*else*/ { __pyx_t_5 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_dinv); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyInt_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Remainder(__pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = __Pyx_PyInt_AsHash_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1097, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_result = __pyx_t_7; } __pyx_L5:;
1098: else:
1099: # Py3.8+
+1100: try:
/*else*/ { { /*try:*/ { /* … */ } /* … */ __pyx_L8_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_L7_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_L11_try_end:; } } __pyx_L4:;
+1101: dinv = pow(self._denominator, -1, _PyHASH_MODULUS)
__pyx_t_3 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyInt_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1101, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Power(__pyx_t_3, __pyx_int_neg_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1101, __pyx_L6_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_v_dinv = __pyx_t_5; __pyx_t_5 = 0;
+1102: 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_5, &__pyx_t_4, &__pyx_t_3) < 0) __PYX_ERR(0, 1102, __pyx_L8_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_4); __Pyx_XGOTREF(__pyx_t_3);
1103: # ValueError means there is no modular inverse.
+1104: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L7_exception_handled; } goto __pyx_L8_except_error;
1105: else:
1106: # The general algorithm now specifies that the absolute value of
1107: # the hash is
1108: # (|N| * dinv) % P
1109: # where N is self._numerator and P is _PyHASH_MODULUS. That's
1110: # optimized here in two ways: first, for a non-negative int i,
1111: # hash(i) == i % P, but the int hash implementation doesn't need
1112: # to divide, and is faster than doing % P explicitly. So we do
1113: # hash(|N| * dinv)
1114: # instead. Second, N is unbounded, so its product with dinv may
1115: # be arbitrarily expensive to compute. The final answer is the
1116: # same if we use the bounded |N| % P instead, which can again
1117: # be done with an int hash() call. If 0 <= i < P, hash(i) == i,
1118: # so this nested hash() call wastes a bit of time making a
1119: # redundant copy when |N| < P, but can save an arbitrarily large
1120: # amount of computation for large |N|.
+1121: result = hash(hash(abs(self._numerator)) * dinv)
/*else:*/ { __pyx_t_5 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_5); __pyx_t_4 = __Pyx_PyNumber_Absolute(__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1121, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = PyObject_Hash(__pyx_t_4); if (unlikely(__pyx_t_7 == ((Py_hash_t)-1))) __PYX_ERR(0, 1121, __pyx_L8_except_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyInt_FromHash_t(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1121, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Multiply(__pyx_t_4, __pyx_v_dinv); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1121, __pyx_L8_except_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_7 = PyObject_Hash(__pyx_t_5); if (unlikely(__pyx_t_7 == ((Py_hash_t)-1))) __PYX_ERR(0, 1121, __pyx_L8_except_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_v_result = __pyx_t_7; } __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_L11_try_end; __pyx_L6_error:; __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
1122:
+1123: if self._numerator < 0:
__pyx_t_3 = PyObject_RichCompare(__pyx_v_self->_numerator, __pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1123, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 1123, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_6) { /* … */ }
+1124: result = -result
__pyx_v_result = (-__pyx_v_result);
+1125: if result == -1:
__pyx_t_6 = (__pyx_v_result == -1L); if (__pyx_t_6) { /* … */ }
+1126: result = -2
__pyx_v_result = -2L;
+1127: self._hash = result
__pyx_v_self->_hash = __pyx_v_result;
+1128: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
1129:
+1130: def __richcmp__(a, b, int op):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_81__richcmp__(PyObject *__pyx_v_a, PyObject *__pyx_v_b, int __pyx_v_op); /*proto*/ static PyObject *__pyx_pw_10quicktions_8Fraction_81__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_80__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_80__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; }
+1131: if isinstance(a, Fraction):
__pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_a), __pyx_ptype_10quicktions_Fraction);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1132: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ); if (__pyx_t_1) { /* … */ }
+1133: return (<Fraction>a)._eq(b)
__Pyx_XDECREF(__pyx_r); __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, 1133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1134: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE); if (__pyx_t_1) { /* … */ }
+1135: result = (<Fraction>a)._eq(b)
__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) __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0;
+1136: 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, 1136, __pyx_L1_error) __pyx_t_4 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1136, __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;
1137: else:
+1138: 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, 1138, __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;
+1139: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ); if (__pyx_t_1) { /* … */ }
+1140: return (<Fraction>a)._eq(b)
__Pyx_XDECREF(__pyx_r); __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, 1140, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1141: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE); if (__pyx_t_1) { /* … */ }
+1142: result = (<Fraction>a)._eq(b)
__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) __Pyx_GOTREF(__pyx_t_4); __pyx_v_result = __pyx_t_4; __pyx_t_4 = 0;
+1143: 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, 1143, __pyx_L1_error) __pyx_t_2 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1143, __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;
+1144: elif op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1145: op = Py_GE
__pyx_v_op = Py_GE;
+1146: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1147: op = Py_LE
__pyx_v_op = Py_LE;
+1148: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1149: op = Py_GT
__pyx_v_op = Py_GT;
+1150: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1151: op = Py_LT
__pyx_v_op = Py_LT;
1152: else:
+1153: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; } __pyx_L5:; } __pyx_L3:;
+1154: return (<Fraction>a)._richcmp(b, op)
__Pyx_XDECREF(__pyx_r); __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, 1154, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1155:
1156: @cython.final
+1157: 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; }
+1158: 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) { /* … */ }
+1159: 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, 1159, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1159, __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, 1159, __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;
+1160: if type(b) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1161: 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, 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_L9_bool_binop_done; }
+1162: 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, 1162, __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;
+1163: 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, 1163, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+1164: 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, 1164, __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, 1164, __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, 1164, __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; }
+1165: 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, 1165, __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, 1165, __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;
+1166: 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, 1166, __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, 1166, __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, 1166, __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) { /* … */ }
+1167: b = b.real
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_n_s_real); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1167, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_3); __pyx_t_3 = 0;
+1168: if isinstance(b, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1169: 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, 1169, __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, 1169, __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, 1169, __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, 1169, __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, 1169, __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, 1169, __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) { /* … */ }
1170: # comparisons with an infinity or nan should behave in
1171: # the same way for any finite a, so treat a as zero.
+1172: 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, 1172, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1173: else:
+1174: 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, 1174, __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, 1174, __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, 1174, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1175: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
1176:
1177: @cython.final
+1178: 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; }
1179: """Helper for comparison operators, for internal use only.
1180:
1181: Implement comparison between a Rational instance `self`, and
1182: either another Rational instance or a float `other`. If
1183: `other` is not a Rational instance or a float, return
1184: NotImplemented. `op` should be one of the six standard
1185: comparison operators.
1186:
1187: """
1188: # convert other to a Rational instance where reasonable.
+1189: 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; }
+1190: 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;
+1191: b = self._denominator * other
__pyx_t_3 = PyNumber_Multiply(__pyx_v_self->_denominator, __pyx_v_other); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1191, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_b = __pyx_t_3; __pyx_t_3 = 0;
+1192: 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; }
+1193: 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, 1193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_a = __pyx_t_3; __pyx_t_3 = 0;
+1194: 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, 1194, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_b = __pyx_t_3; __pyx_t_3 = 0;
+1195: elif isinstance(other, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1196: 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, 1196, __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, 1196, __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, 1196, __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, 1196, __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, 1196, __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, 1196, __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; }
+1197: 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;
1198: else:
+1199: 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, 1199, __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, 1199, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __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, 1199, __pyx_L1_error) __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:;
+1200: 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; }
+1201: 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, 1201, __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, 1201, __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;
+1202: 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, 1202, __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, 1202, __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;
1203: else:
1204: # comparisons with complex should raise a TypeError, for consistency
1205: # with int<->complex, float<->complex, and complex<->complex comparisons.
+1206: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; } __pyx_L3:;
1207:
+1208: if op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT); if (__pyx_t_1) { /* … */ }
+1209: 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, 1209, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1210: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT); if (__pyx_t_1) { /* … */ }
+1211: 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, 1211, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1212: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE); if (__pyx_t_1) { /* … */ }
+1213: 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, 1213, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1214: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE); if (__pyx_t_1) { /* … */ }
+1215: 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, 1215, __pyx_L1_error) __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1216: else:
+1217: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1218:
+1219: def __bool__(self):
/* Python wrapper */ static int __pyx_pw_10quicktions_8Fraction_83__bool__(PyObject *__pyx_v_self); /*proto*/ static int __pyx_pw_10quicktions_8Fraction_83__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_82__bool__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static int __pyx_pf_10quicktions_8Fraction_82__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; }
1220: """a != 0"""
1221: # Use bool() because (a._numerator != 0) can return an
1222: # object which is not a bool.
1223: # See https://bugs.python.org/issue39274
+1224: return bool(self._numerator)
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->_numerator); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1224, __pyx_L1_error) __pyx_r = (!(!__pyx_t_1)); goto __pyx_L0;
1225:
1226: # support for pickling, copy, and deepcopy
1227:
+1228: def __reduce__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_85__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_85__reduce__ = {"__reduce__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_85__reduce__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10quicktions_8Fraction_85__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_84__reduce__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_84__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_85__reduce__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___reduce, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__45)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1228, __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, 1228, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__45 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_reduce, 1228, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__45)) __PYX_ERR(0, 1228, __pyx_L1_error)
+1229: 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, 1229, __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, 1229, __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, 1229, __pyx_L1_error); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1229, __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, 1229, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1)) __PYX_ERR(0, 1229, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1230:
+1231: def __copy__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_87__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_87__copy__ = {"__copy__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_87__copy__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10quicktions_8Fraction_87__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_86__copy__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_self)); /* function exit code */ __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_86__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_87__copy__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___copy, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__46)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1231, __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, 1231, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction); /* … */ __pyx_codeobj__46 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__28, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_src_quicktions_pyx, __pyx_n_s_copy, 1231, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__46)) __PYX_ERR(0, 1231, __pyx_L1_error)
+1232: if type(self) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1233: 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;
+1234: 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, 1234, __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;
1235:
+1236: def __deepcopy__(self, memo):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_89__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_89__deepcopy__ = {"__deepcopy__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_89__deepcopy__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; static PyObject *__pyx_pw_10quicktions_8Fraction_89__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, 1236, __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, 1236, __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, 1236, __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_88__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_88__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__47 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_memo); if (unlikely(!__pyx_tuple__47)) __PYX_ERR(0, 1236, __pyx_L1_error) __Pyx_GOTREF(__pyx_tuple__47); __Pyx_GIVEREF(__pyx_tuple__47); /* … */ __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_89__deepcopy__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_Fraction___deepcopy, NULL, __pyx_n_s_quicktions, __pyx_d, ((PyObject *)__pyx_codeobj__48)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1236, __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, 1236, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; PyType_Modified(__pyx_ptype_10quicktions_Fraction);
+1237: if type(self) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1238: 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;
+1239: 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, 1239, __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;
1240:
1241:
1242: # Register with Python's numerical tower.
+1243: 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, 1243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PyObject_CallOneArg(__pyx_t_2, ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1244:
1245:
+1246: 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; };
1247: """Convert a pair of ints to a rational number, for internal use.
1248:
1249: The ratio of integers should be in lowest terms and the denominator
1250: should be positive.
1251: """
1252: cdef Fraction obj
+1253: 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; }
+1254: obj = Fraction.__new__(Fraction, NOINIT, NOINIT)
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1254, __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, 1254, __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, 1254, __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, 1254, __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;
1255: else:
+1256: obj = cls.__new__(cls)
/*else*/ { __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_cls, __pyx_n_s_new); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1256, __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_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, 1256, __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, 1256, __pyx_L1_error) __pyx_v_obj = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_4); __pyx_t_4 = 0; } __pyx_L3:;
+1257: 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;
+1258: 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;
+1259: return obj
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_obj); __pyx_r = ((PyObject *)__pyx_v_obj); goto __pyx_L0;
1260:
1261:
+1262: 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; }
+1263: 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, 1263, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
1264: # power = bn
+1265: 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, 1265, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1265, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1266: 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, 1266, __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;
+1267: an ** bn,
__pyx_t_2 = PyNumber_Power(__pyx_v_an, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1267, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+1268: ad ** bn)
__pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1268, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+1269: 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, 1269, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1269, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 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_3, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1270, __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;
+1271: ad ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1271, __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, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1272: an ** -bn)
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1272, __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, 1272, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1273: 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, 1273, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1274: raise ZeroDivisionError(f'Fraction({ad ** -bn}, 0)')
__pyx_t_4 = PyTuple_New(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1274, __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, 1274, __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, 1274, __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, 1274, __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, 1274, __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, 1274, __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, 1274, __pyx_L1_error)
1275: else:
+1276: 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, 1276, __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; }
+1277: (-ad) ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1277, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1277, __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, 1277, __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;
+1278: (-an) ** -bn)
__pyx_t_2 = PyNumber_Negative(__pyx_v_an); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1278, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1278, __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, 1278, __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;
1279: else:
1280: # A fractional power will generally produce an
1281: # irrational number.
+1282: 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, 1282, __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, 1282, __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, 1282, __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; }
1283:
1284:
+1285: 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; }
+1286: 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, 1286, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1287:
1288:
1289: # Rational arithmetic algorithms: Knuth, TAOCP, Volume 2, 4.5.1.
1290: #
1291: # Assume input fractions a and b are normalized.
1292: #
1293: # 1) Consider addition/subtraction.
1294: #
1295: # Let g = gcd(da, db). Then
1296: #
1297: # na nb na*db ± nb*da
1298: # a ± b == -- ± -- == ------------- ==
1299: # da db da*db
1300: #
1301: # na*(db//g) ± nb*(da//g) t
1302: # == ----------------------- == -
1303: # (da*db)//g d
1304: #
1305: # Now, if g > 1, we're working with smaller integers.
1306: #
1307: # Note, that t, (da//g) and (db//g) are pairwise coprime.
1308: #
1309: # Indeed, (da//g) and (db//g) share no common factors (they were
1310: # removed) and da is coprime with na (since input fractions are
1311: # normalized), hence (da//g) and na are coprime. By symmetry,
1312: # (db//g) and nb are coprime too. Then,
1313: #
1314: # gcd(t, da//g) == gcd(na*(db//g), da//g) == 1
1315: # gcd(t, db//g) == gcd(nb*(da//g), db//g) == 1
1316: #
1317: # Above allows us optimize reduction of the result to lowest
1318: # terms. Indeed,
1319: #
1320: # g2 = gcd(t, d) == gcd(t, (da//g)*(db//g)*g) == gcd(t, g)
1321: #
1322: # t//g2 t//g2
1323: # a ± b == ----------------------- == ----------------
1324: # (da//g)*(db//g)*(g//g2) (da//g)*(db//g2)
1325: #
1326: # is a normalized fraction. This is useful because the unnormalized
1327: # denominator d could be much larger than g.
1328: #
1329: # We should special-case g == 1 (and g2 == 1), since 60.8% of
1330: # randomly-chosen integers are coprime:
1331: # https://en.wikipedia.org/wiki/Coprime_integers#Probability_of_coprimality
1332: # Note, that g2 == 1 always for fractions, obtained from floats: here
1333: # g is a power of 2 and the unnormalized numerator t is an odd integer.
1334: #
1335: # 2) Consider multiplication
1336: #
1337: # Let g1 = gcd(na, db) and g2 = gcd(nb, da), then
1338: #
1339: # na*nb na*nb (na//g1)*(nb//g2)
1340: # a*b == ----- == ----- == -----------------
1341: # da*db db*da (db//g1)*(da//g2)
1342: #
1343: # Note, that after divisions we're multiplying smaller integers.
1344: #
1345: # Also, the resulting fraction is normalized, because each of
1346: # two factors in the numerator is coprime to each of the two factors
1347: # in the denominator.
1348: #
1349: # Indeed, pick (na//g1). It's coprime with (da//g2), because input
1350: # fractions are normalized. It's also coprime with (db//g1), because
1351: # common factors are removed by g1 == gcd(na, db).
1352: #
1353: # As for addition/subtraction, we should special-case g1 == 1
1354: # and g2 == 1 for same reason. That happens also for multiplying
1355: # rationals, obtained from floats.
1356:
+1357: 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; }
1358: """a + b"""
1359: # return Fraction(na * db + nb * da, da * db)
+1360: 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, 1360, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1361: 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, 1361, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1362: 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, 1362, __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, 1362, __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, 1362, __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, 1362, __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, 1362, __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;
+1363: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1364: 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, 1364, __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, 1364, __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, 1364, __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, 1364, __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;
+1365: 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, 1365, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g2 = __pyx_t_4; __pyx_t_4 = 0;
+1366: 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, 1366, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1367: 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, 1367, __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, 1367, __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;
+1368: 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, 1368, __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, 1368, __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, 1368, __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, 1368, __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;
1369:
+1370: 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; }
1371: """a - b"""
1372: # return Fraction(na * db - nb * da, da * db)
+1373: 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, 1373, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1374: 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, 1374, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1375: 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, 1375, __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, 1375, __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, 1375, __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, 1375, __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, 1375, __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;
+1376: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1376, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1377: 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, 1377, __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, 1377, __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, 1377, __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, 1377, __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;
+1378: 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, 1378, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g2 = __pyx_t_4; __pyx_t_4 = 0;
+1379: 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, 1379, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1380: 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, 1380, __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, 1380, __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;
+1381: 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, 1381, __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, 1381, __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, 1381, __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, 1381, __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;
1382:
+1383: 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; }
1384: """a * b"""
1385: # return Fraction(na * nb, da * db)
+1386: 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, 1386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g1 = __pyx_t_1; __pyx_t_1 = 0;
+1387: 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, 1387, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1387, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1388: na //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1388, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_1); __pyx_t_1 = 0;
+1389: db //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_1); __pyx_t_1 = 0;
+1390: 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, 1390, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g2 = __pyx_t_1; __pyx_t_1 = 0;
+1391: 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, 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: nb //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1392, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_1); __pyx_t_1 = 0;
+1393: da //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1393, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_1); __pyx_t_1 = 0;
+1394: 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, 1394, __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, 1394, __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, 1394, __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;
1395:
+1396: 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; }
1397: """a / b"""
1398: # return Fraction(na * db, da * nb)
1399: # Same as _mul(), with inversed b.
+1400: 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, 1400, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1401: raise ZeroDivisionError(f'Fraction({db}, 0)')
__pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1401, __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, 1401, __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, 1401, __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, 1401, __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, 1401, __pyx_L1_error)
+1402: 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, 1402, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_g1 = __pyx_t_2; __pyx_t_2 = 0;
+1403: 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, 1403, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1403, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1404: na //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1404, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_2); __pyx_t_2 = 0;
+1405: nb //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_2); __pyx_t_2 = 0;
+1406: 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, 1406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1407: 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, 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: da //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_2); __pyx_t_2 = 0;
+1409: db //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_2); __pyx_t_2 = 0;
+1410: 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, 1410, __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, 1410, __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;
+1411: 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, 1411, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1411, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+1412: n, d = -n, -d
__pyx_t_5 = PyNumber_Negative(__pyx_v_n); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = PyNumber_Negative(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1412, __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;
+1413: 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, 1413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1414:
+1415: 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; }
1416: """a // b -> int"""
+1417: 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, 1417, __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, 1417, __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, 1417, __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;
1418:
+1419: 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; }
+1420: 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, 1420, __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, 1420, __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, 1420, __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, 1420, __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, 1420, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1420, __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, 1420, __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, 1420, __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, 1420, __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;
+1421: 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, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1421, __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, 1421, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3)) __PYX_ERR(0, 1421, __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, 1421, __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, 1421, __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, 1421, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_3)) __PYX_ERR(0, 1421, __pyx_L1_error); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1422:
+1423: 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; }
+1424: 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, 1424, __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, 1424, __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, 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; __pyx_t_2 = PyNumber_Multiply(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1424, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1424, __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, 1424, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2)) __PYX_ERR(0, 1424, __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, 1424, __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;
1425:
1426:
1427: """
1428: In general, we want to implement the arithmetic operations so
1429: that mixed-mode operations either call an implementation whose
1430: author knew about the types of both arguments, or convert both
1431: to the nearest built in type and do the operation there. In
1432: Fraction, that means that we define __add__ and __radd__ as:
1433:
1434: def __add__(self, other):
1435: # Both types have numerators/denominator attributes,
1436: # so do the operation directly
1437: if isinstance(other, (int, Fraction)):
1438: return Fraction(self.numerator * other.denominator +
1439: other.numerator * self.denominator,
1440: self.denominator * other.denominator)
1441: # float and complex don't have those operations, but we
1442: # know about those types, so special case them.
1443: elif isinstance(other, float):
1444: return float(self) + other
1445: elif isinstance(other, complex):
1446: return complex(self) + other
1447: # Let the other type take over.
1448: return NotImplemented
1449:
1450: def __radd__(self, other):
1451: # radd handles more types than add because there's
1452: # nothing left to fall back to.
1453: if isinstance(other, Rational):
1454: return Fraction(self.numerator * other.denominator +
1455: other.numerator * self.denominator,
1456: self.denominator * other.denominator)
1457: elif isinstance(other, Real):
1458: return float(other) + float(self)
1459: elif isinstance(other, Complex):
1460: return complex(other) + complex(self)
1461: return NotImplemented
1462:
1463:
1464: There are 5 different cases for a mixed-type addition on
1465: Fraction. I'll refer to all of the above code that doesn't
1466: refer to Fraction, float, or complex as "boilerplate". 'r'
1467: will be an instance of Fraction, which is a subtype of
1468: Rational (r : Fraction <: Rational), and b : B <:
1469: Complex. The first three involve 'r + b':
1470:
1471: 1. If B <: Fraction, int, float, or complex, we handle
1472: that specially, and all is well.
1473: 2. If Fraction falls back to the boilerplate code, and it
1474: were to return a value from __add__, we'd miss the
1475: possibility that B defines a more intelligent __radd__,
1476: so the boilerplate should return NotImplemented from
1477: __add__. In particular, we don't handle Rational
1478: here, even though we could get an exact answer, in case
1479: the other type wants to do something special.
1480: 3. If B <: Fraction, Python tries B.__radd__ before
1481: Fraction.__add__. This is ok, because it was
1482: implemented with knowledge of Fraction, so it can
1483: handle those instances before delegating to Real or
1484: Complex.
1485:
1486: The next two situations describe 'b + r'. We assume that b
1487: didn't know about Fraction in its implementation, and that it
1488: uses similar boilerplate code:
1489:
1490: 4. If B <: Rational, then __radd_ converts both to the
1491: builtin rational type (hey look, that's us) and
1492: proceeds.
1493: 5. Otherwise, __radd__ tries to find the nearest common
1494: base ABC, and fall back to its builtin type. Since this
1495: class doesn't subclass a concrete type, there's no
1496: implementation to fall back to, so we need to try as
1497: hard as possible to return an actual value, or the user
1498: will get a TypeError.
1499: """
1500:
1501: cdef:
+1502: _math_op_add = operator.add
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_add); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1502, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_add); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_add, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1503: _math_op_sub = operator.sub
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_sub); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_sub); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_sub, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1504: _math_op_mul = operator.mul
__pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_mul); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_mul); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_mul, __pyx_t_9); __Pyx_GIVEREF(__pyx_t_9); __pyx_t_9 = 0;
+1505: _math_op_div = getattr(operator, 'div', operator.truediv) # Py2/3
__pyx_t_9 = __pyx_v_10quicktions_operator; __Pyx_INCREF(__pyx_t_9); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_truediv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1505, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_GetAttr3(__pyx_t_9, __pyx_n_s_div, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1505, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 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_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1506: _math_op_truediv = operator.truediv
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_truediv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1506, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_truediv); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_truediv, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1507: _math_op_floordiv = operator.floordiv
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_floordiv); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1507, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_floordiv); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_floordiv, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1508: _math_op_mod = operator.mod
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_n_s_mod); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_mod); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_mod, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1509: _math_op_divmod = divmod
__pyx_t_3 = __Pyx_GetBuiltinName(__pyx_n_s_divmod); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1509, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_divmod); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_divmod, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
1510:
1511:
+1512: ctypedef object (*math_func)(an, ad, bn, bd)
typedef PyObject *(*__pyx_t_10quicktions_math_func)(PyObject *, PyObject *, PyObject *, PyObject *);
1513:
1514:
+1515: cdef forward(a, b, math_func monomorphic_operator, pyoperator, handle_complex=True):
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, struct __pyx_opt_args_10quicktions_forward *__pyx_optional_args) { PyObject *__pyx_v_handle_complex = ((PyObject *)Py_True); PyObject *__pyx_v_an = NULL; PyObject *__pyx_v_ad = NULL; PyObject *__pyx_r = NULL; if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_handle_complex = __pyx_optional_args->handle_complex; } } /* … */ /* 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_5); __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; } /* … */ struct __pyx_opt_args_10quicktions_forward { int __pyx_n; PyObject *handle_complex; };
+1516: 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;
+1517: if type(b) is Fraction:
__pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_3) { /* … */ }
+1518: 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, 1518, __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;
+1519: elif isinstance(b, int):
__pyx_t_3 = PyInt_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1520: 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, 1520, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1521: elif isinstance(b, Fraction):
__pyx_t_3 = __Pyx_TypeCheck(__pyx_v_b, __pyx_ptype_10quicktions_Fraction);
if (__pyx_t_3) {
/* … */
}
+1522: 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, 1522, __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, 1522, __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, 1522, __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;
+1523: elif isinstance(b, float):
__pyx_t_3 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1524: 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, 1524, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_4 = __pyx_v_pyoperator; __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[3] = {__pyx_t_5, __pyx_t_1, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1524, __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;
+1525: elif handle_complex and isinstance(b, complex):
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_v_handle_complex); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1525, __pyx_L1_error) if (__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L4_bool_binop_done; } __pyx_t_7 = PyComplex_Check(__pyx_v_b); __pyx_t_3 = __pyx_t_7; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1526: return pyoperator(float(a), b)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyNumber_Float(__pyx_v_a); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_1 = __pyx_v_pyoperator; __pyx_t_5 = NULL; __pyx_t_6 = 0; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_1); if (likely(__pyx_t_5)) { PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(function); __Pyx_DECREF_SET(__pyx_t_1, function); __pyx_t_6 = 1; } } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_t_4, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 2+__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_2)) __PYX_ERR(0, 1526, __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;
1527: else:
+1528: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1529:
1530:
+1531: cdef reverse(a, b, math_func monomorphic_operator, pyoperator, handle_complex=True):
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, struct __pyx_opt_args_10quicktions_reverse *__pyx_optional_args) { PyObject *__pyx_v_handle_complex = ((PyObject *)Py_True); PyObject *__pyx_v_bn = NULL; PyObject *__pyx_v_bd = NULL; PyObject *__pyx_r = NULL; if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_handle_complex = __pyx_optional_args->handle_complex; } } /* … */ /* 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_5); __Pyx_XDECREF(__pyx_t_6); __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; } /* … */ struct __pyx_opt_args_10quicktions_reverse { int __pyx_n; PyObject *handle_complex; };
+1532: 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;
+1533: if isinstance(a, int):
__pyx_t_3 = PyInt_Check(__pyx_v_a);
if (__pyx_t_3) {
/* … */
}
+1534: 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, 1534, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1535: 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, 1535, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { /* … */ }
+1536: 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, 1536, __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, 1536, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __pyx_v_monomorphic_operator(__pyx_t_2, __pyx_t_1, __pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1536, __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;
+1537: elif isinstance(a, Real):
__pyx_t_4 = __pyx_v_10quicktions_Real; __Pyx_INCREF(__pyx_t_4); __pyx_t_3 = PyObject_IsInstance(__pyx_v_a, __pyx_t_4); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 1537, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_3) { /* … */ }
+1538: 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, 1538, __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, 1538, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_5 = __pyx_v_pyoperator; __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_t_1, __pyx_t_2}; __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; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1538, __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;
+1539: elif handle_complex and isinstance(a, Complex):
__pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_v_handle_complex); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 1539, __pyx_L1_error) if (__pyx_t_8) { } else { __pyx_t_3 = __pyx_t_8; goto __pyx_L4_bool_binop_done; } __pyx_t_4 = __pyx_v_10quicktions_Complex; __Pyx_INCREF(__pyx_t_4); __pyx_t_8 = PyObject_IsInstance(__pyx_v_a, __pyx_t_4); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 1539, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_3 = __pyx_t_8; __pyx_L4_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1540: return pyoperator(complex(a), float(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __Pyx_PyObject_CallOneArg(((PyObject *)(&PyComplex_Type)), __pyx_v_a); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_PyNumber_Float(__pyx_v_b); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __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_5, __pyx_t_2}; __pyx_t_4 = __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_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1540, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1541: else:
+1542: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1543:
1544:
+1545: ctypedef char* charptr
typedef char *__pyx_t_10quicktions_charptr;
1546:
1547: ctypedef fused AnyString:
1548: unicode
1549: charptr
1550:
1551:
+1552: 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 };
1553: BEGIN_SPACE # '\s'* -> (BEGIN_SIGN, SMALL_NUM, START_DECIMAL_DOT)
1554: BEGIN_SIGN # [+-] -> (SMALL_NUM, SMALL_DECIMAL_DOT)
1555: SMALL_NUM # [0-9]+ -> (SMALL_NUM, SMALL_NUM_US, NUM, NUM_SPACE, SMALL_DECIMAL_DOT, EXP_E, DENOM_START)
1556: SMALL_NUM_US # '_' -> (SMALL_NUM, NUM)
1557: NUM # [0-9]+ -> (NUM, NUM_US, NUM_SPACE, DECIMAL_DOT, EXP_E, DENOM_START)
1558: NUM_US # '_' -> (NUM)
1559: NUM_SPACE # '\s'+ -> (DENOM_START)
1560:
1561: # 1) floating point syntax
1562: START_DECIMAL_DOT # '.' -> (SMALL_DECIMAL)
1563: SMALL_DECIMAL_DOT # '.' -> (SMALL_DECIMAL, EXP_E, SMALL_END_SPACE)
1564: DECIMAL_DOT # '.' -> (DECIMAL, EXP_E, END_SPACE)
1565: SMALL_DECIMAL # [0-9]+ -> (SMALL_DECIMAL, SMALL_DECIMAL_US, DECIMAL, EXP_E, SMALL_END_SPACE)
1566: SMALL_DECIMAL_US # '_' -> (SMALL_DECIMAL, DECIMAL)
1567: DECIMAL # [0-9]+ -> (DECIMAL, DECIMAL_US, EXP_E, END_SPACE)
1568: DECIMAL_US # '_' -> (DECIMAL)
1569: EXP_E # [eE] -> (EXP_SIGN, EXP)
1570: EXP_SIGN # [+-] -> (EXP)
1571: EXP # [0-9]+ -> (EXP_US, END_SPACE)
1572: EXP_US # '_' -> (EXP)
1573: END_SPACE # '\s'+
1574: SMALL_END_SPACE # '\s'+
1575:
1576: # 2) "NOM / DENOM" syntax
1577: DENOM_START # '/' -> (DENOM_SIGN, SMALL_DENOM)
1578: DENOM_SIGN # [+-] -> (SMALL_DENOM)
1579: SMALL_DENOM # [0-9]+ -> (SMALL_DENOM, SMALL_DENOM_US, DENOM, DENOM_SPACE)
1580: SMALL_DENOM_US # '_' -> (SMALL_DENOM)
1581: DENOM # [0-9]+ -> (DENOM, DENOM_US, DENOM_SPACE)
1582: DENOM_US # '_' -> (DENOM)
1583: DENOM_SPACE # '\s'+
1584:
1585:
+1586: 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_4); __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; }
+1587: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1588: 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, 1588, __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, 1588, __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, 1588, __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, 1588, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__16); __Pyx_GIVEREF(__pyx_slice__16); /* … */ }
+1589: 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, 1589, __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, 1589, __pyx_L1_error) __Pyx_GOTREF(__pyx_slice__17); __Pyx_GIVEREF(__pyx_slice__17);
+1590: 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, 1590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Invalid_literal_for_Fraction, __pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1590, __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, 1590, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 1590, __pyx_L1_error)
1591:
1592:
+1593: 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; }
+1594: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1595: 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, 1595, __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, 1595, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1596: 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, 1596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1597: 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, 1597, __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, 1597, __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, 1597, __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, 1597, __pyx_L1_error)
1598:
1599:
1600: cdef extern from *:
1601: """
1602: static CYTHON_INLINE int __QUICKTIONS_unpack_ustring(
1603: PyObject* string, Py_ssize_t *length, void** data, int *kind) {
1604: if (PyUnicode_READY(string) < 0) return -1;
1605: *kind = PyUnicode_KIND(string);
1606: *length = PyUnicode_GET_LENGTH(string);
1607: *data = PyUnicode_DATA(string);
1608: return 0;
1609: }
1610: #define __QUICKTIONS_char_at(data, kind, index) \
1611: (((kind == 1) ? (Py_UCS4) ((char*) data)[index] : (Py_UCS4) PyUnicode_READ(kind, data, index)))
1612: """
1613: int _unpack_ustring "__QUICKTIONS_unpack_ustring" (
1614: object string, Py_ssize_t *length, void **data, int *kind) except -1
1615: Py_UCS4 _char_at "__QUICKTIONS_char_at" (void *data, int kind, Py_ssize_t index)
1616: Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)
1617:
1618:
+1619: 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; }
1620: cdef unsigned int unum
1621: cdef int num
+1622: 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'));
+1623: if unum > 9:
__pyx_t_1 = (__pyx_v_unum > 9); if (__pyx_t_1) { /* … */ }
+1624: if not allow_unicode:
__pyx_t_1 = (!(__pyx_v_allow_unicode != 0)); if (__pyx_t_1) { /* … */ }
+1625: return -1
__pyx_r = -1; goto __pyx_L0;
+1626: num = Py_UNICODE_TODECIMAL(c)
__pyx_v_num = Py_UNICODE_TODECIMAL(__pyx_v_c);
+1627: if num == -1:
__pyx_t_1 = (__pyx_v_num == -1L); if (__pyx_t_1) { /* … */ }
+1628: return -1
__pyx_r = -1; goto __pyx_L0;
+1629: unum = <unsigned int> num
__pyx_v_unum = ((unsigned int)__pyx_v_num);
+1630: c = <Py_UCS4> (num + c'0')
__pyx_v_c = ((Py_UCS4)(__pyx_v_num + '0'));
+1631: if c_digits:
__pyx_t_1 = (__pyx_v_c_digits != 0); if (__pyx_t_1) { /* … */ }
+1632: c_digits[0][0] = <char> c
((__pyx_v_c_digits[0])[0]) = ((char)__pyx_v_c);
+1633: c_digits[0] += 1
__pyx_t_2 = 0; (__pyx_v_c_digits[__pyx_t_2]) = ((__pyx_v_c_digits[__pyx_t_2]) + 1);
+1634: return <int> unum
__pyx_r = ((int)__pyx_v_unum); goto __pyx_L0;
1635:
1636:
+1637: 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; }
+1638: c_digits_end[0][0] = 0
((__pyx_v_c_digits_end[0])[0]) = 0;
+1639: 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, 1639, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_py_number = __pyx_t_1; __pyx_t_1 = 0;
+1640: c_digits_end[0] = c_digits_start # reset
(__pyx_v_c_digits_end[0]) = __pyx_v_c_digits_start;
+1641: return py_number
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_py_number); __pyx_r = __pyx_v_py_number; goto __pyx_L0;
1642:
1643:
1644: @cython.cdivision(True)
+1645: 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; }
1646: """
1647: Parse a string into a number tuple: (numerator, denominator, is_normalised)
1648: """
+1649: cdef Py_ssize_t pos, decimal_len = 0
__pyx_v_decimal_len = 0; /* … */ __pyx_v_decimal_len = 0;
1650: cdef Py_UCS4 c
+1651: cdef ParserState state = BEGIN_SPACE
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE;
1652:
+1653: 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;
1654: cdef int digit
1655: cdef unsigned int udigit
+1656: 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;
1657: cdef ullong igcd
+1658: cdef object num = None, decimal, denom
__Pyx_INCREF(Py_None); __pyx_v_num = Py_None; /* … */ __Pyx_INCREF(Py_None); __pyx_v_num = Py_None;
1659: # 2^n > 10^(n * 5/17)
+1660: 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);
1661:
1662: # Incremental Unicode iteration isn't in Cython yet.
+1663: cdef int allow_unicode = AnyString is unicode
__pyx_v_allow_unicode = 1; /* … */ __pyx_v_allow_unicode = 0;
+1664: cdef int s_kind = 1
__pyx_v_s_kind = 1; /* … */ __pyx_v_s_kind = 1;
+1665: cdef void* s_data = NULL
__pyx_v_s_data = NULL; /* … */ __pyx_v_s_data = NULL;
+1666: cdef char* cdata = NULL
__pyx_v_cdata = NULL; /* … */ __pyx_v_cdata = NULL;
1667:
1668: if AnyString is unicode:
+1669: _unpack_ustring(s, &s_len, &s_data, &s_kind)
__pyx_t_1 = __QUICKTIONS_unpack_ustring(__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, 1669, __pyx_L1_error)
+1670: if s_kind == 1:
__pyx_t_2 = (__pyx_v_s_kind == 1); if (__pyx_t_2) { /* … */ }
+1671: 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, 1671, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0;
+1672: cdata = <char*> s_data
__pyx_v_cdata = ((char *)__pyx_v_s_data);
+1673: cdata += 0 # mark used
__pyx_v_cdata = (__pyx_v_cdata + 0);
1674: else:
+1675: cdata = s
__pyx_v_cdata = __pyx_v_s;
1676:
1677: # We collect the digits in inum / idenum as long as the value fits their integer size
1678: # and additionally in a char* buffer in case it grows too large.
+1679: 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, 1679, __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, 1679, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_digits = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1680: 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, 1680, __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, 1680, __pyx_L1_error) __pyx_v_c_digits_start = __pyx_t_2;
+1681: 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;
1682:
+1683: pos = 0
__pyx_v_pos = 0; /* … */ __pyx_v_pos = 0;
+1684: 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;
+1685: 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;
+1686: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1687: 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, 1687, __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, 1687, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1688: 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) { /* … */ }
+1689: if c == u'/':
switch (__pyx_v_c) { case 47: /* … */ break; case 46: /* … */ switch (__pyx_v_c) { case 47: /* … */ break; case 46:
+1690: 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:
+1691: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1691, __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, 1691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1692: elif state in (NUM, NUM_SPACE):
case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; default: /* … */ case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; default:
+1693: 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, 1693, __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, 1693, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1694: else:
+1695: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1695, __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, 1695, __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, 1695, __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; }
+1696: state = DENOM_START
__pyx_v_state = __pyx_e_10quicktions_DENOM_START; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_START;
+1697: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1698: elif c == u'.':
break; case 69: /* … */ break; case 69:
+1699: 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:
+1700: state = START_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
+1701: elif state == SMALL_NUM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1702: state = SMALL_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
+1703: elif state == NUM:
break; default: /* … */ break; default:
+1704: state = DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
1705: else:
+1706: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1706, __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, 1706, __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, 1706, __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; }
+1707: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1708: elif c in u'eE':
case 0x65: /* … */ break; case 43: /* … */ case 0x65: /* … */ break; case 43:
+1709: 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:
+1710: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1710, __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, 1710, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1711: elif state == NUM:
break; default: /* … */ break; default:
+1712: 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, 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_f_10quicktions__parse_pylong(__pyx_v_c_digits_start, (&__pyx_v_c_digits)); 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: else:
+1714: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1714, __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, 1714, __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, 1714, __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; }
+1715: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1716: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1717: elif c in u'-+':
case 45: /* … */ break; case 95: /* … */ case 45: /* … */ break; case 95:
+1718: 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; }
+1719: is_neg = c == u'-'
__pyx_v_is_neg = (__pyx_v_c == 45); /* … */ __pyx_v_is_neg = (__pyx_v_c == 45);
+1720: state = BEGIN_SIGN
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
1721: else:
+1722: _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, 1722, __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, 1722, __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, 1722, __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:;
+1723: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
+1724: elif c == u'_':
break; default: /* … */ break; default:
+1725: 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:
+1726: state = SMALL_NUM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
+1727: elif state == NUM:
break; default: /* … */ break; default:
+1728: state = NUM_US
__pyx_v_state = __pyx_e_10quicktions_NUM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_US;
1729: else:
+1730: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1730, __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, 1730, __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, 1730, __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; }
+1731: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
1732: else:
+1733: 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) { /* … */ }
+1734: 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;
+1735: 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]);
+1736: 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) { /* … */ }
+1737: break
goto __pyx_L10_break; /* … */ goto __pyx_L9_break;
+1738: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L10_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L9_break:;
1739:
+1740: 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:
+1741: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
+1742: elif state == SMALL_NUM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1743: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1743, __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, 1743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+1744: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
+1745: elif state == NUM:
break; default: /* … */ break; default:
+1746: 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, 1746, __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, 1746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+1747: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
1748: else:
+1749: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1749, __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, 1749, __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, 1749, __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; }
+1750: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
1751:
+1752: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1752, __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, 1752, __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, 1752, __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;
+1753: continue
goto __pyx_L4_continue; break; } /* … */ goto __pyx_L3_continue; break; }
1754:
1755: # normal digit found
+1756: 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:
+1757: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1758: state = SMALL_NUM
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
1759:
1760: # fast-path for consecutive digits
+1761: 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;
+1762: 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]);
+1763: 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, 1763, __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, 1763, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1764: 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) { /* … */ }
+1765: break
goto __pyx_L13_break; /* … */ goto __pyx_L12_break;
+1766: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1767: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L13_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L12_break:;
1768:
+1769: 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) { /* … */ }
+1770: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM;
+1771: elif state == NUM_US:
break; default: break; } /* … */ break; default: break; }
+1772: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM;
1773:
1774: # We might have switched to NUM above, so continue right here in that case.
+1775: 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:
1776: pass # handled above
+1777: elif state == NUM:
break; default: /* … */ break; default:
1778: # fast-path for consecutive digits
+1779: 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;
+1780: 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]);
+1781: 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, 1781, __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, 1781, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1782: 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) { /* … */ }
+1783: break
goto __pyx_L19_break; /* … */ goto __pyx_L18_break;
+1784: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L19_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L18_break:;
1785: else:
+1786: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1786, __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, 1786, __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, 1786, __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:;
1787:
+1788: 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:
1789: # NUM '/' | SMALL_NUM '/'
+1790: 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;
+1791: 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]);
+1792: 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) { /* … */ }
+1793: break
goto __pyx_L22_break; /* … */ goto __pyx_L21_break;
+1794: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L22_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L21_break:;
1795:
+1796: 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;
+1797: 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]);
+1798: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1799: 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, 1799, __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, 1799, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1800: 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) { /* … */ }
+1801: 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:
+1802: 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; }
+1803: 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));
+1804: state = DENOM_SIGN
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
1805: else:
+1806: _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, 1806, __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, 1806, __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, 1806, __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:;
+1807: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
+1808: elif c == u'_':
break; default: /* … */ break; default:
+1809: 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:
+1810: state = SMALL_DENOM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
+1811: elif state == DENOM:
break; default: /* … */ break; default:
+1812: state = DENOM_US
__pyx_v_state = __pyx_e_10quicktions_DENOM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_US;
1813: else:
+1814: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1814, __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, 1814, __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, 1814, __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; }
+1815: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
1816: else:
+1817: 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) { /* … */ }
+1818: 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;
+1819: 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]);
+1820: 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) { /* … */ }
+1821: break
goto __pyx_L30_break; /* … */ goto __pyx_L29_break;
+1822: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L30_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L29_break:;
1823:
+1824: 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:
1825: pass
+1826: elif state == SMALL_DENOM:
break; case __pyx_e_10quicktions_DENOM: /* … */ break; case __pyx_e_10quicktions_DENOM:
+1827: denom = idenom
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1827, __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, 1827, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
+1828: elif state == DENOM:
break; default: /* … */ break; default:
+1829: 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, 1829, __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, 1829, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
1830: else:
+1831: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1831, __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, 1831, __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, 1831, __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; }
+1832: state = DENOM_SPACE
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
+1833: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
1834:
+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; /* … */ __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;
+1836: continue
goto __pyx_L24_continue; break; } /* … */ goto __pyx_L23_continue; break; }
1837:
1838: # normal digit found
+1839: 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:
+1840: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit); /* … */ __pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+1841: state = SMALL_DENOM
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
1842:
1843: # fast-path for consecutive digits
+1844: 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;
+1845: 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]);
+1846: 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, 1846, __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, 1846, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1847: 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) { /* … */ }
+1848: break
goto __pyx_L33_break; /* … */ goto __pyx_L32_break;
+1849: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit); /* … */ __pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+1850: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L33_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L32_break:;
1851:
+1852: 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) { /* … */ }
+1853: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM;
+1854: elif state == DENOM_US:
break; default: break; } /* … */ break; default: break; }
+1855: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM;
1856:
1857: # We might have switched to DENOM above, so continue right here in that case.
+1858: 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:
1859: pass # handled above
+1860: elif state == DENOM:
break; default: /* … */ break; default:
1861: # fast-path for consecutive digits
+1862: 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;
+1863: 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]);
+1864: 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, 1864, __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, 1864, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1865: 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) { /* … */ }
+1866: break
goto __pyx_L39_break; /* … */ goto __pyx_L38_break;
+1867: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L39_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L38_break:;
1868: else:
+1869: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1869, __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, 1869, __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, 1869, __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:; }
1870:
+1871: 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; }
1872: # SMALL_NUM '.' | '.'
+1873: 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;
+1874: 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]);
+1875: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1876: 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, 1876, __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, 1876, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1877: 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) { /* … */ }
+1878: if c == u'_':
switch (__pyx_v_c) { case 95: /* … */ break; case 69: /* … */ switch (__pyx_v_c) { case 95: /* … */ break; case 69:
+1879: 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; }
+1880: state = SMALL_DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
1881: else:
+1882: _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, 1882, __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, 1882, __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, 1882, __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:;
+1883: continue
goto __pyx_L41_continue; /* … */ goto __pyx_L40_continue;
+1884: elif c in u'eE':
case 0x65: /* … */ break; default: /* … */ case 0x65: /* … */ break; default:
+1885: 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:
+1886: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1886, __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, 1886, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1887: else:
+1888: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1888, __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, 1888, __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, 1888, __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; }
+1889: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1890: break
goto __pyx_L42_break; /* … */ goto __pyx_L41_break;
1891: else:
+1892: 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) { /* … */ }
+1893: 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;
+1894: 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]);
+1895: 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) { /* … */ }
+1896: break
goto __pyx_L47_break; /* … */ goto __pyx_L46_break;
+1897: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L47_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L46_break:;
1898:
+1899: 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:
+1900: num = inum
__pyx_t_3 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1900, __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, 1900, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+1901: state = SMALL_END_SPACE
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
1902: else:
+1903: _raise_invalid_input(s)
__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; break; } /* … */ __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; break; }
+1904: continue
goto __pyx_L41_continue; /* … */ goto __pyx_L40_continue;
1905:
+1906: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1906, __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, 1906, __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, 1906, __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;
+1907: continue
goto __pyx_L41_continue; break; } /* … */ goto __pyx_L40_continue; break; }
1908:
1909: # normal digit found
+1910: 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:
+1911: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1912: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1913: state = SMALL_DECIMAL
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
1914:
1915: # fast-path for consecutive digits
+1916: 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;
+1917: 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]);
+1918: 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, 1918, __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, 1918, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1919: 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) { /* … */ }
+1920: break
goto __pyx_L50_break; /* … */ goto __pyx_L49_break;
+1921: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1922: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1923: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L50_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L49_break:;
1924:
+1925: 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) { /* … */ }
+1926: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL;
+1927: break
goto __pyx_L42_break; /* … */ goto __pyx_L41_break;
1928: else:
+1929: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1929, __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, 1929, __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, 1929, __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:;
1930:
+1931: 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; }
1932: # NUM '.' | SMALL_DECIMAL->DECIMAL
+1933: 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;
+1934: 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]);
+1935: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1936: 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, 1936, __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, 1936, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1937: 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) { /* … */ }
+1938: if c == u'_':
switch (__pyx_v_c) { case 95: /* … */ break; case 69: /* … */ switch (__pyx_v_c) { case 95: /* … */ break; case 69:
+1939: 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; }
+1940: state = DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
1941: else:
+1942: _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, 1942, __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, 1942, __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, 1942, __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:;
+1943: continue
goto __pyx_L58_continue; /* … */ goto __pyx_L57_continue;
+1944: elif c in u'eE':
case 0x65: /* … */ break; default: /* … */ case 0x65: /* … */ break; default:
+1945: 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:
+1946: 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, 1946, __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, 1946, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
1947: else:
+1948: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1948, __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, 1948, __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, 1948, __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; }
+1949: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1950: break
goto __pyx_L59_break; /* … */ goto __pyx_L58_break;
1951: else:
+1952: 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) { /* … */ }
+1953: 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:
+1954: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_END_SPACE;
1955: else:
+1956: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1956, __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, 1956, __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, 1956, __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; }
+1957: break
goto __pyx_L59_break; /* … */ goto __pyx_L58_break;
1958:
+1959: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1959, __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, 1959, __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, 1959, __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;
+1960: continue
goto __pyx_L58_continue; break; } /* … */ goto __pyx_L57_continue; break; }
1961:
1962: # normal digit found
+1963: 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:
+1964: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1965: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL;
1966:
1967: # fast-path for consecutive digits
+1968: 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;
+1969: 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]);
+1970: 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, 1970, __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, 1970, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1971: 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) { /* … */ }
+1972: break
goto __pyx_L64_break; /* … */ goto __pyx_L63_break;
+1973: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1974: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L64_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L63_break:;
1975: else:
+1976: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1976, __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, 1976, __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, 1976, __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:;
1977:
+1978: 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) { /* … */ }
1979: # (SMALL_) NUM ['.' DECIMAL] 'E'
+1980: 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;
+1981: 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]);
+1982: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1983: 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, 1983, __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, 1983, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1984: 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) { /* … */ }
+1985: 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:
+1986: 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; }
+1987: exp_is_neg = c == u'-'
__pyx_v_exp_is_neg = (__pyx_v_c == 45); /* … */ __pyx_v_exp_is_neg = (__pyx_v_c == 45);
+1988: state = EXP_SIGN
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
1989: else:
+1990: _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, 1990, __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, 1990, __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, 1990, __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:;
+1991: continue
goto __pyx_L67_continue; /* … */ goto __pyx_L66_continue;
+1992: elif c == u'_':
break; default: /* … */ break; default:
+1993: 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; }
+1994: state = EXP_US
__pyx_v_state = __pyx_e_10quicktions_EXP_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_US;
1995: else:
+1996: _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, 1996, __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, 1996, __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, 1996, __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:;
+1997: continue
goto __pyx_L67_continue; /* … */ goto __pyx_L66_continue;
1998: else:
+1999: 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) { /* … */ }
+2000: 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; }
+2001: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2002: else:
+2003: _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, 2003, __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, 2003, __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, 2003, __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:;
+2004: break
goto __pyx_L68_break; /* … */ goto __pyx_L67_break;
2005:
+2006: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2006, __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, 2006, __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, 2006, __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;
+2007: continue
goto __pyx_L67_continue; break; } /* … */ goto __pyx_L66_continue; break; }
2008:
2009: # normal digit found
+2010: 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:
+2011: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit); /* … */ __pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2012: state = EXP
__pyx_v_state = __pyx_e_10quicktions_EXP; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP;
2013:
2014: # fast-path for consecutive digits
+2015: 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;
+2016: 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]);
+2017: 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, 2017, __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, 2017, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2018: 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) { /* … */ }
+2019: break
goto __pyx_L75_break; /* … */ goto __pyx_L74_break;
+2020: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit); /* … */ __pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2021: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L75_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L74_break:;
2022:
+2023: 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) { /* … */ }
+2024: _raise_parse_overflow(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_parse_overflow(__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_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_parse_overflow(__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;
2025: else:
+2026: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2026, __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, 2026, __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, 2026, __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:;
2027:
+2028: 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; }
+2029: 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;
+2030: 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]);
+2031: 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) { /* … */ }
+2032: break
goto __pyx_L81_break; /* … */ goto __pyx_L80_break;
+2033: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L81_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L80_break:;
2034:
+2035: 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) { /* … */ }
+2036: _raise_invalid_input(s)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2036, __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, 2036, __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, 2036, __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;
2037:
+2038: is_normalised = False
__Pyx_INCREF(Py_False); __pyx_v_is_normalised = Py_False; /* … */ __Pyx_INCREF(Py_False); __pyx_v_is_normalised = Py_False;
+2039: 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:
2040: # Special case for 'small' numbers: normalise directly in C space.
+2041: 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; }
2042: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2043: 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; }
+2044: 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, 2044, __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, 2044, __pyx_L1_error) __pyx_v_idenom = __pyx_t_8;
+2045: 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, 2045, __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, 2045, __pyx_L1_error) __pyx_v_igcd = __pyx_t_9;
+2046: 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; }
+2047: inum //= igcd
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd); /* … */ __pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
+2048: 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, 2048, __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, 2048, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2049: else:
+2050: denom = pow10(decimal_len)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2050, __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, 2050, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L89:;
2051: else:
+2052: denom = pow10(decimal_len)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2052, __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, 2052, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L86:;
2053: else:
+2054: 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:;
+2055: if is_neg:
if (__pyx_v_is_neg) { /* … */ } /* … */ if (__pyx_v_is_neg) { /* … */ }
+2056: inum = -inum
__pyx_v_inum = (-__pyx_v_inum); /* … */ __pyx_v_inum = (-__pyx_v_inum);
+2057: 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, 2057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2057, __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, 2057, __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, 2057, __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, 2057, __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, 2057, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyTuple_New(3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 2057, __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, 2057, __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, 2057, __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, 2057, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = ((PyObject*)__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L0;
2058:
+2059: elif state == SMALL_DENOM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+2060: denom = idenom
__pyx_t_9 = __Pyx_PyInt_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2060, __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, 2060, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_6); __pyx_t_6 = 0;
+2061: 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:
+2062: 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);
+2063: 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);
+2064: 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, 2064, __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, 2064, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_6); __pyx_t_6 = 0;
+2065: elif state == DENOM:
break; case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; case __pyx_e_10quicktions_NUM_SPACE:
+2066: 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, 2066, __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, 2066, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_6); __pyx_t_6 = 0;
+2067: 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:
+2068: 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);
+2069: 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);
+2070: elif state == DENOM_SPACE:
break; default: /* … */ break; default:
2071: pass
2072: else:
+2073: _raise_invalid_input(s)
__pyx_t_9 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_s); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2073, __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, 2073, __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, 2073, __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; }
2074:
+2075: 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) { /* … */ }
+2076: _raise_parse_overflow(s)
__pyx_t_9 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_s); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2076, __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, 2076, __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, 2076, __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;
+2077: if exp_is_neg:
if (__pyx_v_exp_is_neg) { /* … */ } /* … */ if (__pyx_v_exp_is_neg) { /* … */ }
+2078: iexp = -iexp
__pyx_v_iexp = (-__pyx_v_iexp); /* … */ __pyx_v_iexp = (-__pyx_v_iexp);
+2079: iexp -= decimal_len
__pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len); /* … */ __pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len);
2080:
+2081: 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; }
+2082: num *= pow10(iexp)
__pyx_t_9 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2082, __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, 2082, __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, 2082, __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, 2082, __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;
+2083: 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:;
2084: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2085: 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, 2085, __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, 2085, __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, 2085, __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, 2085, __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, 2085, __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, 2085, __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;
+2086: denom = pow10(-iexp)
__pyx_t_3 = __pyx_f_10quicktions_pow10((-__pyx_v_iexp)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2086, __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, 2086, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2087:
+2088: if is_neg:
if (__pyx_v_is_neg) { /* … */ } /* … */ if (__pyx_v_is_neg) { /* … */ }
+2089: num = -num
__pyx_t_3 = PyNumber_Negative(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2089, __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, 2089, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2090:
+2091: return num, denom, is_normalised
__Pyx_XDECREF(__pyx_r); if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2091, __pyx_L1_error) } __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2091, __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, 2091, __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, 2091, __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, 2091, __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, 2091, __pyx_L1_error) } __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2091, __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, 2091, __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, 2091, __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, 2091, __pyx_L1_error); __pyx_r = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;