Generated by Cython 3.1.2
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=3
__pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Fraction_limit_denominator_line, __pyx_mstate_global->__pyx_kp_u_Closest_Fraction_to_self_with_de) < 0) __PYX_ERR(0, 1, __pyx_L1_error) if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0002: ## cython: profile=True
0003: # cython: freethreading_compatible=True
0004:
0005: # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
0006: # 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved
0007: #
0008: # Based on the "fractions" module in CPython 3.4+.
0009: # https://hg.python.org/cpython/file/b18288f24501/Lib/fractions.py
0010: #
0011: # Updated to match the recent development in CPython.
0012: # https://github.com/python/cpython/blob/main/Lib/fractions.py
0013: #
0014: # Adapted for efficient Cython compilation by Stefan Behnel.
0015: #
0016:
0017: """
0018: Fast fractions data type for rational numbers.
0019:
0020: This is an almost-drop-in replacement for the standard library's
0021: "fractions.Fraction".
0022: """
0023:
+0024: __all__ = ['Fraction']
__pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_Fraction_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 24, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_all, __pyx_t_2) < 0) __PYX_ERR(0, 24, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0025:
+0026: __version__ = '1.21'
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_version, __pyx_mstate_global->__pyx_kp_u_1_21) < 0) __PYX_ERR(0, 26, __pyx_L1_error)
0027:
0028: cimport cython
0029: from cpython.unicode cimport Py_UNICODE_TODECIMAL
0030: from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE
0031: from cpython.long cimport PyLong_FromString
0032:
0033: cdef extern from *:
0034: cdef long LONG_MAX, INT_MAX
0035: cdef long long PY_LLONG_MIN, PY_LLONG_MAX
0036: cdef long long MAX_SMALL_NUMBER "(PY_LLONG_MAX / 100)"
0037:
0038: cdef object Rational, Integral, Real, Complex, Decimal, math, operator, re
+0039: cdef object PY_MAX_LONG_LONG = PY_LLONG_MAX
__pyx_t_2 = __Pyx_PyLong_From_PY_LONG_LONG(PY_LLONG_MAX); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __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;
0040:
+0041: from numbers import Rational, Integral, Real, Complex
__pyx_t_2 = __Pyx_PyList_Pack(4, __pyx_mstate_global->__pyx_n_u_Rational, __pyx_mstate_global->__pyx_n_u_Integral, __pyx_mstate_global->__pyx_n_u_Real, __pyx_mstate_global->__pyx_n_u_Complex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_numbers, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 41, __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_mstate_global->__pyx_n_u_Rational); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __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_mstate_global->__pyx_n_u_Integral); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __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_mstate_global->__pyx_n_u_Real); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __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_mstate_global->__pyx_n_u_Complex); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 41, __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;
+0042: from decimal import Decimal
__pyx_t_3 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_Decimal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 42, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_decimal, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 42, __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_mstate_global->__pyx_n_u_Decimal); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 42, __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;
+0043: import math
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_math, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 43, __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;
+0044: import operator
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_operator, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 44, __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;
+0045: import re
__pyx_t_2 = __Pyx_ImportDottedModule(__pyx_mstate_global->__pyx_n_u_re, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 45, __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;
0046:
+0047: cdef object _operator_index = operator.index
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_index); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 47, __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;
+0048: cdef object math_gcd = math.gcd
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_math, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 48, __pyx_L1_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;
0049:
0050: # Cache widely used 10**x int objects.
0051: # Py3.12/Ubuntu64: sys.getsizeof(tuple[58]) == 512 bytes, tuple[91] == 768, tuple[123] == 1024
0052: DEF CACHED_POW10 = 91
0053:
+0054: 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; }
0055: cdef int i
+0056: in_ull = True
__pyx_v_in_ull = 1;
+0057: l = []
__pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_l = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+0058: x = 1
__Pyx_INCREF(__pyx_mstate_global->__pyx_int_1);
__pyx_v_x = __pyx_mstate_global->__pyx_int_1;
+0059: for i in range(CACHED_POW10):
for (__pyx_t_2 = 0; __pyx_t_2 < 91; __pyx_t_2+=1) { __pyx_v_i = __pyx_t_2;
+0060: 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, 60, __pyx_L1_error)
+0061: if in_ull:
if (__pyx_v_in_ull) { /* … */ }
+0062: 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:; }
+0063: _C_POW_10[i] = x
__pyx_t_7 = __Pyx_PyLong_As_unsigned_PY_LONG_LONG(__pyx_v_x); if (unlikely((__pyx_t_7 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L6_error) (__pyx_v_10quicktions__C_POW_10[__pyx_v_i]) = __pyx_t_7;
+0064: 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, 64, __pyx_L8_except_error) __Pyx_XGOTREF(__pyx_t_1); __Pyx_XGOTREF(__pyx_t_9); __Pyx_XGOTREF(__pyx_t_10);
+0065: 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;
+0066: x *= 10
__pyx_t_10 = __Pyx_PyLong_MultiplyObjC(__pyx_v_x, __pyx_mstate_global->__pyx_int_10, 10, 1, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 66, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF_SET(__pyx_v_x, __pyx_t_10); __pyx_t_10 = 0; }
+0067: return tuple(l)
__Pyx_XDECREF(__pyx_r); __pyx_t_10 = PyList_AsTuple(__pyx_v_l); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 67, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_r = ((PyObject*)__pyx_t_10); __pyx_t_10 = 0; goto __pyx_L0;
0068:
0069: cdef unsigned long long[CACHED_POW10] _C_POW_10
+0070: cdef tuple POW_10 = _cache_pow10()
__pyx_t_2 = __pyx_f_10quicktions__cache_pow10(); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __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;
0071:
0072:
+0073: 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; }
+0074: return _C_POW_10[i]
__pyx_r = (__pyx_v_10quicktions__C_POW_10[__pyx_v_i]); goto __pyx_L0;
0075:
0076:
+0077: 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; }
+0078: if 0 <= i < CACHED_POW10:
__pyx_t_1 = (0 <= __pyx_v_i); if (__pyx_t_1) { __pyx_t_1 = (__pyx_v_i < 91); } if (__pyx_t_1) { /* … */ }
+0079: 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, 79, __pyx_L1_error) } __pyx_t_2 = __Pyx_GetItemInt_Tuple(__pyx_v_10quicktions_POW_10, __pyx_v_i, PY_LONG_LONG, 1, __Pyx_PyLong_From_PY_LONG_LONG, 0, 1, 1, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 79, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0080: else:
+0081: return 10 ** (<object> i)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_i); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 81, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Power(__pyx_mstate_global->__pyx_int_10, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 81, __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; }
0082:
0083:
0084: # Half-private GCD implementation.
0085:
0086: cdef extern from *:
0087: """
0088: #if PY_VERSION_HEX >= 0x030c00a5 && defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
0089: #define __Quicktions_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) (x))
0090: #if CYTHON_COMPILING_IN_CPYTHON
0091: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) (((PyLongObject*)x)->long_value.ob_digit[0]))
0092: #else
0093: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) PyUnstable_Long_CompactValue((PyLongObject*) (x))))
0094: #endif
0095: #elif PY_VERSION_HEX < 0x030c0000 && CYTHON_COMPILING_IN_CPYTHON
0096: #define __Quicktions_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
0097: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) ((Py_SIZE(x) == 0) ? 0 : (((PyLongObject*)x)->ob_digit)[0]))
0098: #else
0099: #define __Quicktions_PyLong_IsCompact(x) (0)
0100: #define __Quicktions_PyLong_CompactValueUnsigned(x) (0U)
0101: #endif
0102: #if PY_VERSION_HEX < 0x030500F0 || PY_VERSION_HEX >= 0x030d0000 || !CYTHON_COMPILING_IN_CPYTHON
0103: #define _PyLong_GCD(a, b) (NULL)
0104: #endif
0105:
0106: #ifdef __has_builtin
0107: #if __has_builtin(__builtin_ctz) && __has_builtin(__builtin_ctzl) && __has_builtin(__builtin_ctzll)
0108: #define __Quicktions_HAS_FAST_CTZ 1
0109: #define __Quicktions_trailing_zeros_uint(x) __builtin_ctz(x)
0110: #define __Quicktions_trailing_zeros_ulong(x) __builtin_ctzl(x)
0111: #define __Quicktions_trailing_zeros_ullong(x) __builtin_ctzll(x)
0112: #elif __has_builtin(__builtin_ctzg)
0113: #define __Quicktions_HAS_FAST_CTZ 1
0114: #define __Quicktions_trailing_zeros_uint(x) __builtin_ctzg(x)
0115: #define __Quicktions_trailing_zeros_ulong(x) __builtin_ctzg(x)
0116: #define __Quicktions_trailing_zeros_ullong(x) __builtin_ctzg(x)
0117: #endif
0118: #elif defined(_MSC_VER) && defined(_WIN64) && SIZEOF_INT == 4 && SIZEOF_LONG_LONG == 8
0119: /* Typical Windows64 config (Win32 does not define "_BitScanForward64"). */
0120: #define __Quicktions_HAS_FAST_CTZ 1
0121: #pragma intrinsic(_BitScanForward, _BitScanForward64)
0122: static CYTHON_INLINE int __Quicktions_trailing_zeros_uint(uint32_t x) {
0123: unsigned long bits;
0124: _BitScanForward(&bits, x);
0125: return (int) bits;
0126: }
0127: static CYTHON_INLINE int __Quicktions_trailing_zeros_ullong(uint64_t x) {
0128: unsigned long bits;
0129: _BitScanForward64(&bits, x);
0130: return (int) bits;
0131: }
0132: #if SIZEOF_LONG == 4
0133: #define __Quicktions_trailing_zeros_ulong(x) __Quicktions_trailing_zeros_uint(x)
0134: #else
0135: #define __Quicktions_trailing_zeros_ulong(x) __Quicktions_trailing_zeros_ullong(x)
0136: #endif
0137: #endif
0138: #if !defined(__Quicktions_HAS_FAST_CTZ)
0139: #define __Quicktions_HAS_FAST_CTZ 0
0140: #define __Quicktions_trailing_zeros_uint(x) (0)
0141: #define __Quicktions_trailing_zeros_ulong(x) (0)
0142: #define __Quicktions_trailing_zeros_ullong(x) (0)
0143: #endif
0144: """
0145: bint PyLong_IsCompact "__Quicktions_PyLong_IsCompact" (x)
0146: Py_ssize_t PyLong_CompactValueUnsigned "__Quicktions_PyLong_CompactValueUnsigned" (x)
0147:
0148: # CPython 3.5-3.12 has a fast PyLong GCD implementation that we can use.
0149: # In CPython 3.13, math.gcd() is fast enough to call it directly.
0150: int PY_VERSION_HEX
0151: int HAS_PYLONG_GCD "(CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000)"
0152: _PyLong_GCD(a, b)
0153:
0154: bint HAS_FAST_CTZ "__Quicktions_HAS_FAST_CTZ"
0155: int trailing_zeros_uint "__Quicktions_trailing_zeros_uint" (unsigned int x)
0156: int trailing_zeros_ulong "__Quicktions_trailing_zeros_ulong" (unsigned long x)
0157: int trailing_zeros_ullong "__Quicktions_trailing_zeros_ullong" (unsigned long long x)
0158:
0159:
+0160: 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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_a,&__pyx_mstate_global->__pyx_n_u_b,0}; PyObject* values[2] = {0,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 160, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 2: values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 160, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 160, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "_gcd", 0) < 0) __PYX_ERR(0, 160, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 2; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("_gcd", 1, 2, 2, i); __PYX_ERR(0, 160, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 2)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 160, __pyx_L3_error) values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 160, __pyx_L3_error) } __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, 160, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 160, __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_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_1_gcd, 0, __pyx_mstate_global->__pyx_n_u_gcd_2, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[0])); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_gcd_2, __pyx_t_2) < 0) __PYX_ERR(0, 160, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0161: """Calculate the Greatest Common Divisor of a and b as a non-negative number.
0162: """
+0163: 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) { /* … */ }
+0164: 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, 164, __pyx_L1_error) __pyx_t_4 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 164, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0165: if PY_VERSION_HEX >= 0x030d0000:
__pyx_t_1 = (PY_VERSION_HEX >= 0x030d0000); if (__pyx_t_1) { /* … */ }
+0166: return math_gcd(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = NULL; __Pyx_INCREF(__pyx_v_10quicktions_math_gcd); __pyx_t_6 = __pyx_v_10quicktions_math_gcd; __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_5); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_5); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_v_a, __pyx_v_b}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0167: if not HAS_PYLONG_GCD:
__pyx_t_1 = (!((CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000) != 0)); if (__pyx_t_1) { /* … */ }
+0168: 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, 168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0169: 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, 169, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0170:
0171:
+0172: ctypedef unsigned long long ullong
typedef unsigned PY_LONG_LONG __pyx_t_10quicktions_ullong;
+0173: ctypedef unsigned long ulong
typedef unsigned long __pyx_t_10quicktions_ulong;
0174: ctypedef unsigned int uint
0175:
0176: ctypedef fused cunumber:
0177: ullong
0178: ulong
0179: uint
0180:
0181:
+0182: 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; }
+0183: if x == PY_LLONG_MIN:
__pyx_t_1 = (__pyx_v_x == PY_LLONG_MIN); if (__pyx_t_1) { /* … */ }
+0184: return (<ullong>PY_LLONG_MAX) + 1
__pyx_r = (((__pyx_t_10quicktions_ullong)PY_LLONG_MAX) + 1); goto __pyx_L0;
+0185: return abs(x)
__pyx_t_2 = __Pyx_abs_longlong(__pyx_v_x); __pyx_r = __pyx_t_2; goto __pyx_L0;
0186:
0187:
+0188: 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; }
0189: """Euclid's GCD algorithm"""
+0190: if HAS_FAST_CTZ:
if (__Quicktions_HAS_FAST_CTZ) { /* … */ } /* … */ if (__Quicktions_HAS_FAST_CTZ) { /* … */ } /* … */ if (__Quicktions_HAS_FAST_CTZ) { /* … */ }
+0191: 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, 191, __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, 191, __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, 191, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0;
0192: else:
+0193: 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, 193, __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, 193, __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, 193, __pyx_L1_error) __pyx_r = __pyx_t_1; goto __pyx_L0; }
0194:
0195:
+0196: 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; }
0197: """Euclid's GCD algorithm"""
+0198: 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;
+0199: 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, 199, __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, 199, __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, 199, __pyx_L1_error) } __pyx_t_3 = (__pyx_v_a % __pyx_v_b); __pyx_v_a = __pyx_t_2; __pyx_v_b = __pyx_t_3; }
+0200: 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;
0201:
0202:
+0203: 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; }
0204: if cunumber is uint:
+0205: return trailing_zeros_uint(x)
__pyx_r = __Quicktions_trailing_zeros_uint(__pyx_v_x); goto __pyx_L0;
0206: elif cunumber is ulong:
+0207: return trailing_zeros_ulong(x)
__pyx_r = __Quicktions_trailing_zeros_ulong(__pyx_v_x); goto __pyx_L0;
0208: else:
+0209: return trailing_zeros_ullong(x)
__pyx_r = __Quicktions_trailing_zeros_ullong(__pyx_v_x); goto __pyx_L0;
0210:
0211:
+0212: 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; }
0213: # See https://en.wikipedia.org/wiki/Binary_GCD_algorithm
+0214: 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) { /* … */ }
+0215: 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;
+0216: 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) { /* … */ }
+0217: 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;
0218:
+0219: 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, 219, __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, 219, __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, 219, __pyx_L1_error) __pyx_v_i = __pyx_t_2;
+0220: 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);
+0221: 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, 221, __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, 221, __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, 221, __pyx_L1_error) __pyx_v_j = __pyx_t_2;
+0222: 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);
0223:
+0224: 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;
0225:
+0226: while True:
while (1) { /* … */ while (1) { /* … */ while (1) {
+0227: 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) { /* … */ }
+0228: 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;
+0229: 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);
+0230: 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) { /* … */ }
+0231: 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;
+0232: 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, 232, __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, 232, __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, 232, __pyx_L1_error) __pyx_v_b = (__pyx_v_b >> __pyx_t_4); }
0233:
0234:
+0235: 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; }
+0236: 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) { /* … */ }
+0237: 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, 237, __pyx_L1_error) __pyx_t_4 = __Pyx_PyLong_From_int(((int)__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 237, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0238: 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) { /* … */ }
+0239: 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, 239, __pyx_L1_error) __pyx_t_4 = __Pyx_PyLong_From_long(((long)__pyx_t_5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 239, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+0240: elif b:
__pyx_t_1 = (__pyx_v_b != 0); if (__pyx_t_1) { /* … */ }
+0241: 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, 241, __pyx_L1_error)
__pyx_v_a = __pyx_t_6;
+0242: return a
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 242, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0243:
0244:
+0245: 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;
}
+0246: 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) { /* … */ }
+0247: 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, 247, __pyx_L1_error)
__pyx_r = __pyx_t_3;
goto __pyx_L0;
+0248: 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) { /* … */ }
+0249: 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, 249, __pyx_L1_error)
__pyx_r = __pyx_t_4;
goto __pyx_L0;
0250: else:
+0251: 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, 251, __pyx_L1_error)
__pyx_r = __pyx_t_5;
goto __pyx_L0;
}
0252:
0253:
+0254: 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; }
0255: """Fallback GCD implementation if _PyLong_GCD() is not available.
0256: """
0257: # Try doing the computation in C space. If the numbers are too
0258: # large at the beginning, do object calculations until they are small enough.
0259: cdef ullong au, bu
0260: cdef long long ai, bi
0261:
0262: # Optimistically try to switch to C space.
+0263: 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); }
+0264: ai, bi = a, b
__pyx_t_4 = __Pyx_PyLong_As_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_4 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L3_error) __pyx_t_5 = __Pyx_PyLong_As_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_5 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 264, __pyx_L3_error) __pyx_v_ai = __pyx_t_4; __pyx_v_bi = __pyx_t_5;
+0265: 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;
0266: pass
0267: else:
+0268: 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, 268, __pyx_L5_except_error) __pyx_v_au = __pyx_t_6;
+0269: 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, 269, __pyx_L5_except_error) __pyx_v_bu = __pyx_t_6;
+0270: 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, 270, __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:;
0271:
0272: # Do object calculation until we reach the C space limit.
+0273: a = abs(a)
__pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_v_a); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_a, __pyx_t_7); __pyx_t_7 = 0;
+0274: b = abs(b)
__pyx_t_7 = __Pyx_PyNumber_Absolute(__pyx_v_b); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 274, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_7); __pyx_t_7 = 0;
+0275: 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, 275, __pyx_L1_error) __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 275, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (!__pyx_t_9) break;
+0276: 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, 276, __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; }
+0277: 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, 277, __pyx_L1_error) if (__pyx_t_11) { } else { __pyx_t_9 = __pyx_t_11; goto __pyx_L15_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, 277, __pyx_L1_error) __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_11 < 0))) __PYX_ERR(0, 277, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_9 = __pyx_t_11; __pyx_L15_bool_binop_done:; if (!__pyx_t_9) break;
+0278: 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, 278, __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; }
+0279: if not b:
__pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_b); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 279, __pyx_L1_error) __pyx_t_11 = (!__pyx_t_9); if (__pyx_t_11) { /* … */ }
+0280: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_a); __pyx_r = __pyx_v_a; goto __pyx_L0;
+0281: return _py_gcd(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = __Pyx_PyLong_As_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_6 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 281, __pyx_L1_error) __pyx_t_12 = __Pyx_PyLong_As_unsigned_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_12 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 281, __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, 281, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
0282:
0283:
0284: # Constants related to the hash implementation; hash(x) is based
0285: # on the reduction of x modulo the prime _PyHASH_MODULUS.
0286:
+0287: from sys import hash_info
__pyx_t_2 = __Pyx_PyList_Pack(1, __pyx_mstate_global->__pyx_n_u_hash_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_sys, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 287, __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_mstate_global->__pyx_n_u_hash_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_hash_info, __pyx_t_2) < 0) __PYX_ERR(0, 287, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0288:
+0289: cdef Py_hash_t _PyHASH_MODULUS = hash_info.modulus
__Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_hash_info); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 289, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_modulus); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 289, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_4 = __Pyx_PyLong_AsHash_t(__pyx_t_2); if (unlikely((__pyx_t_4 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 289, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_10quicktions__PyHASH_MODULUS = __pyx_t_4;
0290:
0291: # Value to be used for rationals that reduce to infinity modulo
0292: # _PyHASH_MODULUS.
+0293: cdef Py_hash_t _PyHASH_INF = hash_info.inf
__Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_hash_info); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_inf); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = __Pyx_PyLong_AsHash_t(__pyx_t_3); if (unlikely((__pyx_t_4 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 293, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_10quicktions__PyHASH_INF = __pyx_t_4;
0294:
+0295: del hash_info
if (__Pyx_PyObject_DelAttrStr(__pyx_m, __pyx_mstate_global->__pyx_n_u_hash_info) < 0) __PYX_ERR(0, 295, __pyx_L1_error)
0296:
0297:
0298: # Helpers for formatting
0299:
+0300: 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; };
0301: """Round a rational number to the nearest multiple of a given power of 10.
0302:
0303: Rounds the rational number n/d to the nearest integer multiple of
0304: 10**exponent, rounding to the nearest even integer multiple in the case of
0305: a tie. Returns a pair (sign: bool, significand: int) representing the
0306: rounded value (-1)**sign * significand * 10**exponent.
0307:
0308: If no_neg_zero is true, then the returned sign will always be False when
0309: the significand is zero. Otherwise, the sign reflects the sign of the
0310: input.
0311:
0312: d must be positive, but n and d need not be relatively prime.
0313: """
+0314: if exponent >= 0:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_exponent, __pyx_mstate_global->__pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 314, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 314, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0315: d *= 10**exponent
__pyx_t_1 = PyNumber_Power(__pyx_mstate_global->__pyx_int_10, __pyx_v_exponent, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 315, __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, 315, __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;
0316: else:
+0317: n *= 10**-exponent
/*else*/ { __pyx_t_3 = PyNumber_Negative(__pyx_v_exponent); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 317, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = PyNumber_Power(__pyx_mstate_global->__pyx_int_10, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 317, __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, 317, __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:;
0318:
0319: # The divmod quotient is correct for round-ties-towards-positive-infinity;
0320: # In the case of a tie, we zero out the least significant bit of q.
+0321: q, r = divmod(n + (d >> 1), d)
__pyx_t_3 = __Pyx_PyLong_RshiftObjC(__pyx_v_d, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 321, __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, 321, __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, 321, __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, 321, __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_INCREF(__pyx_t_1); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 321, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 321, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 321, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 321, __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, 321, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 321, __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, 321, __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;
+0322: if r == 0 and d & 1 == 0:
__pyx_t_7 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_r, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 322, __pyx_L1_error) if (__pyx_t_7) { } else { __pyx_t_2 = __pyx_t_7; goto __pyx_L7_bool_binop_done; } __pyx_t_3 = __Pyx_PyLong_AndObjC(__pyx_v_d, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 322, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = (__Pyx_PyLong_BoolEqObjC(__pyx_t_3, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 322, __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) { /* … */ }
+0323: q &= -2
__pyx_t_3 = __Pyx_PyLong_AndObjC(__pyx_v_q, __pyx_mstate_global->__pyx_int_neg_2, -2L, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 323, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_q, __pyx_t_3); __pyx_t_3 = 0;
0324:
+0325: 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_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 325, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 325, __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_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 325, __pyx_L1_error) __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 325, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_2 = __pyx_t_7; } __pyx_v_sign = __pyx_t_2;
+0326: 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, 326, __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, 326, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 326, __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) != (0)) __PYX_ERR(0, 326, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4) != (0)) __PYX_ERR(0, 326, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0327:
0328:
+0329: 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; }
0330: """Round a rational number to a given number of significant figures.
0331:
0332: Rounds the rational number n/d to the given number of significant figures
0333: using the round-ties-to-even rule, and returns a triple
0334: (sign: bool, significand: int, exponent: int) representing the rounded
0335: value (-1)**sign * significand * 10**exponent.
0336:
0337: In the special case where n = 0, returns a significand of zero and
0338: an exponent of 1 - figures, for compatibility with formatting.
0339: Otherwise, the returned significand satisfies
0340: 10**(figures - 1) <= significand < 10**figures.
0341:
0342: d must be positive, but n and d need not be relatively prime.
0343: figures must be positive.
0344: """
0345: # Special case for n == 0.
+0346: if n == 0:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_n, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 346, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0347: return False, 0, 1 - figures
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyLong_FromSsize_t((1 - __pyx_v_figures)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 347, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 347, __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) != (0)) __PYX_ERR(0, 347, __pyx_L1_error); __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_0); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_mstate_global->__pyx_int_0) != (0)) __PYX_ERR(0, 347, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2) != (0)) __PYX_ERR(0, 347, __pyx_L1_error); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0348:
0349: cdef bint sign
0350:
0351: # Find integer m satisfying 10**(m - 1) <= abs(n)/d <= 10**m. (If abs(n)/d
0352: # is a power of 10, either of the two possible values for m is fine.)
+0353: 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, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_Unicode(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_Unicode(__pyx_v_d); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_v_str_n = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0; __pyx_v_str_d = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0;
+0354: cdef Py_ssize_t m = len(str_n) - len(str_d) + (str_d <= str_n)
__pyx_t_4 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str_n); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 354, __pyx_L1_error) __pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_str_d); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 354, __pyx_L1_error) __pyx_t_3 = PyLong_FromSsize_t((__pyx_t_4 - __pyx_t_5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 354, __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, 354, __pyx_L1_error) __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 354, __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, 354, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_m = __pyx_t_5;
0355:
0356: # Round to a multiple of 10**(m - figures). The significand we get
0357: # satisfies 10**(figures - 1) <= significand <= 10**figures.
+0358: exponent = m - figures
__pyx_t_6 = PyLong_FromSsize_t((__pyx_v_m - __pyx_v_figures)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_v_exponent = __pyx_t_6; __pyx_t_6 = 0;
+0359: 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, 359, __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, 359, __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_INCREF(__pyx_t_2); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 359, __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, 359, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 359, __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, 359, __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, 359, __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;
0360:
0361: # Adjust in the case where significand == 10**figures, to ensure that
0362: # 10**(figures - 1) <= significand < 10**figures.
+0363: if len(str(significand)) == figures + 1:
__pyx_t_6 = __Pyx_PyObject_Unicode(__pyx_v_significand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 363, __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) { /* … */ }
+0364: significand //= 10
__pyx_t_6 = __Pyx_PyLong_FloorDivideObjC(__pyx_v_significand, __pyx_mstate_global->__pyx_int_10, 10, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 364, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_significand, __pyx_t_6); __pyx_t_6 = 0;
+0365: exponent += 1
__pyx_t_6 = __Pyx_PyLong_AddObjC(__pyx_v_exponent, __pyx_mstate_global->__pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 365, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_exponent, __pyx_t_6); __pyx_t_6 = 0;
0366:
+0367: 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, 367, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 367, __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) != (0)) __PYX_ERR(0, 367, __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) != (0)) __PYX_ERR(0, 367, __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) != (0)) __PYX_ERR(0, 367, __pyx_L1_error); __pyx_t_6 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0368:
0369:
0370: # Pattern for matching non-float-style format specifications.
+0371: cdef object _GENERAL_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
__pyx_t_2 = __pyx_v_10quicktions_re;
__Pyx_INCREF(__pyx_t_2);
0372: (?:
0373: (?P<fill>.)?
0374: (?P<align>[<>=^])
0375: )?
0376: (?P<sign>[-+ ]?)
0377: # Alt flag forces a slash and denominator in the output, even for
0378: # integer-valued Fraction objects.
0379: (?P<alt>\#)?
0380: # We don't implement the zeropad flag since there's no single obvious way
0381: # to interpret it.
0382: (?P<minimumwidth>0|[1-9][0-9]*)?
0383: (?P<thousands_sep>[,_])?
0384: $
+0385: """, re.DOTALL | re.VERBOSE).match
__pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_DOTALL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_VERBOSE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = PyNumber_Or(__pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_8 = 0; { PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_P_fill_P_align_P_sign_Alt_flag, __pyx_t_7}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_compile, __pyx_callargs+__pyx_t_8, (3-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 371, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_match); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER); __Pyx_DECREF_SET(__pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = 0;
0386:
0387:
0388: # Pattern for matching float-style format specifications;
0389: # supports 'e', 'E', 'f', 'F', 'g', 'G' and '%' presentation types.
+0390: cdef object _FLOAT_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
__pyx_t_3 = __pyx_v_10quicktions_re;
__Pyx_INCREF(__pyx_t_3);
0391: (?:
0392: (?P<fill>.)?
0393: (?P<align>[<>=^])
0394: )?
0395: (?P<sign>[-+ ]?)
0396: (?P<no_neg_zero>z)?
0397: (?P<alt>\#)?
0398: # A '0' that's *not* followed by another digit is parsed as a minimum width
0399: # rather than a zeropad flag.
0400: (?P<zeropad>0(?=[0-9]))?
0401: (?P<minimumwidth>[0-9]+)?
0402: (?P<thousands_sep>[,_])?
0403: (?:\.(?P<precision>[0-9]+))?
0404: (?P<presentation_type>[eEfFgG%])
0405: $
+0406: """, re.DOTALL | re.VERBOSE).match
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_DOTALL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_VERBOSE); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_5 = PyNumber_Or(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_8 = 0; { PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_P_fill_P_align_P_sign_P_no_neg, __pyx_t_5}; __pyx_t_7 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_compile, __pyx_callargs+__pyx_t_8, (3-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 390, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); } __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_match); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER); __Pyx_DECREF_SET(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0;
0407:
+0408: cdef object NOINIT = object()
__pyx_t_7 = NULL; __Pyx_INCREF(__pyx_builtin_object); __pyx_t_3 = __pyx_builtin_object; __pyx_t_8 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_7, NULL}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_8, (1-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 408, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __Pyx_XGOTREF(__pyx_v_10quicktions_NOINIT); __Pyx_DECREF_SET(__pyx_v_10quicktions_NOINIT, __pyx_t_5); __Pyx_GIVEREF(__pyx_t_5); __pyx_t_5 = 0;
0409:
0410:
+0411: 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;
0412: """A Rational number.
0413:
0414: Takes a string like '3/2' or '1.5', another Rational instance, a
0415: numerator/denominator pair, or a float.
0416:
0417: Examples
0418: --------
0419:
0420: >>> Fraction(10, -8)
0421: Fraction(-5, 4)
0422: >>> Fraction(Fraction(1, 7), 5)
0423: Fraction(1, 35)
0424: >>> Fraction(Fraction(1, 7), Fraction(2, 3))
0425: Fraction(3, 14)
0426: >>> Fraction('314')
0427: Fraction(314, 1)
0428: >>> Fraction('-35/4')
0429: Fraction(-35, 4)
0430: >>> Fraction('3.1415') # conversion from numeric string
0431: Fraction(6283, 2000)
0432: >>> Fraction('-47e-2') # string may include a decimal exponent
0433: Fraction(-47, 100)
0434: >>> Fraction(1.47) # direct construction from float (exact conversion)
0435: Fraction(6620291452234629, 4503599627370496)
0436: >>> Fraction(2.25)
0437: Fraction(9, 4)
0438: >>> from decimal import Decimal
0439: >>> Fraction(Decimal('1.47'))
0440: Fraction(147, 100)
0441:
0442: """
0443: cdef _numerator
0444: cdef _denominator
0445: cdef Py_hash_t _hash
0446:
+0447: 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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_numerator,&__pyx_mstate_global->__pyx_n_u_denominator,0}; PyObject* values[2] = {0,0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_VARARGS(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 447, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 2: values[1] = __Pyx_ArgRef_VARARGS(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 447, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 447, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__cinit__", 0) < 0) __PYX_ERR(0, 447, __pyx_L3_error) if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)__pyx_mstate_global->__pyx_int_0)); if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)Py_None)); } else { switch (__pyx_nargs) { case 2: values[1] = __Pyx_ArgRef_VARARGS(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 447, __pyx_L3_error) CYTHON_FALLTHROUGH; case 1: values[0] = __Pyx_ArgRef_VARARGS(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 447, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)__pyx_mstate_global->__pyx_int_0)); if (!values[1]) values[1] = __Pyx_NewRef(((PyObject *)Py_None)); } __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, 447, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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_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_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_12); __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_g); __Pyx_XDECREF(__pyx_v_numerator); __Pyx_XDECREF(__pyx_v_denominator); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+0448: self._hash = -1
__pyx_v_self->_hash = -1L;
+0449: if numerator is NOINIT:
__pyx_t_1 = (__pyx_v_numerator == __pyx_v_10quicktions_NOINIT); if (__pyx_t_1) { /* … */ }
+0450: return # fast-path for external initialisation
__pyx_r = 0; goto __pyx_L0;
0451:
+0452: cdef bint _normalize = True
__pyx_v__normalize = 1;
+0453: if denominator is None:
__pyx_t_1 = (__pyx_v_denominator == Py_None); if (__pyx_t_1) { /* … */ goto __pyx_L4; }
+0454: if type(numerator) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyLong_Type))); if (__pyx_t_1) { /* … */ }
+0455: 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;
+0456: self._denominator = 1
__Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_int_1); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_mstate_global->__pyx_int_1;
+0457: return
__pyx_r = 0; goto __pyx_L0;
0458:
+0459: elif type(numerator) is float:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyFloat_Type))); if (__pyx_t_1) { /* … */ }
0460: # Exact conversion
+0461: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_3 = __pyx_v_numerator; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } 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, 461, __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_INCREF(__pyx_t_3); __pyx_t_5 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_5); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_5); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); #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, 461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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_5 = __pyx_t_7(__pyx_t_6); if (unlikely(!__pyx_t_5)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_5); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_6), 2) < 0) __PYX_ERR(0, 461, __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, 461, __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_5); __Pyx_GOTREF(__pyx_v_self->_denominator); __Pyx_DECREF(__pyx_v_self->_denominator); __pyx_v_self->_denominator = __pyx_t_5; __pyx_t_5 = 0;
+0462: return
__pyx_r = 0; goto __pyx_L0;
0463:
+0464: elif type(numerator) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0465: 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;
+0466: 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;
+0467: return
__pyx_r = 0; goto __pyx_L0;
0468:
+0469: elif isinstance(numerator, unicode):
__pyx_t_1 = PyUnicode_Check(__pyx_v_numerator);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+0470: numerator, denominator, is_normalised = _parse_fraction[unicode](
__pyx_t_2 = __pyx_fuse_0__pyx_f_10quicktions__parse_fraction(((PyObject*)__pyx_v_numerator), __pyx_t_8, __pyx_v_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 470, __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_PyTuple_GET_SIZE(sequence); if (unlikely(size != 3)) { if (size > 3) __Pyx_RaiseTooManyValuesError(3); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 470, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __pyx_t_5 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 2); __Pyx_INCREF(__pyx_t_6); #else __pyx_t_5 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 470, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 470, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 470, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 470, __pyx_L1_error) } __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 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;
+0471: <unicode>numerator, len(<unicode>numerator), numerator)
if (unlikely(__pyx_v_numerator == Py_None)) { PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); __PYX_ERR(0, 471, __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, 471, __pyx_L1_error)
+0472: if is_normalised:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_is_normalised); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 472, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0473: _normalize = False
__pyx_v__normalize = 0;
0474: # fall through to normalisation below
0475:
+0476: 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) {
/* … */
}
+0477: 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_mstate_global->__pyx_n_u_as_integer_ratio); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 477, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_L9_bool_binop_done:;
0478: # Exact conversion
+0479: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_6 = __pyx_v_numerator; __Pyx_INCREF(__pyx_t_6); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } 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, 479, __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_INCREF(__pyx_t_6); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_6 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_6); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 479, __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_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 479, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_6 = __pyx_t_7(__pyx_t_5); 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_5); if (unlikely(!__pyx_t_3)) goto __pyx_L12_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_5), 2) < 0) __PYX_ERR(0, 479, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L13_unpacking_done; __pyx_L12_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 479, __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;
+0480: return
__pyx_r = 0; goto __pyx_L0;
0481:
+0482: 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_mstate_global->__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) { /* … */ }
+0483: self._numerator = numerator.numerator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 483, __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;
+0484: self._denominator = numerator.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 484, __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;
+0485: return
__pyx_r = 0; goto __pyx_L0;
0486:
+0487: 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, 487, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (likely(__pyx_t_1)) { /* … */ }
+0488: self._numerator, self._denominator = numerator.as_integer_ratio()
__pyx_t_3 = __pyx_v_numerator; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } 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, 488, __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_INCREF(__pyx_t_3); __pyx_t_6 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_6); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_6); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 488, __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_5 = PyObject_GetIter(__pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_7 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); index = 0; __pyx_t_3 = __pyx_t_7(__pyx_t_5); if (unlikely(!__pyx_t_3)) goto __pyx_L16_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); index = 1; __pyx_t_6 = __pyx_t_7(__pyx_t_5); if (unlikely(!__pyx_t_6)) goto __pyx_L16_unpacking_failed; __Pyx_GOTREF(__pyx_t_6); if (__Pyx_IternextUnpackEndCheck(__pyx_t_7(__pyx_t_5), 2) < 0) __PYX_ERR(0, 488, __pyx_L1_error) __pyx_t_7 = NULL; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; goto __pyx_L17_unpacking_done; __pyx_L16_unpacking_failed:; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 488, __pyx_L1_error) __pyx_L17_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;
+0489: return
__pyx_r = 0; goto __pyx_L0;
0490:
0491: else:
+0492: raise TypeError("argument should be a string or a Rational "
/*else*/ { __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_builtin_TypeError); __pyx_t_3 = __pyx_builtin_TypeError; __pyx_t_4 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_mstate_global->__pyx_kp_u_argument_should_be_a_string_or_a}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 492, __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, 492, __pyx_L1_error) } __pyx_L5:;
0493: "instance or have the as_integer_ratio() method")
0494:
+0495: elif type(numerator) is int is type(denominator):
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyLong_Type))); if (__pyx_t_1) { __pyx_t_1 = ((&PyLong_Type) == ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_denominator)))); } if (__pyx_t_1) { goto __pyx_L4; }
0496: pass # *very* normal case
0497:
+0498: elif type(numerator) is Fraction is type(denominator):
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { __pyx_t_1 = (__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction == ((PyTypeObject*)((PyObject *)Py_TYPE(__pyx_v_denominator)))); } if (__pyx_t_1) { /* … */ goto __pyx_L4; }
0499: numerator, denominator = (
+0500: (<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, 500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+0501: (<Fraction>denominator)._numerator * (<Fraction>numerator)._denominator
__pyx_t_3 = PyNumber_Multiply(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_denominator)->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_numerator)->_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 501, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_3); __pyx_t_3 = 0;
0502: )
0503:
+0504: elif (isinstance(numerator, (Fraction, Rational)) and
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_3 = __pyx_v_10quicktions_Rational; __pyx_t_9 = __Pyx_TypeCheck(__pyx_v_numerator, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); if (!__pyx_t_9) { } else { __pyx_t_10 = __pyx_t_9; goto __pyx_L20_bool_binop_done; } __pyx_t_9 = PyObject_IsInstance(__pyx_v_numerator, __pyx_t_3); __pyx_t_10 = __pyx_t_9; __pyx_L20_bool_binop_done:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_10) { } else { __pyx_t_1 = __pyx_t_10; goto __pyx_L18_bool_binop_done; } /* … */ if (likely(__pyx_t_1)) { /* … */ goto __pyx_L4; }
+0505: isinstance(denominator, (Fraction, Rational))):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_3 = __pyx_v_10quicktions_Rational; __pyx_t_9 = __Pyx_TypeCheck(__pyx_v_denominator, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); if (!__pyx_t_9) { } else { __pyx_t_10 = __pyx_t_9; goto __pyx_L22_bool_binop_done; } __pyx_t_9 = PyObject_IsInstance(__pyx_v_denominator, __pyx_t_3); __pyx_t_10 = __pyx_t_9; __pyx_L22_bool_binop_done:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_1 = __pyx_t_10; __pyx_L18_bool_binop_done:;
0506: numerator, denominator = (
+0507: numerator.numerator * denominator.denominator,
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 507, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_denominator, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 507, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyNumber_Multiply(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 507, __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;
+0508: denominator.numerator * numerator.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_denominator, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_numerator, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 508, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = PyNumber_Multiply(__pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 508, __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_SET(__pyx_v_numerator, __pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
0509: )
0510:
0511: else:
+0512: raise TypeError("both arguments should be "
/*else*/ { __pyx_t_6 = NULL; __Pyx_INCREF(__pyx_builtin_TypeError); __pyx_t_3 = __pyx_builtin_TypeError; __pyx_t_4 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_mstate_global->__pyx_kp_u_both_arguments_should_be_Rationa}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 512, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 512, __pyx_L1_error) } __pyx_L4:;
0513: "Rational instances")
0514:
+0515: if denominator == 0:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_denominator, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 515, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+0516: raise ZeroDivisionError(f'Fraction({numerator}, 0)')
__pyx_t_3 = NULL; __Pyx_INCREF(__pyx_builtin_ZeroDivisionError); __pyx_t_6 = __pyx_builtin_ZeroDivisionError; __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_numerator, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 516, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_11[0] = __pyx_mstate_global->__pyx_kp_u_Fraction; __pyx_t_11[1] = __pyx_t_2; __pyx_t_11[2] = __pyx_mstate_global->__pyx_kp_u_0; __pyx_t_12 = __Pyx_PyUnicode_Join(__pyx_t_11, 3, 9 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 4, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2)); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 516, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_4 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_12}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 516, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 516, __pyx_L1_error)
+0517: if _normalize:
if (__pyx_v__normalize) { /* … */ }
+0518: if not isinstance(numerator, int):
__pyx_t_1 = PyLong_Check(__pyx_v_numerator);
__pyx_t_10 = (!__pyx_t_1);
if (__pyx_t_10) {
/* … */
}
+0519: numerator = int(numerator)
__pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 519, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0;
+0520: if not isinstance(denominator, int):
__pyx_t_10 = PyLong_Check(__pyx_v_denominator);
__pyx_t_1 = (!__pyx_t_10);
if (__pyx_t_1) {
/* … */
}
+0521: denominator = int(denominator)
__pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 521, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
+0522: g = _gcd(numerator, denominator)
__pyx_t_5 = __pyx_f_10quicktions__gcd(__pyx_v_numerator, __pyx_v_denominator, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 522, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_v_g = __pyx_t_5; __pyx_t_5 = 0;
0523: # NOTE: 'is' tests on integers are generally a bad idea, but
0524: # they are fast and if they fail here, it'll still be correct
+0525: if denominator < 0:
__pyx_t_5 = PyObject_RichCompare(__pyx_v_denominator, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 525, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 525, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+0526: if g is 1:
__pyx_t_1 = (__pyx_v_g == __pyx_mstate_global->__pyx_int_1); if (__pyx_t_1) { /* … */ goto __pyx_L29; }
+0527: numerator = -numerator
__pyx_t_5 = PyNumber_Negative(__pyx_v_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 527, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0;
+0528: denominator = -denominator
__pyx_t_5 = PyNumber_Negative(__pyx_v_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 528, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
0529: else:
+0530: g = -g
/*else*/ { __pyx_t_5 = PyNumber_Negative(__pyx_v_g); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 530, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_g, __pyx_t_5); __pyx_t_5 = 0; } __pyx_L29:;
+0531: if g is not 1:
__pyx_t_1 = (__pyx_v_g != __pyx_mstate_global->__pyx_int_1); if (__pyx_t_1) { /* … */ }
+0532: numerator //= g
__pyx_t_5 = PyNumber_InPlaceFloorDivide(__pyx_v_numerator, __pyx_v_g); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 532, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0;
+0533: denominator //= g
__pyx_t_5 = PyNumber_InPlaceFloorDivide(__pyx_v_denominator, __pyx_v_g); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
+0534: 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;
+0535: 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;
0536:
+0537: @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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_number,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 537, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 537, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "from_number", 0) < 0) __PYX_ERR(0, 537, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("from_number", 1, 1, 1, i); __PYX_ERR(0, 537, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 537, __pyx_L3_error) } __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, 537, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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_3); __Pyx_XDECREF(__pyx_t_4); __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_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_3from_number, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_from_number, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[1])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_number, __pyx_t_5) < 0) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GetNameInClass(__pyx_t_5, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_number); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_number, __pyx_t_3) < 0) __PYX_ERR(0, 537, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0538: def from_number(cls, number):
0539: """Converts a finite real number to a rational number, exactly.
0540:
0541: Beware that Fraction.from_number(0.3) != Fraction(3, 10).
0542:
0543: """
+0544: if type(number) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_number)) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0545: 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_3 = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_number)->_denominator; __Pyx_INCREF(__pyx_t_3); __pyx_t_5.__pyx_n = 1; __pyx_t_5.cls = ((PyObject *)__pyx_v_cls); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_3, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 545, __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;
0546:
+0547: elif isinstance(number, int):
__pyx_t_1 = PyLong_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0548: return _fraction_from_coprime_ints(number, 1, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_5.__pyx_n = 1; __pyx_t_5.cls = ((PyObject *)__pyx_v_cls); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_number, __pyx_mstate_global->__pyx_int_1, &__pyx_t_5); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 548, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0549:
+0550: elif isinstance(number, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0551: n, d = number.as_integer_ratio()
__pyx_t_3 = __pyx_v_number; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } 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_3 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_2); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 551, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 551, __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_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 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_7); index = 0; __pyx_t_3 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); 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, 551, __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, 551, __pyx_L1_error) __pyx_L5_unpacking_done:; } __pyx_v_n = __pyx_t_3; __pyx_t_3 = 0; __pyx_v_d = __pyx_t_2; __pyx_t_2 = 0;
+0552: return _fraction_from_coprime_ints(n, d, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_5.__pyx_n = 1; __pyx_t_5.cls = ((PyObject *)__pyx_v_cls); __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_n, __pyx_v_d, &__pyx_t_5); 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: elif isinstance(number, Rational):
__pyx_t_4 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_4); __pyx_t_1 = PyObject_IsInstance(__pyx_v_number, __pyx_t_4); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 554, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+0555: return _fraction_from_coprime_ints(number.numerator, number.denominator, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 555, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 555, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5.__pyx_n = 1; __pyx_t_5.cls = ((PyObject *)__pyx_v_cls); __pyx_t_3 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_4, __pyx_t_2, &__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 555, __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; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0556:
+0557: 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_mstate_global->__pyx_n_u_as_integer_ratio); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 557, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_L6_bool_binop_done:; if (likely(__pyx_t_1)) { /* … */ }
+0558: n, d = number.as_integer_ratio()
__pyx_t_2 = __pyx_v_number; __Pyx_INCREF(__pyx_t_2); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } 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, 558, __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_INCREF(__pyx_t_2); __pyx_t_4 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_4); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_4); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); #endif __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { Py_ssize_t index = -1; __pyx_t_7 = PyObject_GetIter(__pyx_t_3); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 558, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_8 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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_4 = __pyx_t_8(__pyx_t_7); if (unlikely(!__pyx_t_4)) goto __pyx_L8_unpacking_failed; __Pyx_GOTREF(__pyx_t_4); if (__Pyx_IternextUnpackEndCheck(__pyx_t_8(__pyx_t_7), 2) < 0) __PYX_ERR(0, 558, __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, 558, __pyx_L1_error) __pyx_L9_unpacking_done:; } __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_4; __pyx_t_4 = 0;
+0559: return _fraction_from_coprime_ints(n, d, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_5.__pyx_n = 1; __pyx_t_5.cls = ((PyObject *)__pyx_v_cls); __pyx_t_3 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_n, __pyx_v_d, &__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 559, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0560:
0561: else:
+0562: raise TypeError("argument should be a Rational instance or "
/*else*/ { __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_builtin_TypeError); __pyx_t_2 = __pyx_builtin_TypeError; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_mstate_global->__pyx_kp_u_argument_should_be_a_Rational_in}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 562, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(0, 562, __pyx_L1_error) }
0563: "have the as_integer_ratio() method")
0564:
+0565: @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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_f,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 565, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 565, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "from_float", 0) < 0) __PYX_ERR(0, 565, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("from_float", 1, 1, 1, i); __PYX_ERR(0, 565, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 565, __pyx_L3_error) } __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, 565, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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_9); __Pyx_XDECREF(__pyx_t_11); __Pyx_XDECREF(__pyx_t_12); __Pyx_XDECREF(__pyx_t_13); __Pyx_XDECREF(__pyx_t_14); __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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_5from_float, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_from_float, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[2])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_float, __pyx_t_3) < 0) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_GetNameInClass(__pyx_t_3, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_float); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_Method_ClassMethod(__pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_float, __pyx_t_5) < 0) __PYX_ERR(0, 565, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
0566: def from_float(cls, f):
0567: """Converts a finite float to a rational number, exactly.
0568:
0569: Beware that Fraction.from_float(0.3) != Fraction(3, 10).
0570:
0571: """
+0572: 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); }
+0573: ratio = f.as_integer_ratio()
__pyx_t_5 = __pyx_v_f; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 573, __pyx_L3_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_v_ratio = __pyx_t_4; __pyx_t_4 = 0;
+0574: except (ValueError, OverflowError, AttributeError):
__pyx_t_7 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError) || __Pyx_PyErr_ExceptionMatches(__pyx_builtin_AttributeError); if (__pyx_t_7) { __Pyx_ErrRestore(0,0,0); goto __pyx_L4_exception_handled; } goto __pyx_L5_except_error;
0575: pass # not something we can convert, raise concrete exceptions below
0576: else:
+0577: 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, 577, __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, 577, __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;
0578:
+0579: if isinstance(f, Integral):
__pyx_t_5 = __pyx_v_10quicktions_Integral; __Pyx_INCREF(__pyx_t_5); __pyx_t_8 = PyObject_IsInstance(__pyx_v_f, __pyx_t_5); if (unlikely(__pyx_t_8 == ((int)-1))) __PYX_ERR(0, 579, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_8) { /* … */ }
+0580: return cls(f)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = NULL; __Pyx_INCREF((PyObject *)__pyx_v_cls); __pyx_t_9 = ((PyObject *)__pyx_v_cls); __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_f}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+0581: elif not isinstance(f, float):
__pyx_t_8 = PyFloat_Check(__pyx_v_f);
__pyx_t_10 = (!__pyx_t_8);
if (unlikely(__pyx_t_10)) {
/* … */
}
+0582: raise TypeError(f"{cls.__name__}.from_float() only takes floats, not {f!r} ({type(f).__name__})")
__pyx_t_9 = NULL; __Pyx_INCREF(__pyx_builtin_TypeError); __pyx_t_4 = __pyx_builtin_TypeError; __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_12 = __Pyx_PyObject_FormatSimple(__pyx_t_11, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_12); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_11 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_13 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_f)), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __pyx_t_14 = __Pyx_PyObject_FormatSimple(__pyx_t_13, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_15[0] = __pyx_t_12; __pyx_t_15[1] = __pyx_mstate_global->__pyx_kp_u_from_float_only_takes_floats_no; __pyx_t_15[2] = __pyx_t_11; __pyx_t_15[3] = __pyx_mstate_global->__pyx_kp_u_; __pyx_t_15[4] = __pyx_t_14; __pyx_t_15[5] = __pyx_mstate_global->__pyx_kp_u__2; __pyx_t_13 = __Pyx_PyUnicode_Join(__pyx_t_15, 6, __Pyx_PyUnicode_GET_LENGTH(__pyx_t_12) + 37 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_11) + 2 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_12) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_11) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_14)); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_13}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 582, __pyx_L1_error)
+0583: if math.isinf(f):
__pyx_t_4 = __pyx_v_10quicktions_math; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v_f}; __pyx_t_5 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isinf, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_t_10 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_10 < 0))) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_t_10)) { /* … */ }
+0584: raise OverflowError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_4 = NULL; __Pyx_INCREF(__pyx_builtin_OverflowError); __pyx_t_13 = __pyx_builtin_OverflowError; __pyx_t_9 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_11 = __Pyx_PyObject_FormatSimple(__pyx_t_14, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_16[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert; __pyx_t_16[1] = __pyx_t_9; __pyx_t_16[2] = __pyx_mstate_global->__pyx_kp_u_to; __pyx_t_16[3] = __pyx_t_11; __pyx_t_16[4] = __pyx_mstate_global->__pyx_kp_u__3; __pyx_t_14 = __Pyx_PyUnicode_Join(__pyx_t_16, 5, 15 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9) + 4 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_11) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_11)); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_14}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 584, __pyx_L1_error)
+0585: raise ValueError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_13 = NULL; __Pyx_INCREF(__pyx_builtin_ValueError); __pyx_t_14 = __pyx_builtin_ValueError; __pyx_t_4 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_t_11, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __pyx_t_16[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert; __pyx_t_16[1] = __pyx_t_4; __pyx_t_16[2] = __pyx_mstate_global->__pyx_kp_u_to; __pyx_t_16[3] = __pyx_t_9; __pyx_t_16[4] = __pyx_mstate_global->__pyx_kp_u__3; __pyx_t_11 = __Pyx_PyUnicode_Join(__pyx_t_16, 5, 15 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4) + 4 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9)); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_t_11}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_14, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __Pyx_Raise(__pyx_t_5, 0, 0, 0); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __PYX_ERR(0, 585, __pyx_L1_error)
0586:
+0587: @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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_dec,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 587, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 587, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "from_decimal", 0) < 0) __PYX_ERR(0, 587, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("from_decimal", 1, 1, 1, i); __PYX_ERR(0, 587, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 587, __pyx_L3_error) } __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, 587, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_RefNannyFinishContext(); return __pyx_r; } static PyObject *__pyx_pf_10quicktions_8Fraction_6from_decimal(PyTypeObject *__pyx_v_cls, PyObject *__pyx_v_dec) { PyObject *__pyx_v_num = NULL; PyObject *__pyx_v_denom = 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_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __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_dec); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_5 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_7from_decimal, __Pyx_CYFUNCTION_CLASSMETHOD | __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_from_decimal, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[3])); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_decimal, __pyx_t_5) < 0) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GetNameInClass(__pyx_t_5, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_decimal); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_decimal, __pyx_t_3) < 0) __PYX_ERR(0, 587, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0588: def from_decimal(cls, dec):
0589: """Converts a finite Decimal instance to a rational number, exactly."""
0590: cdef Py_ssize_t exp
+0591: 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, 591, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0592: dec = Decimal(int(dec))
__pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_10quicktions_Decimal); __pyx_t_4 = __pyx_v_10quicktions_Decimal; __pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_dec); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_5}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_DECREF_SET(__pyx_v_dec, __pyx_t_1); __pyx_t_1 = 0;
+0593: 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, 593, __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:;
+0594: raise TypeError(
__pyx_t_4 = NULL;
__Pyx_INCREF(__pyx_builtin_TypeError);
__pyx_t_5 = __pyx_builtin_TypeError;
+0595: f"{cls.__name__}.from_decimal() only takes Decimals, not {dec!r} ({type(dec).__name__})")
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_t_3, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_dec), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_dec)), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = __Pyx_PyObject_FormatSimple(__pyx_t_9, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_11[0] = __pyx_t_8; __pyx_t_11[1] = __pyx_mstate_global->__pyx_kp_u_from_decimal_only_takes_Decimal; __pyx_t_11[2] = __pyx_t_3; __pyx_t_11[3] = __pyx_mstate_global->__pyx_kp_u_; __pyx_t_11[4] = __pyx_t_10; __pyx_t_11[5] = __pyx_mstate_global->__pyx_kp_u__2; __pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_11, 6, __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8) + 41 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 2 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_9}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 594, __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, 594, __pyx_L1_error)
+0596: if dec.is_infinite():
__pyx_t_5 = __pyx_v_dec; __Pyx_INCREF(__pyx_t_5); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_infinite, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 596, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0597: raise OverflowError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_5 = NULL; __Pyx_INCREF(__pyx_builtin_OverflowError); __pyx_t_9 = __pyx_builtin_OverflowError; __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_v_dec, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 597, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_10 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 597, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_t_10, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 597, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert; __pyx_t_12[1] = __pyx_t_4; __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_to; __pyx_t_12[3] = __pyx_t_3; __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u__3; __pyx_t_10 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 15 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4) + 4 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 597, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_10}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 597, __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, 597, __pyx_L1_error)
+0598: if dec.is_nan():
__pyx_t_9 = __pyx_v_dec; __Pyx_INCREF(__pyx_t_9); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_is_nan, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 598, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 598, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0599: raise ValueError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_9 = NULL; __Pyx_INCREF(__pyx_builtin_ValueError); __pyx_t_10 = __pyx_builtin_ValueError; __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_dec, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_3, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_12[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert; __pyx_t_12[1] = __pyx_t_5; __pyx_t_12[2] = __pyx_mstate_global->__pyx_kp_u_to; __pyx_t_12[3] = __pyx_t_4; __pyx_t_12[4] = __pyx_mstate_global->__pyx_kp_u__3; __pyx_t_3 = __Pyx_PyUnicode_Join(__pyx_t_12, 5, 15 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5) + 4 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4) + 1, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 599, __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_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_3}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 599, __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, 599, __pyx_L1_error)
0600:
+0601: num, denom = dec.as_integer_ratio()
__pyx_t_10 = __pyx_v_dec; __Pyx_INCREF(__pyx_t_10); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_10, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_6, (1-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } 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, 601, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_10 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_10); __pyx_t_3 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_3); } else { __pyx_t_10 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_10); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); } #else __pyx_t_10 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 601, __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_9 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 601, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_13 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_9); index = 0; __pyx_t_10 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_10)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_10); index = 1; __pyx_t_3 = __pyx_t_13(__pyx_t_9); if (unlikely(!__pyx_t_3)) goto __pyx_L6_unpacking_failed; __Pyx_GOTREF(__pyx_t_3); if (__Pyx_IternextUnpackEndCheck(__pyx_t_13(__pyx_t_9), 2) < 0) __PYX_ERR(0, 601, __pyx_L1_error) __pyx_t_13 = NULL; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L7_unpacking_done; __pyx_L6_unpacking_failed:; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_13 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 601, __pyx_L1_error) __pyx_L7_unpacking_done:; } __pyx_v_num = __pyx_t_10; __pyx_t_10 = 0; __pyx_v_denom = __pyx_t_3; __pyx_t_3 = 0;
+0602: return _fraction_from_coprime_ints(num, denom, cls)
__Pyx_XDECREF(__pyx_r); __pyx_t_14.__pyx_n = 1; __pyx_t_14.cls = ((PyObject *)__pyx_v_cls); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_num, __pyx_v_denom, &__pyx_t_14); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 602, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0603:
+0604: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("is_integer", __pyx_kwds); 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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_9is_integer, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_is_integer, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[4])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 604, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_is_integer, __pyx_t_3) < 0) __PYX_ERR(0, 604, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0605: """Return True if the Fraction is an integer."""
+0606: return self._denominator == 1
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyLong_EqObjC(__pyx_v_self->_denominator, __pyx_mstate_global->__pyx_int_1, 1, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0607:
+0608: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("as_integer_ratio", __pyx_kwds); 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_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_11as_integer_ratio, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_as_integer_ratio, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[5])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 608, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_t_3) < 0) __PYX_ERR(0, 608, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0609: """Return a pair of integers, whose ratio is equal to the original Fraction.
0610:
0611: The ratio is in lowest terms and has a positive denominator.
0612: """
+0613: return (self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 613, __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) != (0)) __PYX_ERR(0, 613, __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) != (0)) __PYX_ERR(0, 613, __pyx_L1_error); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0614:
+0615: 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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_max_denominator,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 615, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 615, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "limit_denominator", 0) < 0) __PYX_ERR(0, 615, __pyx_L3_error) if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)__pyx_mstate_global->__pyx_int_1000000)); } else { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 615, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)__pyx_mstate_global->__pyx_int_1000000)); } __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, 615, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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_6); __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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_13limit_denominator, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_limit_denominator, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[6])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_mstate_global->__pyx_tuple[0]); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_limit_denominator, __pyx_t_3) < 0) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_mstate_global->__pyx_tuple[0] = PyTuple_Pack(1, __pyx_mstate_global->__pyx_int_1000000); if (unlikely(!__pyx_mstate_global->__pyx_tuple[0])) __PYX_ERR(0, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]);
0616: """Closest Fraction to self with denominator at most max_denominator.
0617:
0618: >>> Fraction('3.141592653589793').limit_denominator(10)
0619: Fraction(22, 7)
0620: >>> Fraction('3.141592653589793').limit_denominator(100)
0621: Fraction(311, 99)
0622: >>> Fraction(4321, 8765).limit_denominator(10000)
0623: Fraction(4321, 8765)
0624:
0625: """
0626: # Algorithm notes: For any real number x, define a *best upper
0627: # approximation* to x to be a rational number p/q such that:
0628: #
0629: # (1) p/q >= x, and
0630: # (2) if p/q > r/s >= x then s > q, for any rational r/s.
0631: #
0632: # Define *best lower approximation* similarly. Then it can be
0633: # proved that a rational number is a best upper or lower
0634: # approximation to x if, and only if, it is a convergent or
0635: # semiconvergent of the (unique shortest) continued fraction
0636: # associated to x.
0637: #
0638: # To find a best rational approximation with denominator <= M,
0639: # we find the best upper and lower approximations with
0640: # denominator <= M and take whichever of these is closer to x.
0641: # In the event of a tie, the bound with smaller denominator is
0642: # chosen. If both denominators are equal (which can happen
0643: # only when max_denominator == 1 and self is midway between
0644: # two integers) the lower bound---i.e., the floor of self, is
0645: # taken.
0646:
+0647: if max_denominator < 1:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_max_denominator, __pyx_mstate_global->__pyx_int_1, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 647, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 647, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_2)) { /* … */ }
+0648: raise ValueError("max_denominator should be at least 1")
__pyx_t_3 = NULL; __Pyx_INCREF(__pyx_builtin_ValueError); __pyx_t_4 = __pyx_builtin_ValueError; __pyx_t_5 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_max_denominator_should_be_at_lea}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 648, __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, 648, __pyx_L1_error)
+0649: 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, 649, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 649, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0650: return Fraction(self)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = NULL; __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_3 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_5 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_4, ((PyObject *)__pyx_v_self)}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 650, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_1); } __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;
0651:
+0652: p0, q0, p1, q1 = 0, 1, 1, 0
__pyx_t_1 = __pyx_mstate_global->__pyx_int_0; __Pyx_INCREF(__pyx_t_1); __pyx_t_3 = __pyx_mstate_global->__pyx_int_1; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = __pyx_mstate_global->__pyx_int_1; __Pyx_INCREF(__pyx_t_4); __pyx_t_6 = __pyx_mstate_global->__pyx_int_0; __Pyx_INCREF(__pyx_t_6); __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_6; __pyx_t_6 = 0;
+0653: n, d = self._numerator, self._denominator
__pyx_t_6 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_6); __pyx_t_4 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_4); __pyx_v_n = __pyx_t_6; __pyx_t_6 = 0; __pyx_v_d = __pyx_t_4; __pyx_t_4 = 0;
+0654: while True:
while (1) {
+0655: a = n//d
__pyx_t_4 = PyNumber_FloorDivide(__pyx_v_n, __pyx_v_d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_4); __pyx_t_4 = 0;
+0656: q2 = q0+a*q1
__pyx_t_4 = PyNumber_Multiply(__pyx_v_a, __pyx_v_q1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = PyNumber_Add(__pyx_v_q0, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_XDECREF_SET(__pyx_v_q2, __pyx_t_6); __pyx_t_6 = 0;
+0657: if q2 > max_denominator:
__pyx_t_6 = PyObject_RichCompare(__pyx_v_q2, __pyx_v_max_denominator, Py_GT); __Pyx_XGOTREF(__pyx_t_6); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 657, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 657, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_2) { /* … */ }
+0658: break
goto __pyx_L6_break;
+0659: p0, q0, p1, q1 = p1, q1, p0+a*p1, q2
__pyx_t_6 = __pyx_v_p1; __Pyx_INCREF(__pyx_t_6); __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, 659, __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, 659, __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_6); __pyx_t_6 = 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;
+0660: 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, 660, __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, 660, __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:;
0661:
+0662: 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, 662, __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, 662, __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;
0663:
0664: # Determine which of the candidates (p0+k*p1)/(q0+k*q1) and p1/q1 is
0665: # closer to self. The distance between them is 1/(q1*(q0+k*q1)), while
0666: # the distance from p1/q1 to self is d/(q1*self._denominator). So we
0667: # need to compare 2*(q0+k*q1) with self._denominator/d.
+0668: if 2*d*(q0+k*q1) <= self._denominator:
__pyx_t_3 = __Pyx_PyLong_MultiplyCObj(__pyx_mstate_global->__pyx_int_2, __pyx_v_d, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 668, __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, 668, __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, 668, __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, 668, __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, 668, __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, 668, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0669: 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, 669, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0670: else:
+0671: 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, 671, __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, 671, __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, 671, __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, 671, __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, 671, __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; }
0672:
+0673: @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; }
0674: def numerator(self):
+0675: return self._numerator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_numerator); __pyx_r = __pyx_v_self->_numerator; goto __pyx_L0;
0676:
+0677: @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; }
0678: def denominator(self):
+0679: return self._denominator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_denominator); __pyx_r = __pyx_v_self->_denominator; goto __pyx_L0;
0680:
+0681: 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_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_5); __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; }
0682: """repr(self)"""
+0683: return '%s(%s, %s)' % (self.__class__.__name__,
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_class); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 683, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 683, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_t_2), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 683, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 6, __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1) + 1 * 2 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 2 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 683, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+0684: self._numerator, self._denominator)
__pyx_t_2 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_v_self->_numerator), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 684, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Str(__pyx_v_self->_denominator), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 684, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4[0] = __pyx_t_1; __pyx_t_4[1] = __pyx_mstate_global->__pyx_kp_u__4; __pyx_t_4[2] = __pyx_t_2; __pyx_t_4[3] = __pyx_mstate_global->__pyx_kp_u__5; __pyx_t_4[4] = __pyx_t_3; __pyx_t_4[5] = __pyx_mstate_global->__pyx_kp_u__2;
0685:
+0686: 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_3); __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; }
0687: """str(self)"""
+0688: if self._denominator == 1:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_self->_denominator, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 688, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0689: return str(self._numerator)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_Unicode(__pyx_v_self->_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 689, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0690: else:
+0691: return f'{self._numerator}/{self._denominator}'
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_self->_numerator, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_FormatSimple(__pyx_v_self->_denominator, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 691, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4[0] = __pyx_t_2; __pyx_t_4[1] = __pyx_mstate_global->__pyx_kp_u__6; __pyx_t_4[2] = __pyx_t_3; __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __Pyx_PyUnicode_GET_LENGTH(__pyx_t_2) + 1 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_3), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_2) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_3)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 691, __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_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; }
0692:
+0693: @cython.final
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; }
0694: cdef _format_general(self, dict match):
0695: """Helper method for __format__.
0696:
0697: Handles fill, alignment, signs, and thousands separators in the
0698: case of no presentation type.
0699: """
0700: # Validate and parse the format specifier.
+0701: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 701, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_fill); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 701, __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, 701, __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_mstate_global->__pyx_kp_u__7); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__7; __pyx_L3_bool_binop_done:; __pyx_v_fill = __pyx_t_1; __pyx_t_1 = 0;
+0702: 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, 702, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 702, __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, 702, __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_mstate_global->__pyx_kp_u__8); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__8; __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, 702, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_align = __pyx_t_4;
+0703: 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, 703, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 703, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_mstate_global->__pyx_kp_u__9, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 703, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__10); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__10; } else { if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 703, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 703, __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;
+0704: 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, 704, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_alt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 704, __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, 704, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_alternate_form = __pyx_t_3;
+0705: 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, 705, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_minimumwidth); 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_L7_bool_binop_done; } __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u_0_2); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u_0_2; __pyx_L7_bool_binop_done:; __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 705, __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, 705, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_minimumwidth = __pyx_t_5;
+0706: 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, 706, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_thousands_sep); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 706, __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, 706, __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_mstate_global->__pyx_kp_u__10); __pyx_t_2 = __pyx_mstate_global->__pyx_kp_u__10; __pyx_L9_bool_binop_done:; __pyx_v_thousands_sep = __pyx_t_2; __pyx_t_2 = 0;
0707:
+0708: if PY_VERSION_HEX < 0x03060000:
__pyx_t_3 = (PY_VERSION_HEX < 0x03060000); if (__pyx_t_3) { /* … */ }
+0709: legacy_thousands_sep, thousands_sep = thousands_sep, ''
__pyx_t_2 = __pyx_v_thousands_sep; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__10; __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;
0710: cdef Py_ssize_t first_pos # Py2/3.5-only
0711:
0712: # Determine the body and sign representation.
+0713: 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;
+0714: 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, 714, __pyx_L1_error) } __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_v_legacy_thousands_sep); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 714, __pyx_L1_error) __pyx_t_3 = __pyx_t_6; __pyx_L13_bool_binop_done:; if (__pyx_t_3) { /* … */ goto __pyx_L12; }
0715: # Insert thousands separators if required.
+0716: body = str(abs(n))
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_Unicode(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 716, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_body = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+0717: first_pos = 1 + (len(body) - 1) % 3
__pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_body); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 717, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_5 - 1), 3, 1));
+0718: body = body[:first_pos] + "".join([
__pyx_t_1 = __Pyx_PyUnicode_Substring(__pyx_v_body, 0, __pyx_v_first_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 718, __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, 718, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_10 = PyUnicode_Join(__pyx_mstate_global->__pyx_kp_u__10, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 718, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_1, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 718, __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, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0;
+0719: legacy_thousands_sep + body[pos : pos + 3]
if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 719, __pyx_L1_error) } __pyx_t_9 = __Pyx_PyUnicode_Substring(__pyx_v_body, __pyx_7genexpr__pyx_v_pos, (__pyx_7genexpr__pyx_v_pos + 3)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 719, __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, 719, __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, 718, __pyx_L1_error) __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; } } /* exit inner scope */
+0720: for pos in range(first_pos, len(body), 3)
__pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_body); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 720, __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;
0721: ])
+0722: if d > 1 or alternate_form:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_d, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 722, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 722, __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) { /* … */ }
+0723: den = str(abs(d))
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = __Pyx_PyObject_Unicode(__pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_den = ((PyObject*)__pyx_t_10); __pyx_t_10 = 0;
+0724: first_pos = 1 + (len(den) - 1) % 3
__pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_den); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 724, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_5 - 1), 3, 1));
+0725: den = den[:first_pos] + "".join([
__pyx_t_10 = __Pyx_PyUnicode_Substring(__pyx_v_den, 0, __pyx_v_first_pos); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 725, __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, 725, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); /* … */ __pyx_t_9 = PyUnicode_Join(__pyx_mstate_global->__pyx_kp_u__10, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 725, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_10, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 725, __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, ((PyObject*)__pyx_t_2)); __pyx_t_2 = 0;
+0726: legacy_thousands_sep + den[pos: pos + 3]
if (unlikely(!__pyx_v_legacy_thousands_sep)) { __Pyx_RaiseUnboundLocalError("legacy_thousands_sep"); __PYX_ERR(0, 726, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyUnicode_Substring(__pyx_v_den, __pyx_8genexpr1__pyx_v_pos, (__pyx_8genexpr1__pyx_v_pos + 3)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 726, __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, 726, __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, 725, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; } } /* exit inner scope */
+0727: for pos in range(first_pos, len(den), 3)
__pyx_t_5 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_den); if (unlikely(__pyx_t_5 == ((Py_ssize_t)-1))) __PYX_ERR(0, 727, __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;
0728: ])
+0729: body += "/" + den
__pyx_t_2 = __Pyx_PyUnicode_Concat(__pyx_mstate_global->__pyx_kp_u__6, __pyx_v_den); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 729, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PyUnicode_ConcatInPlace(__pyx_v_body, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 729, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_body, ((PyObject*)__pyx_t_9)); __pyx_t_9 = 0;
+0730: elif d > 1 or alternate_form:
__pyx_t_9 = PyObject_RichCompare(__pyx_v_d, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 730, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 730, __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; }
+0731: body = f"{abs(n):{thousands_sep}}/{d:{thousands_sep}}"
__pyx_t_9 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = __Pyx_PyObject_Format(__pyx_t_9, __pyx_t_2); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PyObject_Format(__pyx_v_d, __pyx_t_2); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 731, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_11[0] = __pyx_t_10; __pyx_t_11[1] = __pyx_mstate_global->__pyx_kp_u__6; __pyx_t_11[2] = __pyx_t_9; __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_11, 3, __Pyx_PyUnicode_GET_LENGTH(__pyx_t_10) + 1 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_10) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 731, __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_v_body = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0;
0732: else:
+0733: body = f"{abs(n):{thousands_sep}}"
/*else*/ { __pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = __Pyx_PyObject_Format(__pyx_t_2, __pyx_t_9); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 733, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_v_body = ((PyObject*)__pyx_t_10); __pyx_t_10 = 0; } __pyx_L12:;
+0734: sign = '-' if n < 0 else pos_sign
__pyx_t_9 = PyObject_RichCompare(__pyx_v_n, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_9); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 734, __pyx_L1_error) __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_9); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 734, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__9); __pyx_t_10 = __pyx_mstate_global->__pyx_kp_u__9; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_10 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_10; __pyx_t_10 = 0;
0735:
0736: # Pad with fill character if necessary and return.
+0737: 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, 737, __pyx_L1_error) __pyx_t_7 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_body); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 737, __pyx_L1_error) __pyx_t_10 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_5) - __pyx_t_7)); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = PyNumber_Multiply(__pyx_v_fill, __pyx_t_10); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 737, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_v_padding = __pyx_t_9; __pyx_t_9 = 0;
+0738: if align == u">":
switch (__pyx_v_align) { case 62: /* … */ break; case 60:
+0739: 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, 739, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_v_body); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 739, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_r = __pyx_t_10; __pyx_t_10 = 0; goto __pyx_L0;
+0740: elif align == u"<":
break; case 94:
+0741: return sign + body + padding
__Pyx_XDECREF(__pyx_r); __pyx_t_10 = PyNumber_Add(__pyx_v_sign, __pyx_v_body); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 741, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_9 = PyNumber_Add(__pyx_t_10, __pyx_v_padding); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 741, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_r = __pyx_t_9; __pyx_t_9 = 0; goto __pyx_L0;
+0742: elif align == u"^":
break; default:
+0743: half = len(padding) // 2
__pyx_t_7 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_7 == ((Py_ssize_t)-1))) __PYX_ERR(0, 743, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_7, 2, 1);
+0744: 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, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_10 = PyNumber_Add(__pyx_t_9, __pyx_v_sign); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = PyNumber_Add(__pyx_t_10, __pyx_v_body); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_t_10 = __Pyx_PyObject_GetSlice(__pyx_v_padding, __pyx_v_half, 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_2 = PyNumber_Add(__pyx_t_9, __pyx_t_10); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0745: else: # align == u"="
+0746: return sign + padding + body
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyNumber_Add(__pyx_v_sign, __pyx_v_padding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = PyNumber_Add(__pyx_t_2, __pyx_v_body); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_10; __pyx_t_10 = 0; goto __pyx_L0; break; }
0747:
+0748: @cython.final
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; }
0749: cdef _format_float_style(self, dict match):
0750: """Helper method for __format__; handles float presentation types."""
+0751: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 751, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_fill); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 751, __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, 751, __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_mstate_global->__pyx_kp_u__7); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__7; __pyx_L3_bool_binop_done:; __pyx_v_fill = __pyx_t_1; __pyx_t_1 = 0;
+0752: align = match["align"] or ">"
if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 752, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_align); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 752, __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, 752, __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_mstate_global->__pyx_kp_u__8); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__8; __pyx_L5_bool_binop_done:; __pyx_v_align = __pyx_t_1; __pyx_t_1 = 0;
+0753: 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, 753, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 753, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_2, __pyx_mstate_global->__pyx_kp_u__9, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 753, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__10); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__10; } else { if (unlikely(__pyx_v_match == Py_None)) { PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); __PYX_ERR(0, 753, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 753, __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;
+0754: 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, 754, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_no_neg_zero); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 754, __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, 754, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_no_neg_zero = __pyx_t_3;
+0755: 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, 755, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_alt); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 755, __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, 755, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_alternate_form = __pyx_t_3;
+0756: cdef bint zeropad = match["zeropad"]
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_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_zeropad); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 756, __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, 756, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_zeropad = __pyx_t_3;
+0757: 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, 757, __pyx_L1_error) } __pyx_t_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_minimumwidth); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 757, __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, 757, __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_mstate_global->__pyx_kp_u_0_2); __pyx_t_1 = __pyx_mstate_global->__pyx_kp_u_0_2; __pyx_L7_bool_binop_done:; __pyx_t_2 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 757, __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, 757, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_minimumwidth = __pyx_t_4;
+0758: thousands_sep = match["thousands_sep"]
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_2 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_thousands_sep); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 758, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_thousands_sep = __pyx_t_2; __pyx_t_2 = 0;
+0759: 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, 759, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_precision); 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 < 0))) __PYX_ERR(0, 759, __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_mstate_global->__pyx_kp_u_6); __pyx_t_2 = __pyx_mstate_global->__pyx_kp_u_6; __pyx_L9_bool_binop_done:; __pyx_t_1 = __Pyx_PyNumber_Int(__pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 759, __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, 759, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_precision = __pyx_t_4;
+0760: 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, 760, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyDict_GetItem(__pyx_v_match, __pyx_mstate_global->__pyx_n_u_presentation_type); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 760, __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, 760, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_presentation_type = __pyx_t_5;
+0761: 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;
+0762: cdef bint trim_point = not alternate_form
__pyx_v_trim_point = (!__pyx_v_alternate_form);
+0763: 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_mstate_global->__pyx_n_u_E); __pyx_t_1 = __pyx_mstate_global->__pyx_n_u_E; break; default: __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_e); __pyx_t_1 = __pyx_mstate_global->__pyx_n_u_e; break; } __pyx_v_exponent_indicator = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
0764:
0765: cdef bint negative, scientific
0766: cdef Py_ssize_t exponent, figures
0767:
0768: # Round to get the digits we need, figure out where to place the point,
0769: # and decide whether to use scientific notation. 'point_pos' is the
0770: # relative to the _end_ of the digit string: that is, it's the number
0771: # of digits that should follow the point.
+0772: if presentation_type in u"fF%":
switch (__pyx_v_presentation_type) { case 37: case 70: case 0x66: /* … */ break; default:
+0773: exponent = -precision
__pyx_v_exponent = (-__pyx_v_precision);
+0774: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37); if (__pyx_t_3) { /* … */ }
+0775: exponent -= 2
__pyx_v_exponent = (__pyx_v_exponent - 2);
+0776: 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, 776, __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, 776, __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_INCREF(__pyx_t_8); __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_2); } else { __pyx_t_8 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_8); __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); } #else __pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 776, __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, 776, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 776, __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, 776, __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, 776, __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;
+0777: 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 = PyLong_FromSsize_t(__pyx_v_exponent); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 777, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8);
+0778: scientific = False
__pyx_v_scientific = 0;
+0779: point_pos = precision
__pyx_t_9 = PyLong_FromSsize_t(__pyx_v_precision); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 779, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_point_pos = __pyx_t_9; __pyx_t_9 = 0;
0780: else: # presentation_type in "eEgG"
0781: figures = (
+0782: 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:
+0783: if presentation_type in u"gG"
case 0x67:
+0784: else precision + 1
__pyx_t_4 = (__pyx_v_precision + 1); break; } __pyx_v_figures = __pyx_t_4;
0785: )
+0786: 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, 786, __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, 786, __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_INCREF(__pyx_t_2); __pyx_t_9 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_9); __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); __Pyx_INCREF(__pyx_t_1); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 786, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 786, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_9); __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 786, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 786, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 786, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 786, __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, 786, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_11 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 786, __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, 786, __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, 786, __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, 786, __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;
+0787: 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);
0788: scientific = (
+0789: 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; }
+0790: 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; }
+0791: 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;
0792: )
+0793: point_pos = figures - 1 if scientific else -exponent
if (__pyx_v_scientific) { __pyx_t_1 = PyLong_FromSsize_t((__pyx_v_figures - 1)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 793, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __pyx_t_1; __pyx_t_1 = 0; } else { __pyx_t_1 = PyLong_FromSsize_t((-__pyx_v_exponent)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 793, __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; }
0794:
0795: # Get the suffix - the part following the digits, if any.
+0796: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37); if (__pyx_t_3) { /* … */ goto __pyx_L21; }
+0797: suffix = "%"
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__11);
__pyx_v_suffix = __pyx_mstate_global->__pyx_kp_u__11;
+0798: elif scientific:
if (__pyx_v_scientific) { /* … */ goto __pyx_L21; }
0799: #suffix = f"{exponent_indicator}{exponent + point_pos:+03d}"
+0800: suffix = "%s%+03d" % (exponent_indicator, exponent + point_pos)
__pyx_t_8 = PyLong_FromSsize_t(__pyx_v_exponent); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 800, __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, 800, __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, 800, __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) != (0)) __PYX_ERR(0, 800, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 800, __pyx_L1_error); __pyx_t_1 = 0; __pyx_t_1 = PyUnicode_Format(__pyx_mstate_global->__pyx_kp_u_s_03d, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 800, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_suffix = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
0801: else:
+0802: suffix = ""
/*else*/ {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__10);
__pyx_v_suffix = __pyx_mstate_global->__pyx_kp_u__10;
}
__pyx_L21:;
0803:
0804: # String of output digits, padded sufficiently with zeros on the left
0805: # so that we'll have at least one digit before the decimal point.
+0806: digits = f"{significand:0{point_pos + 1}d}"
__pyx_t_1 = __Pyx_PyLong_AddObjC(__pyx_v_point_pos, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_t_1, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_15[0] = __pyx_mstate_global->__pyx_kp_u_0_2; __pyx_t_15[1] = __pyx_t_8; __pyx_t_15[2] = __pyx_mstate_global->__pyx_n_u_d; __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_15, 3, 1 * 2 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_8)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyObject_Format(__pyx_v_significand, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 806, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_digits = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0;
0807:
0808: # Before padding, the output has the form f"{sign}{leading}{trailing}",
0809: # where `leading` includes thousands separators if necessary and
0810: # `trailing` includes the decimal separator where appropriate.
+0811: sign = "-" if negative else pos_sign
if (__pyx_v_negative) { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__9); __pyx_t_8 = __pyx_mstate_global->__pyx_kp_u__9; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_8 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_8; __pyx_t_8 = 0;
+0812: 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, 812, __pyx_L1_error) __pyx_t_8 = PyLong_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 812, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = PyNumber_Subtract(__pyx_t_8, __pyx_v_point_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_3 = (__pyx_t_1 == Py_None); if (__pyx_t_3) { __pyx_t_4 = PY_SSIZE_T_MAX; } 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, 812, __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, 0, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 812, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_leading = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+0813: 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, 813, __pyx_L1_error) __pyx_t_1 = PyLong_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 813, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = PyNumber_Subtract(__pyx_t_1, __pyx_v_point_pos); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 813, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (__pyx_t_8 == Py_None); if (__pyx_t_3) { __pyx_t_4 = 0; } else { __pyx_t_13 = __Pyx_PyIndex_AsSsize_t(__pyx_t_8); if (unlikely((__pyx_t_13 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 813, __pyx_L1_error) __pyx_t_4 = __pyx_t_13; } __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyUnicode_Substring(__pyx_v_digits, __pyx_t_4, PY_SSIZE_T_MAX); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 813, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_frac_part = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0;
+0814: if trim_zeros:
if (__pyx_v_trim_zeros) { /* … */ }
+0815: frac_part = frac_part.rstrip("0")
__pyx_t_8 = __Pyx_CallUnboundCMethod1(&__pyx_mstate_global->__pyx_umethod_PyUnicode_Type__rstrip, __pyx_v_frac_part, __pyx_mstate_global->__pyx_kp_u_0_2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF_SET(__pyx_v_frac_part, ((PyObject*)__pyx_t_8)); __pyx_t_8 = 0;
+0816: 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_PyUnicode_IS_TRUE(__pyx_v_frac_part) != 0); if (unlikely(((!CYTHON_ASSUME_SAFE_MACROS) && __pyx_t_6 < 0))) __PYX_ERR(0, 816, __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_mstate_global->__pyx_kp_u__10); __pyx_t_8 = __pyx_mstate_global->__pyx_kp_u__10; } else { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__3); __pyx_t_8 = __pyx_mstate_global->__pyx_kp_u__3; } __pyx_v_separator = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0;
+0817: trailing = separator + frac_part + suffix
__pyx_t_8 = __Pyx_PyUnicode_ConcatSafe(__pyx_v_separator, __pyx_v_frac_part); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 817, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_8, __pyx_v_suffix); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 817, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_v_trailing = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
0818:
0819: # Do zero padding if required.
+0820: if zeropad:
if (__pyx_v_zeropad) { /* … */ }
+0821: 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, 821, __pyx_L1_error) __pyx_t_13 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_trailing); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 821, __pyx_L1_error) __pyx_t_1 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_4) - __pyx_t_13)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 821, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_min_leading = __pyx_t_1; __pyx_t_1 = 0;
0822: # When adding thousands separators, they'll be added to the
0823: # zero-padded portion too, so we need to compensate.
+0824: leading = leading.zfill(
__pyx_t_8 = __Pyx_CallUnboundCMethod1(&__pyx_mstate_global->__pyx_umethod_PyUnicode_Type__zfill, __pyx_v_leading, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 824, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF_SET(__pyx_v_leading, ((PyObject*)__pyx_t_8)); __pyx_t_8 = 0;
+0825: 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, 825, __pyx_L1_error) if (__pyx_t_3) { __pyx_t_8 = __Pyx_PyLong_MultiplyCObj(__pyx_mstate_global->__pyx_int_3, __pyx_v_min_leading, 3, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 825, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyLong_FloorDivideObjC(__pyx_t_8, __pyx_mstate_global->__pyx_int_4, 4, 0, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 825, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = __Pyx_PyLong_AddObjC(__pyx_t_9, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 825, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_1 = __pyx_t_8; __pyx_t_8 = 0; } else { __Pyx_INCREF(__pyx_v_min_leading); __pyx_t_1 = __pyx_v_min_leading; }
0826: )
0827:
0828: # Insert thousands separators if required.
+0829: if thousands_sep:
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_thousands_sep); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 829, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0830: first_pos = 1 + (len(leading) - 1) % 3
__pyx_t_13 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_leading); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 830, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_13 - 1), 3, 1));
+0831: leading = leading[:first_pos] + "".join([
__pyx_t_8 = __Pyx_PyUnicode_Substring(__pyx_v_leading, 0, __pyx_v_first_pos); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); { /* enter inner scope */ __pyx_t_1 = PyList_New(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); /* … */ __pyx_t_2 = PyUnicode_Join(__pyx_mstate_global->__pyx_kp_u__10, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_8, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_leading, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0;
+0832: thousands_sep + leading[pos : pos + 3]
__pyx_t_9 = __Pyx_PyUnicode_Substring(__pyx_v_leading, __pyx_8genexpr2__pyx_v_pos, (__pyx_8genexpr2__pyx_v_pos + 3)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 832, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_2 = PyNumber_Add(__pyx_v_thousands_sep, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 832, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(__Pyx_ListComp_Append(__pyx_t_1, (PyObject*)__pyx_t_2))) __PYX_ERR(0, 831, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } /* exit inner scope */
+0833: for pos in range(first_pos, len(leading), 3)
__pyx_t_13 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_leading); if (unlikely(__pyx_t_13 == ((Py_ssize_t)-1))) __PYX_ERR(0, 833, __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;
0834: ])
0835:
0836: # We now have a sign and a body. Pad with fill character if necessary
0837: # and return.
+0838: body = leading + trailing
__pyx_t_1 = __Pyx_PyUnicode_Concat(__pyx_v_leading, __pyx_v_trailing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 838, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_body = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+0839: 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, 839, __pyx_L1_error) __pyx_t_4 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_body); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 839, __pyx_L1_error) __pyx_t_1 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_13) - __pyx_t_4)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 839, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Multiply(__pyx_v_fill, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 839, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_padding = __pyx_t_2; __pyx_t_2 = 0;
+0840: if align == ">":
__pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__8, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 840, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0841: 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, 841, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_v_body); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 841, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+0842: elif align == "<":
__pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__12, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 842, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0843: 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, 843, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_padding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 843, __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;
+0844: elif align == "^":
__pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__13, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 844, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+0845: half = len(padding) // 2
__pyx_t_4 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 845, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_4, 2, 1);
+0846: 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, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_v_sign); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_v_body); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_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, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = PyNumber_Add(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 846, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_8; __pyx_t_8 = 0; goto __pyx_L0;
0847: else: # align == "="
+0848: return sign + padding + body
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_8 = PyNumber_Add(__pyx_v_sign, __pyx_v_padding); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = PyNumber_Add(__pyx_t_8, __pyx_v_body); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 848, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
0849:
+0850: 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_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_19__format__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___format, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[7])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_format, __pyx_t_3) < 0) __PYX_ERR(0, 850, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0851: """Format this fraction according to the given format specification."""
0852:
+0853: if match := _GENERAL_FORMAT_SPECIFICATION_MATCHER(format_spec):
__pyx_t_2 = NULL; __Pyx_INCREF(__pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER); __pyx_t_3 = __pyx_v_10quicktions__GENERAL_FORMAT_SPECIFICATION_MATCHER; __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_format_spec}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 853, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __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, 853, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+0854: return self._format_general(match.groupdict())
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_v_match; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_1 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_groupdict, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 854, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_1))) __PYX_ERR(0, 854, __pyx_L1_error) __pyx_t_3 = __pyx_f_10quicktions_8Fraction__format_general(__pyx_v_self, ((PyObject*)__pyx_t_1)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 854, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0855:
+0856: if match := _FLOAT_FORMAT_SPECIFICATION_MATCHER(format_spec):
__pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER); __pyx_t_2 = __pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER; __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_2, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_format_spec}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF_SET(__pyx_v_match, __pyx_t_3); __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 856, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_5) { /* … */ }
0857: # Refuse the temptation to guess if both alignment _and_
0858: # zero padding are specified.
+0859: match_groups = match.groupdict()
__pyx_t_2 = __pyx_v_match; __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, NULL}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_groupdict, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 859, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_v_match_groups = __pyx_t_3; __pyx_t_3 = 0;
+0860: if match_groups["align"] is None or match_groups["zeropad"] is None:
__pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_match_groups, __pyx_mstate_global->__pyx_n_u_align); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 860, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = (__pyx_t_3 == Py_None); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (!__pyx_t_6) { } else { __pyx_t_5 = __pyx_t_6; goto __pyx_L6_bool_binop_done; } __pyx_t_3 = __Pyx_PyObject_Dict_GetItem(__pyx_v_match_groups, __pyx_mstate_global->__pyx_n_u_zeropad); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 860, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = (__pyx_t_3 == Py_None); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = __pyx_t_6; __pyx_L6_bool_binop_done:; if (__pyx_t_5) { /* … */ }
+0861: 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, 861, __pyx_L1_error) __pyx_t_3 = __pyx_f_10quicktions_8Fraction__format_float_style(__pyx_v_self, ((PyObject*)__pyx_v_match_groups)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 861, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0862:
+0863: raise ValueError(
__pyx_t_2 = NULL;
__Pyx_INCREF(__pyx_builtin_ValueError);
__pyx_t_1 = __pyx_builtin_ValueError;
+0864: f"Invalid format specifier {format_spec!r} "
__pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_format_spec), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 864, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); /* … */ __pyx_t_8 = __Pyx_PyUnicode_Join(__pyx_t_10, 4, 25 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7) + 20 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_9)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 864, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_4 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_8}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 863, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_Raise(__pyx_t_3, 0, 0, 0); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __PYX_ERR(0, 863, __pyx_L1_error)
+0865: f"for object of type {type(self).__name__!r}"
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 865, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_t_8), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 865, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_10[0] = __pyx_mstate_global->__pyx_kp_u_Invalid_format_specifier; __pyx_t_10[1] = __pyx_t_7; __pyx_t_10[2] = __pyx_mstate_global->__pyx_kp_u_for_object_of_type; __pyx_t_10[3] = __pyx_t_9;
0866: )
0867:
+0868: 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; }
0869: """a + b"""
+0870: 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, 870, __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;
0871:
+0872: 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; }
0873: """a + b"""
+0874: 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, 874, __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;
0875:
+0876: 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; }
0877: """a - b"""
+0878: 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, 878, __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;
0879:
+0880: 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; }
0881: """a - b"""
+0882: 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, 882, __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;
0883:
+0884: 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; }
0885: """a * b"""
+0886: 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, 886, __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;
0887:
+0888: 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; }
0889: """a * b"""
+0890: 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, 890, __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;
0891:
+0892: def __div__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_33__div__(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_32__div__, "a / b"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_33__div__ = {"__div__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_33__div__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_32__div__}; static PyObject *__pyx_pw_10quicktions_8Fraction_33__div__(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 ) { 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("__div__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_b,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 892, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 892, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__div__", 0) < 0) __PYX_ERR(0, 892, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__div__", 1, 1, 1, i); __PYX_ERR(0, 892, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 892, __pyx_L3_error) } __pyx_v_b = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__div__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 892, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("quicktions.Fraction.__div__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_32__div__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_a), __pyx_v_b); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_RefNannyFinishContext(); return __pyx_r; } 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; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_33__div__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___div, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[8])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 892, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_div, __pyx_t_3) < 0) __PYX_ERR(0, 892, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0893: """a / b"""
+0894: 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, 894, __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;
0895:
+0896: def __rdiv__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_35__rdiv__(PyObject *__pyx_v_b, #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_34__rdiv__, "a / b"); static PyMethodDef __pyx_mdef_10quicktions_8Fraction_35__rdiv__ = {"__rdiv__", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_8Fraction_35__rdiv__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_8Fraction_34__rdiv__}; static PyObject *__pyx_pw_10quicktions_8Fraction_35__rdiv__(PyObject *__pyx_v_b, #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; #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("__rdiv__ (wrapper)", 0); #if !CYTHON_METH_FASTCALL #if CYTHON_ASSUME_SAFE_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_a,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 896, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 896, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__rdiv__", 0) < 0) __PYX_ERR(0, 896, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__rdiv__", 1, 1, 1, i); __PYX_ERR(0, 896, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 896, __pyx_L3_error) } __pyx_v_a = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__rdiv__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 896, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_AddTraceback("quicktions.Fraction.__rdiv__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_8Fraction_34__rdiv__(((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b), __pyx_v_a); int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; /* function exit code */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(values[__pyx_temp]); } __Pyx_RefNannyFinishContext(); return __pyx_r; } 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; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_35__rdiv__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___rdiv, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[9])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 896, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_rdiv, __pyx_t_3) < 0) __PYX_ERR(0, 896, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0897: """a / b"""
+0898: 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, 898, __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;
0899:
+0900: 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; }
0901: """a / b"""
+0902: 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, 902, __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;
0903:
+0904: 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; }
0905: """a / b"""
+0906: 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, 906, __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;
0907:
+0908: 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; }
0909: """a // b"""
+0910: 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, 910, __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;
0911:
+0912: 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; }
0913: """a // b"""
+0914: 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, 914, __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;
0915:
+0916: 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; }
0917: """a % b"""
+0918: 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, 918, __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;
0919:
+0920: 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; }
0921: """a % b"""
+0922: 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, 922, __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;
0923:
+0924: 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; }
0925: """divmod(self, other): The pair (self // other, self % other).
0926:
0927: Sometimes this can be computed faster than the pair of
0928: operations.
0929: """
+0930: 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, 930, __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;
0931:
+0932: 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; }
0933: """divmod(self, other): The pair (self // other, self % other).
0934:
0935: Sometimes this can be computed faster than the pair of
0936: operations.
0937: """
+0938: 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, 938, __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;
0939:
+0940: 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_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __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; }
0941: """a ** b
0942:
0943: If b is not an integer, the result will be a float or complex
0944: since roots are generally irrational. If b is an integer, the
0945: result will be rational.
0946: """
+0947: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { /* … */ }
+0948: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
0949:
+0950: if isinstance(b, int):
__pyx_t_1 = PyLong_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+0951: return _pow(a.numerator, a.denominator, b, 1)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 951, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 951, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __pyx_f_10quicktions__pow(__pyx_t_2, __pyx_t_3, __pyx_v_b, __pyx_mstate_global->__pyx_int_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 951, __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;
+0952: elif isinstance(b, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_4 = __pyx_v_10quicktions_Rational; __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_b, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); if (!__pyx_t_5) { } else { __pyx_t_1 = __pyx_t_5; goto __pyx_L5_bool_binop_done; } __pyx_t_5 = PyObject_IsInstance(__pyx_v_b, __pyx_t_4); __pyx_t_1 = __pyx_t_5; __pyx_L5_bool_binop_done:; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+0953: return _pow(a.numerator, a.denominator, b.numerator, b.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 953, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 953, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 953, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 953, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __pyx_f_10quicktions__pow(__pyx_t_4, __pyx_t_3, __pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 953, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
+0954: elif isinstance(b, (float, complex)):
__pyx_t_5 = PyFloat_Check(__pyx_v_b); if (!__pyx_t_5) { } else { __pyx_t_1 = __pyx_t_5; goto __pyx_L7_bool_binop_done; } __pyx_t_5 = PyComplex_Check(__pyx_v_b); __pyx_t_1 = __pyx_t_5; __pyx_L7_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0955: return (a.numerator / a.denominator) ** b
__Pyx_XDECREF(__pyx_r); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 955, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 955, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_t_7, __pyx_t_6); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 955, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __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_2, __pyx_v_b, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 955, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
0956: else:
+0957: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
0958:
+0959: 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; }
0960: """a ** b
0961:
0962: If b is not an integer, the result will be a float or complex
0963: since roots are generally irrational. If b is an integer, the
0964: result will be rational.
0965: """
+0966: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None); if (__pyx_t_1) { /* … */ }
+0967: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
0968:
+0969: bn, bd = b.numerator, b.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_b), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 969, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_b), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 969, __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;
+0970: if bd == 1 and bn >= 0:
__pyx_t_4 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_bd, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 970, __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_mstate_global->__pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 970, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 970, __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) { /* … */ }
0971: # If a is an int, keep it that way if possible.
+0972: 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, 972, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0973:
+0974: if isinstance(a, int):
__pyx_t_1 = PyLong_Check(__pyx_v_a);
if (__pyx_t_1) {
/* … */
}
+0975: return _pow(a, 1, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_f_10quicktions__pow(__pyx_v_a, __pyx_mstate_global->__pyx_int_1, __pyx_v_bn, __pyx_v_bd); 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: 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_mstate_global->__pyx_ptype_10quicktions_Fraction); if (!__pyx_t_4) { } else { __pyx_t_1 = __pyx_t_4; goto __pyx_L9_bool_binop_done; } __pyx_t_4 = PyObject_IsInstance(__pyx_v_a, __pyx_t_3); __pyx_t_1 = __pyx_t_4; __pyx_L9_bool_binop_done:; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+0977: return _pow(a.numerator, a.denominator, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 977, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 977, __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, 977, __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;
0978:
+0979: if bd == 1:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_bd, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 979, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0980: 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, 980, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0981:
+0982: 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, 982, __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, 982, __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;
0983:
+0984: 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; }
0985: """+a: Coerces a subclass instance to Fraction"""
+0986: if type(a) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_a))) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+0987: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_a); __pyx_r = ((PyObject *)__pyx_v_a); goto __pyx_L0;
+0988: 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, 988, __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;
0989:
+0990: 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; }
0991: """-a"""
+0992: 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, 992, __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, 992, __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;
0993:
+0994: 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; }
0995: """abs(a)"""
+0996: 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, 996, __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, 996, __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;
0997:
+0998: 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_XDECREF(__pyx_t_6); __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; }
0999: """int(a)"""
+1000: if a._numerator < 0:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1000, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1000, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1001: return _operator_index(-(-a._numerator // a._denominator))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_10quicktions__operator_index); __pyx_t_4 = __pyx_v_10quicktions__operator_index; __pyx_t_5 = PyNumber_Negative(__pyx_v_a->_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyNumber_FloorDivide(__pyx_t_5, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyNumber_Negative(__pyx_t_6); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_5}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1002: else:
+1003: return _operator_index(a._numerator // a._denominator)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_10quicktions__operator_index); __pyx_t_5 = __pyx_v_10quicktions__operator_index; __pyx_t_3 = PyNumber_FloorDivide(__pyx_v_a->_numerator, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1003, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); assert(__pyx_t_4); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_5, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_3}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1003, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
1004:
+1005: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__trunc__", __pyx_kwds); 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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_65__trunc__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___trunc, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[10])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1005, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_trunc, __pyx_t_3) < 0) __PYX_ERR(0, 1005, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1006: """math.trunc(a)"""
+1007: if a._numerator < 0:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1007, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1007, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1008: 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, 1008, __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, 1008, __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, 1008, __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;
1009: else:
+1010: 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, 1010, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; }
1011:
+1012: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__floor__", __pyx_kwds); 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_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_67__floor__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___floor, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[11])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1012, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_floor, __pyx_t_3) < 0) __PYX_ERR(0, 1012, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1013: """math.floor(a)"""
+1014: return a.numerator // a.denominator
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1014, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1014, __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, 1014, __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;
1015:
+1016: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__ceil__", __pyx_kwds); 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_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_69__ceil__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___ceil, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[12])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1016, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_ceil, __pyx_t_3) < 0) __PYX_ERR(0, 1016, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1017: """math.ceil(a)"""
1018: # The negations cleverly convince floordiv to return the ceiling.
+1019: return -(-a.numerator // a.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1019, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1019, __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_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1019, __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, 1019, __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, 1019, __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;
1020:
+1021: 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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_ndigits,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 1021, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1021, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__round__", 0) < 0) __PYX_ERR(0, 1021, __pyx_L3_error) if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)Py_None)); } else { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1021, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } if (!values[0]) values[0] = __Pyx_NewRef(((PyObject *)Py_None)); } __pyx_v_ndigits = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__round__", 0, 0, 1, __pyx_nargs); __PYX_ERR(0, 1021, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_10); __Pyx_XDECREF(__pyx_t_11); __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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_71__round__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___round, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[13])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1021, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_3, __pyx_mstate_global->__pyx_tuple[1]); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_round_2, __pyx_t_3) < 0) __PYX_ERR(0, 1021, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1022: """round(self, ndigits)
1023:
1024: Rounds half toward even.
1025: """
+1026: if ndigits is None:
__pyx_t_1 = (__pyx_v_ndigits == Py_None); if (__pyx_t_1) { /* … */ }
+1027: floor, remainder = divmod(self.numerator, self.denominator)
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1027, __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, 1027, __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, 1027, __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_INCREF(__pyx_t_3); __pyx_t_2 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_2); } else { __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1027, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); } #else __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1027, __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, 1027, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_6 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 1027, __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, 1027, __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;
+1028: if remainder * 2 < self.denominator:
__pyx_t_4 = __Pyx_PyLong_MultiplyObjC(__pyx_v_remainder, __pyx_mstate_global->__pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1028, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1028, __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, 1028, __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, 1028, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+1029: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
+1030: elif remainder * 2 > self.denominator:
__pyx_t_3 = __Pyx_PyLong_MultiplyObjC(__pyx_v_remainder, __pyx_mstate_global->__pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1030, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1030, __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, 1030, __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, 1030, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1031: return floor + 1
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyLong_AddObjC(__pyx_v_floor, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1031, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1032: # Deal with the half case:
+1033: elif floor % 2 == 0:
__pyx_t_4 = __Pyx_PyLong_RemainderObjC(__pyx_v_floor, __pyx_mstate_global->__pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1033, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_t_4, __pyx_mstate_global->__pyx_int_0, 0, 0)); 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
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
1035: else:
+1036: return floor + 1
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyLong_AddObjC(__pyx_v_floor, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1036, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1037: shift = pow10(abs(<long long>ndigits))
__pyx_t_7 = __Pyx_PyLong_As_PY_LONG_LONG(__pyx_v_ndigits); if (unlikely((__pyx_t_7 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 1037, __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, 1037, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_shift = __pyx_t_4; __pyx_t_4 = 0;
1038: # See _operator_fallbacks.forward to check that the results of
1039: # these operations will always be Fraction and therefore have
1040: # round().
+1041: if ndigits > 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_ndigits, __pyx_mstate_global->__pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1041, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1041, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1042: return Fraction(round(self * shift), shift)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = NULL; __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_3 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_9 = NULL; __Pyx_INCREF(__pyx_builtin_round); __pyx_t_10 = __pyx_builtin_round; __pyx_t_11 = PyNumber_Multiply(((PyObject *)__pyx_v_self), __pyx_v_shift); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1042, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __pyx_t_12 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_t_11}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_10, __pyx_callargs+__pyx_t_12, (2-__pyx_t_12) | (__pyx_t_12*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1042, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_t_12 = 1; { PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_t_5, __pyx_v_shift}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_12, (3-__pyx_t_12) | (__pyx_t_12*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1042, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_4); } __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0;
1043: else:
+1044: return Fraction(round(self / shift) * shift)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_3 = NULL; __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_5 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_10 = NULL; __Pyx_INCREF(__pyx_builtin_round); __pyx_t_11 = __pyx_builtin_round; __pyx_t_9 = __Pyx_PyNumber_Divide(((PyObject *)__pyx_v_self), __pyx_v_shift); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_12 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_10, __pyx_t_9}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_11, __pyx_callargs+__pyx_t_12, (2-__pyx_t_12) | (__pyx_t_12*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_11 = PyNumber_Multiply(__pyx_t_2, __pyx_v_shift); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_11); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_12 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_11}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_12, (2-__pyx_t_12) | (__pyx_t_12*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1044, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_4); } __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0; }
1045:
+1046: 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; }
1047: """float(self) = self.numerator / self.denominator
1048:
1049: It's important that this conversion use the integer's "true"
1050: division rather than casting one side to float before dividing
1051: so that ratios of huge integers convert without overflowing.
1052: """
+1053: return _as_float(self.numerator, self.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1053, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1053, __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, 1053, __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;
1054:
1055: # Concrete implementations of Complex abstract methods.
+1056: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__complex__", __pyx_kwds); 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_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_AddTraceback("quicktions.Fraction.__complex__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* … */ __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_75__complex__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___complex, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[14])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_complex, __pyx_t_3) < 0) __PYX_ERR(0, 1056, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1057: """complex(self) == complex(float(self), 0)"""
+1058: return complex(float(self))
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = NULL; __Pyx_INCREF((PyObject *)(&PyComplex_Type)); __pyx_t_3 = ((PyObject *)(&PyComplex_Type)); __pyx_t_4 = __Pyx_PyNumber_Float(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1058, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_4}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1058, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1059:
1060: # == +self
+1061: real = property(__pos__, doc="Real numbers are their real component.")
__pyx_t_5 = NULL; __Pyx_INCREF(__pyx_builtin_property); __pyx_t_7 = __pyx_builtin_property; __Pyx_GetNameInClass(__pyx_t_6, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_pos); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1061, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = 1; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_5, __pyx_t_6}; __pyx_t_2 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1061, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (__Pyx_VectorcallBuilder_AddArg(__pyx_mstate_global->__pyx_n_u_doc, __pyx_mstate_global->__pyx_kp_u_Real_numbers_are_their_real_comp, __pyx_t_2, __pyx_callargs+2, 0) < 0) __PYX_ERR(0, 1061, __pyx_L1_error) __pyx_t_3 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_7, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2); __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1061, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_real, __pyx_t_3) < 0) __PYX_ERR(0, 1061, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1062:
1063: # == 0
+1064: @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; }
1065: def imag(self):
1066: "Real numbers have no imaginary component."
+1067: return 0
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_mstate_global->__pyx_int_0); __pyx_r = __pyx_mstate_global->__pyx_int_0; goto __pyx_L0;
1068:
+1069: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("conjugate", __pyx_kwds); 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_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_77conjugate, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction_conjugate, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[15])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1069, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_conjugate, __pyx_t_3) < 0) __PYX_ERR(0, 1069, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1070: """Conjugate is a no-op for Reals."""
+1071: return +self
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Positive(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1071, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1072:
+1073: 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; }
1074: """hash(self)"""
+1075: if self._hash != -1:
__pyx_t_1 = (__pyx_v_self->_hash != -1L); if (__pyx_t_1) { /* … */ }
+1076: return self._hash
__pyx_r = __pyx_v_self->_hash; goto __pyx_L0;
1077:
1078: cdef Py_hash_t result
1079:
1080: # In order to make sure that the hash of a Fraction agrees
1081: # with the hash of a numerically equal integer, float or
1082: # Decimal instance, we follow the rules for numeric hashes
1083: # outlined in the documentation. (See library docs, 'Built-in
1084: # Types').
1085:
+1086: if PY_VERSION_HEX < 0x030800B1:
__pyx_t_1 = (PY_VERSION_HEX < 0x030800B1); if (__pyx_t_1) { /* … */ goto __pyx_L4; }
1087: # dinv is the inverse of self._denominator modulo the prime
1088: # _PyHASH_MODULUS, or 0 if self._denominator is divisible by
1089: # _PyHASH_MODULUS.
+1090: 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_PyLong_FromHash_t((__pyx_v_10quicktions__PyHASH_MODULUS - 2)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1090, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyLong_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1090, __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, 1090, __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;
+1091: if not dinv:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_dinv); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1091, __pyx_L1_error) __pyx_t_6 = (!__pyx_t_1); if (__pyx_t_6) { /* … */ goto __pyx_L5; }
+1092: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF;
1093: else:
+1094: 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, 1094, __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, 1094, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyLong_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1094, __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, 1094, __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_PyLong_AsHash_t(__pyx_t_3); if (unlikely((__pyx_t_7 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1094, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_result = __pyx_t_7; } __pyx_L5:;
1095: else:
1096: # Py3.8+
+1097: 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:;
+1098: dinv = pow(self._denominator, -1, _PyHASH_MODULUS)
__pyx_t_3 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyLong_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1098, __pyx_L6_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Power(__pyx_t_3, __pyx_mstate_global->__pyx_int_neg_1, __pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1098, __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;
+1099: 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, 1099, __pyx_L8_except_error) __Pyx_XGOTREF(__pyx_t_5); __Pyx_XGOTREF(__pyx_t_4); __Pyx_XGOTREF(__pyx_t_3);
1100: # ValueError means there is no modular inverse.
+1101: 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;
1102: else:
1103: # The general algorithm now specifies that the absolute value of
1104: # the hash is
1105: # (|N| * dinv) % P
1106: # where N is self._numerator and P is _PyHASH_MODULUS. That's
1107: # optimized here in two ways: first, for a non-negative int i,
1108: # hash(i) == i % P, but the int hash implementation doesn't need
1109: # to divide, and is faster than doing % P explicitly. So we do
1110: # hash(|N| * dinv)
1111: # instead. Second, N is unbounded, so its product with dinv may
1112: # be arbitrarily expensive to compute. The final answer is the
1113: # same if we use the bounded |N| % P instead, which can again
1114: # be done with an int hash() call. If 0 <= i < P, hash(i) == i,
1115: # so this nested hash() call wastes a bit of time making a
1116: # redundant copy when |N| < P, but can save an arbitrarily large
1117: # amount of computation for large |N|.
+1118: 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, 1118, __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, 1118, __pyx_L8_except_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __pyx_t_4 = __Pyx_PyLong_FromHash_t(__pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1118, __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, 1118, __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, 1118, __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;
1119:
+1120: if self._numerator < 0:
__pyx_t_3 = PyObject_RichCompare(__pyx_v_self->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1120, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 1120, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_6) { /* … */ }
+1121: result = -result
__pyx_v_result = (-__pyx_v_result);
+1122: if result == -1:
__pyx_t_6 = (__pyx_v_result == -1L); if (__pyx_t_6) { /* … */ }
+1123: result = -2
__pyx_v_result = -2L;
+1124: self._hash = result
__pyx_v_self->_hash = __pyx_v_result;
+1125: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
1126:
+1127: 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; }
+1128: if isinstance(a, Fraction):
__pyx_t_1 = __Pyx_TypeCheck(((PyObject *)__pyx_v_a), __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1129: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ); if (__pyx_t_1) { /* … */ }
+1130: 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, 1130, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1131: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE); if (__pyx_t_1) { /* … */ }
+1132: 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, 1132, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0;
+1133: 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, 1133, __pyx_L1_error) __pyx_t_4 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1133, __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;
1134: else:
+1135: a, b = b, a
/*else*/ { __pyx_t_2 = __pyx_v_b; __Pyx_INCREF(__pyx_t_2); if (!(likely(((__pyx_t_2) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_2, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction))))) __PYX_ERR(0, 1135, __pyx_L1_error) __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;
+1136: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ); if (__pyx_t_1) { /* … */ }
+1137: 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, 1137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1138: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE); if (__pyx_t_1) { /* … */ }
+1139: 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, 1139, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_result = __pyx_t_4; __pyx_t_4 = 0;
+1140: 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, 1140, __pyx_L1_error) __pyx_t_2 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1140, __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;
+1141: elif op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1142: op = Py_GE
__pyx_v_op = Py_GE;
+1143: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1144: op = Py_LE
__pyx_v_op = Py_LE;
+1145: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1146: op = Py_GT
__pyx_v_op = Py_GT;
+1147: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE); if (__pyx_t_1) { /* … */ goto __pyx_L5; }
+1148: op = Py_LT
__pyx_v_op = Py_LT;
1149: else:
+1150: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; } __pyx_L5:; } __pyx_L3:;
+1151: 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, 1151, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1152:
+1153: @cython.final
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_2); __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __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; }
1154: cdef _eq(a, b):
+1155: if type(b) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)(&PyLong_Type))); if (__pyx_t_1) { /* … */ }
+1156: return a._numerator == b and a._denominator == 1
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_v_b, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1156, __pyx_L1_error) if (__pyx_t_1) { __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L4_bool_binop_done; } __pyx_t_3 = __Pyx_PyLong_EqObjC(__pyx_v_a->_denominator, __pyx_mstate_global->__pyx_int_1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1156, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_L4_bool_binop_done:; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1157: if type(b) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1158: return (a._numerator == (<Fraction>b)._numerator and
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_numerator, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1158, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1158, __pyx_L1_error) if (__pyx_t_1) { __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } else { __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L7_bool_binop_done; }
+1159: a._denominator == (<Fraction>b)._denominator)
__pyx_t_3 = PyObject_RichCompare(__pyx_v_a->_denominator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_b)->_denominator, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1159, __pyx_L1_error) __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_L7_bool_binop_done:; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1160: if isinstance(b, Rational):
__pyx_t_2 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = PyObject_IsInstance(__pyx_v_b, __pyx_t_2); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 1160, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1161: return (a._numerator == b.numerator and
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyObject_RichCompare(__pyx_v_a->_numerator, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1161, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __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_2 = __pyx_t_4; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L10_bool_binop_done; }
+1162: a._denominator == b.denominator)
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1162, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyObject_RichCompare(__pyx_v_a->_denominator, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1162, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_INCREF(__pyx_t_3); __pyx_t_2 = __pyx_t_3; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_L10_bool_binop_done:; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1163: if isinstance(b, Complex) and b.imag == 0:
__pyx_t_2 = __pyx_v_10quicktions_Complex; __Pyx_INCREF(__pyx_t_2); __pyx_t_5 = PyObject_IsInstance(__pyx_v_b, __pyx_t_2); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 1163, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_5) { } else { __pyx_t_1 = __pyx_t_5; goto __pyx_L13_bool_binop_done; } __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_imag); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1163, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = (__Pyx_PyLong_BoolEqObjC(__pyx_t_2, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1163, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = __pyx_t_5; __pyx_L13_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+1164: b = b.real
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_real); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1164, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_2); __pyx_t_2 = 0;
+1165: if isinstance(b, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1166: if math.isnan(b) or math.isinf(b):
__pyx_t_3 = __pyx_v_10quicktions_math; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isnan, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1166, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!__pyx_t_5) { } else { __pyx_t_1 = __pyx_t_5; goto __pyx_L17_bool_binop_done; } __pyx_t_3 = __pyx_v_10quicktions_math; __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isinf, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1166, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = __pyx_t_5; __pyx_L17_bool_binop_done:; if (__pyx_t_1) { /* … */ }
1167: # comparisons with an infinity or nan should behave in
1168: # the same way for any finite a, so treat a as zero.
+1169: return 0.0 == b
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyFloat_EqCObj(__pyx_mstate_global->__pyx_float_0_0, __pyx_v_b, 0.0, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1169, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1170: else:
+1171: return a == a.from_float(b)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_3 = ((PyObject *)__pyx_v_a); __Pyx_INCREF(__pyx_t_3); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_from_float, __pyx_callargs+__pyx_t_6, (2-__pyx_t_6) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_3 = PyObject_RichCompare(((PyObject *)__pyx_v_a), __pyx_t_2, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1171, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0; }
+1172: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
1173:
+1174: @cython.final
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_2); __Pyx_XDECREF(__pyx_t_3); __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; }
1175: cdef _richcmp(self, other, int op):
1176: """Helper for comparison operators, for internal use only.
1177:
1178: Implement comparison between a Rational instance `self`, and
1179: either another Rational instance or a float `other`. If
1180: `other` is not a Rational instance or a float, return
1181: NotImplemented. `op` should be one of the six standard
1182: comparison operators.
1183:
1184: """
1185: # convert other to a Rational instance where reasonable.
+1186: if isinstance(other, int):
__pyx_t_1 = PyLong_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1187: a = self._numerator
__pyx_t_2 = __pyx_v_self->_numerator;
__Pyx_INCREF(__pyx_t_2);
__pyx_v_a = __pyx_t_2;
__pyx_t_2 = 0;
+1188: b = self._denominator * other
__pyx_t_2 = PyNumber_Multiply(__pyx_v_self->_denominator, __pyx_v_other); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1188, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
+1189: elif type(other) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_other)) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1190: a = self._numerator * (<Fraction>other)._denominator
__pyx_t_2 = PyNumber_Multiply(__pyx_v_self->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_other)->_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1190, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_a = __pyx_t_2; __pyx_t_2 = 0;
+1191: b = self._denominator * (<Fraction>other)._numerator
__pyx_t_2 = PyNumber_Multiply(__pyx_v_self->_denominator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_other)->_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1191, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
+1192: elif isinstance(other, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1193: if math.isnan(other) or math.isinf(other):
__pyx_t_3 = __pyx_v_10quicktions_math; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_other}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isnan, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1193, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (!__pyx_t_5) { } else { __pyx_t_1 = __pyx_t_5; goto __pyx_L5_bool_binop_done; } __pyx_t_3 = __pyx_v_10quicktions_math; __Pyx_INCREF(__pyx_t_3); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_other}; __pyx_t_2 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_isinf, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1193, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = __pyx_t_5; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* … */ goto __pyx_L4; }
+1194: a, b = 0.0, other # Comparison to 0.0 is just as good as any.
__pyx_t_2 = __pyx_mstate_global->__pyx_float_0_0; __Pyx_INCREF(__pyx_t_2); __pyx_t_3 = __pyx_v_other; __Pyx_INCREF(__pyx_t_3); __pyx_v_a = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_b = __pyx_t_3; __pyx_t_3 = 0;
1195: else:
+1196: return self._richcmp(self.from_float(other), op)
/*else*/ { __Pyx_XDECREF(__pyx_r); __pyx_t_2 = ((PyObject *)__pyx_v_self); __Pyx_INCREF(__pyx_t_2); __pyx_t_4 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_other}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_from_float, __pyx_callargs+__pyx_t_4, (2-__pyx_t_4) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_t_2 = __pyx_f_10quicktions_8Fraction__richcmp(__pyx_v_self, __pyx_t_3, __pyx_v_op); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1196, __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; } __pyx_L4:;
+1197: elif isinstance(other, (Fraction, Rational)):
__Pyx_INCREF(__pyx_v_10quicktions_Rational); __pyx_t_2 = __pyx_v_10quicktions_Rational; __pyx_t_5 = __Pyx_TypeCheck(__pyx_v_other, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); if (!__pyx_t_5) { } else { __pyx_t_1 = __pyx_t_5; goto __pyx_L7_bool_binop_done; } __pyx_t_5 = PyObject_IsInstance(__pyx_v_other, __pyx_t_2); __pyx_t_1 = __pyx_t_5; __pyx_L7_bool_binop_done:; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1198: a = self._numerator * other.denominator
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_Multiply(__pyx_v_self->_numerator, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1198, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_a = __pyx_t_3; __pyx_t_3 = 0;
+1199: b = self._denominator * other.numerator
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_other, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1199, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_Multiply(__pyx_v_self->_denominator, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1199, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
1200: else:
1201: # comparisons with complex should raise a TypeError, for consistency
1202: # with int<->complex, float<->complex, and complex<->complex comparisons.
+1203: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; } __pyx_L3:;
1204:
+1205: if op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT); if (__pyx_t_1) { /* … */ }
+1206: return a < b
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1206, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1207: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT); if (__pyx_t_1) { /* … */ }
+1208: return a > b
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1208, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1209: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE); if (__pyx_t_1) { /* … */ }
+1210: return a <= b
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1210, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1211: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE); if (__pyx_t_1) { /* … */ }
+1212: return a >= b
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyObject_RichCompare(__pyx_v_a, __pyx_v_b, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1212, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1213: else:
+1214: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1215:
+1216: 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; }
1217: """a != 0"""
1218: # Use bool() because (a._numerator != 0) can return an
1219: # object which is not a bool.
1220: # See https://bugs.python.org/issue39274
+1221: return bool(self._numerator)
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->_numerator); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1221, __pyx_L1_error) __pyx_r = (!(!__pyx_t_1)); goto __pyx_L0;
1222:
1223: # support for pickling, copy, and deepcopy
1224:
+1225: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__reduce__", __pyx_kwds); 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_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_85__reduce__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___reduce, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[16])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1225, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_reduce, __pyx_t_3) < 0) __PYX_ERR(0, 1225, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1226: 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, 1226, __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) != (0)) __PYX_ERR(0, 1226, __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) != (0)) __PYX_ERR(0, 1226, __pyx_L1_error); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1226, __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)))) != (0)) __PYX_ERR(0, 1226, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 1226, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1227:
+1228: 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(*)(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_SIZE __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; } const Py_ssize_t __pyx_kwds_len = unlikely(__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len < 0)) return NULL; if (unlikely(__pyx_kwds_len > 0)) {__Pyx_RejectKeywords("__copy__", __pyx_kwds); 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_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_87__copy__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___copy, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[17])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1228, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_copy, __pyx_t_3) < 0) __PYX_ERR(0, 1228, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1229: if type(self) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1230: 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;
+1231: return type(self)(self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = NULL; __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __pyx_t_4 = ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))); __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_v_self->_numerator, __pyx_v_self->_denominator}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (3-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1231, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1232:
+1233: 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(*)(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_SIZE __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 ** const __pyx_pyargnames[] = {&__pyx_mstate_global->__pyx_n_u_memo,0}; PyObject* values[1] = {0}; const Py_ssize_t __pyx_kwds_len = (__pyx_kwds) ? __Pyx_NumKwargs_FASTCALL(__pyx_kwds) : 0; if (unlikely(__pyx_kwds_len) < 0) __PYX_ERR(0, 1233, __pyx_L3_error) if (__pyx_kwds_len > 0) { switch (__pyx_nargs) { case 1: values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1233, __pyx_L3_error) CYTHON_FALLTHROUGH; case 0: break; default: goto __pyx_L5_argtuple_error; } const Py_ssize_t kwd_pos_args = __pyx_nargs; if (__Pyx_ParseKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values, kwd_pos_args, __pyx_kwds_len, "__deepcopy__", 0) < 0) __PYX_ERR(0, 1233, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("__deepcopy__", 1, 1, 1, i); __PYX_ERR(0, 1233, __pyx_L3_error) } } } else if (unlikely(__pyx_nargs != 1)) { goto __pyx_L5_argtuple_error; } else { values[0] = __Pyx_ArgRef_FASTCALL(__pyx_args, 0); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[0])) __PYX_ERR(0, 1233, __pyx_L3_error) } __pyx_v_memo = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__deepcopy__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 1233, __pyx_L3_error) __pyx_L6_skip:; goto __pyx_L4_argument_unpacking_done; __pyx_L3_error:; for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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 */ for (Py_ssize_t __pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { Py_XDECREF(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_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_10quicktions_8Fraction_89__deepcopy__, __Pyx_CYFUNCTION_CCLASS, __pyx_mstate_global->__pyx_n_u_Fraction___deepcopy, NULL, __pyx_mstate_global->__pyx_n_u_quicktions, __pyx_mstate_global->__pyx_d, ((PyObject *)__pyx_mstate_global->__pyx_codeobj_tab[18])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_deepcopy, __pyx_t_3) < 0) __PYX_ERR(0, 1233, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1234: if type(self) is Fraction:
__pyx_t_1 = (((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_1) { /* … */ }
+1235: 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;
+1236: return type(self)(self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = NULL; __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); __pyx_t_4 = ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))); __pyx_t_5 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_5 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_v_self->_numerator, __pyx_v_self->_denominator}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_5, (3-__pyx_t_5) | (__pyx_t_5*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1236, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1237:
1238:
1239: # Register with Python's numerical tower.
+1240: Rational.register(Fraction)
__pyx_t_7 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_7); __pyx_t_8 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_7, ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_register, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1241:
1242:
+1243: 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_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; };
1244: """Convert a pair of ints to a rational number, for internal use.
1245:
1246: The ratio of integers should be in lowest terms and the denominator
1247: should be positive.
1248: """
1249: cdef Fraction obj
+1250: 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_mstate_global->__pyx_ptype_10quicktions_Fraction)); __pyx_t_1 = __pyx_t_2; __pyx_L4_bool_binop_done:; if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+1251: obj = Fraction.__new__(Fraction, NOINIT, NOINIT)
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1251, __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) != (0)) __PYX_ERR(0, 1251, __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) != (0)) __PYX_ERR(0, 1251, __pyx_L1_error); __pyx_t_4 = ((PyObject *)__pyx_tp_new_10quicktions_Fraction(((PyTypeObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction), __pyx_t_3, NULL)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1251, __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;
1252: else:
+1253: obj = cls.__new__(cls)
/*else*/ { __pyx_t_3 = __pyx_v_cls; __Pyx_INCREF(__pyx_t_3); __pyx_t_5 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_v_cls}; __pyx_t_4 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_new, __pyx_callargs+__pyx_t_5, (2-__pyx_t_5) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1253, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction))))) __PYX_ERR(0, 1253, __pyx_L1_error) __pyx_v_obj = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_4); __pyx_t_4 = 0; } __pyx_L3:;
+1254: 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;
+1255: 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;
+1256: return obj
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_obj); __pyx_r = ((PyObject *)__pyx_v_obj); goto __pyx_L0;
1257:
1258:
+1259: 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_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions._pow", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1260: if bd == 1:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_bd, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1260, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
1261: # power = bn
+1262: if bn >= 0:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_bn, __pyx_mstate_global->__pyx_int_0, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1262, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1262, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1263: 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, 1263, __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;
+1264: an ** bn,
__pyx_t_2 = PyNumber_Power(__pyx_v_an, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1264, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+1265: ad ** bn)
__pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1265, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+1266: elif an > 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_an, __pyx_mstate_global->__pyx_int_0, Py_GT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1266, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1266, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1267: 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, 1267, __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;
+1268: ad ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1268, __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, 1268, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1269: an ** -bn)
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1269, __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, 1269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1270: elif an == 0:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_an, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1270, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1271: raise ZeroDivisionError(f'Fraction({ad ** -bn}, 0)')
__pyx_t_2 = NULL; __Pyx_INCREF(__pyx_builtin_ZeroDivisionError); __pyx_t_3 = __pyx_builtin_ZeroDivisionError; __pyx_t_5 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyNumber_Power(__pyx_v_ad, __pyx_t_5, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_7[0] = __pyx_mstate_global->__pyx_kp_u_Fraction; __pyx_t_7[1] = __pyx_t_5; __pyx_t_7[2] = __pyx_mstate_global->__pyx_kp_u_0; __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_7, 3, 9 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5) + 4, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_8 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_t_6}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1271, __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, 1271, __pyx_L1_error)
1272: else:
+1273: return _fraction_from_coprime_ints(
/*else*/ { __Pyx_XDECREF(__pyx_r); /* … */ __pyx_t_4 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_6, __pyx_t_2, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1273, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0; }
+1274: (-ad) ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1274, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1274, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = PyNumber_Power(__pyx_t_4, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1274, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1275: (-an) ** -bn)
__pyx_t_3 = PyNumber_Negative(__pyx_v_an); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Power(__pyx_t_3, __pyx_t_4, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1275, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
1276: else:
1277: # A fractional power will generally produce an
1278: # irrational number.
+1279: 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, 1279, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = __Pyx_PyNumber_Divide(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1279, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_6 = PyNumber_Power(__pyx_t_4, __pyx_t_2, Py_None); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1279, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0; }
1280:
1281:
+1282: 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; }
+1283: 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, 1283, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1284:
1285:
1286: # Rational arithmetic algorithms: Knuth, TAOCP, Volume 2, 4.5.1.
1287: #
1288: # Assume input fractions a and b are normalized.
1289: #
1290: # 1) Consider addition/subtraction.
1291: #
1292: # Let g = gcd(da, db). Then
1293: #
1294: # na nb na*db ± nb*da
1295: # a ± b == -- ± -- == ------------- ==
1296: # da db da*db
1297: #
1298: # na*(db//g) ± nb*(da//g) t
1299: # == ----------------------- == -
1300: # (da*db)//g d
1301: #
1302: # Now, if g > 1, we're working with smaller integers.
1303: #
1304: # Note, that t, (da//g) and (db//g) are pairwise coprime.
1305: #
1306: # Indeed, (da//g) and (db//g) share no common factors (they were
1307: # removed) and da is coprime with na (since input fractions are
1308: # normalized), hence (da//g) and na are coprime. By symmetry,
1309: # (db//g) and nb are coprime too. Then,
1310: #
1311: # gcd(t, da//g) == gcd(na*(db//g), da//g) == 1
1312: # gcd(t, db//g) == gcd(nb*(da//g), db//g) == 1
1313: #
1314: # Above allows us optimize reduction of the result to lowest
1315: # terms. Indeed,
1316: #
1317: # g2 = gcd(t, d) == gcd(t, (da//g)*(db//g)*g) == gcd(t, g)
1318: #
1319: # t//g2 t//g2
1320: # a ± b == ----------------------- == ----------------
1321: # (da//g)*(db//g)*(g//g2) (da//g)*(db//g2)
1322: #
1323: # is a normalized fraction. This is useful because the unnormalized
1324: # denominator d could be much larger than g.
1325: #
1326: # We should special-case g == 1 (and g2 == 1), since 60.8% of
1327: # randomly-chosen integers are coprime:
1328: # https://en.wikipedia.org/wiki/Coprime_integers#Probability_of_coprimality
1329: # Note, that g2 == 1 always for fractions, obtained from floats: here
1330: # g is a power of 2 and the unnormalized numerator t is an odd integer.
1331: #
1332: # 2) Consider multiplication
1333: #
1334: # Let g1 = gcd(na, db) and g2 = gcd(nb, da), then
1335: #
1336: # na*nb na*nb (na//g1)*(nb//g2)
1337: # a*b == ----- == ----- == -----------------
1338: # da*db db*da (db//g1)*(da//g2)
1339: #
1340: # Note, that after divisions we're multiplying smaller integers.
1341: #
1342: # Also, the resulting fraction is normalized, because each of
1343: # two factors in the numerator is coprime to each of the two factors
1344: # in the denominator.
1345: #
1346: # Indeed, pick (na//g1). It's coprime with (da//g2), because input
1347: # fractions are normalized. It's also coprime with (db//g1), because
1348: # common factors are removed by g1 == gcd(na, db).
1349: #
1350: # As for addition/subtraction, we should special-case g1 == 1
1351: # and g2 == 1 for same reason. That happens also for multiplying
1352: # rationals, obtained from floats.
1353:
+1354: 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; }
1355: """a + b"""
1356: # return Fraction(na * db + nb * da, da * db)
+1357: 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, 1357, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1358: if g == 1:
__pyx_t_2 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1358, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1359: 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, 1359, __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, 1359, __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, 1359, __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, 1359, __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, 1359, __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;
+1360: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1360, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1361: 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, 1361, __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, 1361, __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, 1361, __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, 1361, __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;
+1362: 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, 1362, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g2 = __pyx_t_4; __pyx_t_4 = 0;
+1363: if g2 == 1:
__pyx_t_2 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1363, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1364: 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, 1364, __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, 1364, __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;
+1365: 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, 1365, __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, 1365, __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, 1365, __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, 1365, __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;
1366:
+1367: 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; }
1368: """a - b"""
1369: # return Fraction(na * db - nb * da, da * db)
+1370: 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, 1370, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1371: if g == 1:
__pyx_t_2 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1371, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1372: 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, 1372, __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, 1372, __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, 1372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Multiply(__pyx_v_da, __pyx_v_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1372, __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, 1372, __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;
+1373: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1373, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1374: 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, 1374, __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, 1374, __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, 1374, __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, 1374, __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;
+1375: 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, 1375, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_g2 = __pyx_t_4; __pyx_t_4 = 0;
+1376: if g2 == 1:
__pyx_t_2 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1376, __pyx_L1_error) if (__pyx_t_2) { /* … */ }
+1377: 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, 1377, __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, 1377, __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;
+1378: 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, 1378, __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, 1378, __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, 1378, __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, 1378, __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;
1379:
+1380: 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; }
1381: """a * b"""
1382: # return Fraction(na * nb, da * db)
+1383: 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, 1383, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g1 = __pyx_t_1; __pyx_t_1 = 0;
+1384: if g1 > 1:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_g1, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1384, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1384, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1385: na //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_1); __pyx_t_1 = 0;
+1386: db //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1386, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_1); __pyx_t_1 = 0;
+1387: 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, 1387, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_g2 = __pyx_t_1; __pyx_t_1 = 0;
+1388: if g2 > 1:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1388, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1388, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1389: nb //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_1); __pyx_t_1 = 0;
+1390: da //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1390, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_1); __pyx_t_1 = 0;
+1391: 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, 1391, __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, 1391, __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, 1391, __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;
1392:
+1393: 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_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __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; }
1394: """a / b"""
1395: # return Fraction(na * db, da * nb)
1396: # Same as _mul(), with inversed b.
+1397: if nb == 0:
__pyx_t_1 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_nb, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1397, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1398: raise ZeroDivisionError(f'Fraction({db}, 0)')
__pyx_t_3 = NULL; __Pyx_INCREF(__pyx_builtin_ZeroDivisionError); __pyx_t_4 = __pyx_builtin_ZeroDivisionError; __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_db, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1398, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6[0] = __pyx_mstate_global->__pyx_kp_u_Fraction; __pyx_t_6[1] = __pyx_t_5; __pyx_t_6[2] = __pyx_mstate_global->__pyx_kp_u_0; __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_6, 3, 9 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5) + 4, 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1398, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_8 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_7}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1398, __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, 1398, __pyx_L1_error)
+1399: 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, 1399, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_g1 = __pyx_t_2; __pyx_t_2 = 0;
+1400: if g1 > 1:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_g1, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1400, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1400, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1401: na //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1401, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_2); __pyx_t_2 = 0;
+1402: nb //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1402, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_2); __pyx_t_2 = 0;
+1403: 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, 1403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1404: if g2 > 1:
__pyx_t_2 = PyObject_RichCompare(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1404, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1404, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1405: da //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1405, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_2); __pyx_t_2 = 0;
+1406: db //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1406, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_2); __pyx_t_2 = 0;
+1407: 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, 1407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = PyNumber_Multiply(__pyx_v_nb, __pyx_v_da); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_4; __pyx_t_4 = 0;
+1408: if d < 0:
__pyx_t_4 = PyObject_RichCompare(__pyx_v_d, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1408, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1408, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1409: n, d = -n, -d
__pyx_t_4 = PyNumber_Negative(__pyx_v_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Negative(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF_SET(__pyx_v_d, __pyx_t_2); __pyx_t_2 = 0;
+1410: 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, 1410, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1411:
+1412: 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; }
1413: """a // b -> int"""
+1414: 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, 1414, __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, 1414, __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, 1414, __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;
1415:
+1416: 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; }
+1417: 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, 1417, __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, 1417, __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, 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; 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, 1417, __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_INCREF(__pyx_t_2); __pyx_t_1 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_1); } else { __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1417, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1417, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); } #else __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1417, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1417, __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, 1417, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __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, 1417, __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, 1417, __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;
+1418: return div, Fraction(n_mod, ad * bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = NULL; __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_2 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_4 = PyNumber_Multiply(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_6 = 1; { PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_v_n_mod, __pyx_t_4}; __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1418, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_3); } __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1418, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_INCREF(__pyx_v_div); __Pyx_GIVEREF(__pyx_v_div); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_div) != (0)) __PYX_ERR(0, 1418, __pyx_L1_error); __Pyx_GIVEREF((PyObject *)__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, ((PyObject *)__pyx_t_3)) != (0)) __PYX_ERR(0, 1418, __pyx_L1_error); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1419:
+1420: 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_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_AddTraceback("quicktions._mod", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
+1421: return Fraction((an * bd) % (bn * ad), ad * bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = NULL; __Pyx_INCREF((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_3 = ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction); __pyx_t_4 = PyNumber_Multiply(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Multiply(__pyx_v_bn, __pyx_v_ad); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = PyNumber_Remainder(__pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = PyNumber_Multiply(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_7 = 1; { PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_t_6, __pyx_t_5}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1421, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_1); } __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;
1422:
1423:
1424: """
1425: In general, we want to implement the arithmetic operations so
1426: that mixed-mode operations either call an implementation whose
1427: author knew about the types of both arguments, or convert both
1428: to the nearest built in type and do the operation there. In
1429: Fraction, that means that we define __add__ and __radd__ as:
1430:
1431: def __add__(self, other):
1432: # Both types have numerators/denominator attributes,
1433: # so do the operation directly
1434: if isinstance(other, (int, Fraction)):
1435: return Fraction(self.numerator * other.denominator +
1436: other.numerator * self.denominator,
1437: self.denominator * other.denominator)
1438: # float and complex don't have those operations, but we
1439: # know about those types, so special case them.
1440: elif isinstance(other, float):
1441: return float(self) + other
1442: elif isinstance(other, complex):
1443: return complex(self) + other
1444: # Let the other type take over.
1445: return NotImplemented
1446:
1447: def __radd__(self, other):
1448: # radd handles more types than add because there's
1449: # nothing left to fall back to.
1450: if isinstance(other, Rational):
1451: return Fraction(self.numerator * other.denominator +
1452: other.numerator * self.denominator,
1453: self.denominator * other.denominator)
1454: elif isinstance(other, Real):
1455: return float(other) + float(self)
1456: elif isinstance(other, Complex):
1457: return complex(other) + complex(self)
1458: return NotImplemented
1459:
1460:
1461: There are 5 different cases for a mixed-type addition on
1462: Fraction. I'll refer to all of the above code that doesn't
1463: refer to Fraction, float, or complex as "boilerplate". 'r'
1464: will be an instance of Fraction, which is a subtype of
1465: Rational (r : Fraction <: Rational), and b : B <:
1466: Complex. The first three involve 'r + b':
1467:
1468: 1. If B <: Fraction, int, float, or complex, we handle
1469: that specially, and all is well.
1470: 2. If Fraction falls back to the boilerplate code, and it
1471: were to return a value from __add__, we'd miss the
1472: possibility that B defines a more intelligent __radd__,
1473: so the boilerplate should return NotImplemented from
1474: __add__. In particular, we don't handle Rational
1475: here, even though we could get an exact answer, in case
1476: the other type wants to do something special.
1477: 3. If B <: Fraction, Python tries B.__radd__ before
1478: Fraction.__add__. This is ok, because it was
1479: implemented with knowledge of Fraction, so it can
1480: handle those instances before delegating to Real or
1481: Complex.
1482:
1483: The next two situations describe 'b + r'. We assume that b
1484: didn't know about Fraction in its implementation, and that it
1485: uses similar boilerplate code:
1486:
1487: 4. If B <: Rational, then __radd_ converts both to the
1488: builtin rational type (hey look, that's us) and
1489: proceeds.
1490: 5. Otherwise, __radd__ tries to find the nearest common
1491: base ABC, and fall back to its builtin type. Since this
1492: class doesn't subclass a concrete type, there's no
1493: implementation to fall back to, so we need to try as
1494: hard as possible to return an actual value, or the user
1495: will get a TypeError.
1496: """
1497:
1498: cdef:
+1499: _math_op_add = operator.add
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_add); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1499, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_add); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_add, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1500: _math_op_sub = operator.sub
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_sub); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1500, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_sub); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_sub, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1501: _math_op_mul = operator.mul
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_mul); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1501, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_mul); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_mul, __pyx_t_3); __Pyx_GIVEREF(__pyx_t_3); __pyx_t_3 = 0;
+1502: _math_op_div = getattr(operator, 'div', operator.truediv) # Py2/3
__pyx_t_3 = __pyx_v_10quicktions_operator; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_truediv); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1502, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __Pyx_GetAttr3(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_div_2, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1502, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_div); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_div, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+1503: _math_op_truediv = operator.truediv
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_truediv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1503, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_truediv); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_truediv, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+1504: _math_op_floordiv = operator.floordiv
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_floordiv); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_floordiv); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_floordiv, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+1505: _math_op_mod = operator.mod
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_mod); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1505, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_mod); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_mod, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
+1506: _math_op_divmod = divmod
__pyx_t_2 = __Pyx_GetBuiltinName(__pyx_mstate_global->__pyx_n_u_divmod); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1506, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions__math_op_divmod); __Pyx_DECREF_SET(__pyx_v_10quicktions__math_op_divmod, __pyx_t_2); __Pyx_GIVEREF(__pyx_t_2); __pyx_t_2 = 0;
1507:
1508:
+1509: ctypedef object (*math_func)(an, ad, bn, bd)
typedef PyObject *(*__pyx_t_10quicktions_math_func)(PyObject *, PyObject *, PyObject *, PyObject *);
1510:
1511:
+1512: 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; };
+1513: 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;
+1514: if type(b) is Fraction:
__pyx_t_3 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction)); if (__pyx_t_3) { /* … */ }
+1515: 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, 1515, __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;
+1516: elif isinstance(b, int):
__pyx_t_3 = PyLong_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1517: 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_mstate_global->__pyx_int_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1517, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1518: elif isinstance(b, Fraction):
__pyx_t_3 = __Pyx_TypeCheck(__pyx_v_b, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction);
if (__pyx_t_3) {
/* … */
}
+1519: return monomorphic_operator(an, ad, b.numerator, b.denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1519, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1519, __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, 1519, __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;
+1520: elif isinstance(b, float):
__pyx_t_3 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1521: return pyoperator(_as_float(an, ad), b)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_4 = __pyx_v_pyoperator; __pyx_t_5 = __pyx_f_10quicktions__as_float(__pyx_v_an, __pyx_v_ad); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1521, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_t_5, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1521, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1522: 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, 1522, __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) { /* … */ }
+1523: return pyoperator(float(a), b)
__Pyx_XDECREF(__pyx_r); __pyx_t_4 = NULL; __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_5 = __pyx_v_pyoperator; __pyx_t_1 = __Pyx_PyNumber_Float(__pyx_v_a); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1523, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_5))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); assert(__pyx_t_4); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_5); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_5, __pyx__function); __pyx_t_6 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_t_1, __pyx_v_b}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1523, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1524: else:
+1525: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1526:
1527:
+1528: 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_XDECREF(__pyx_t_9); __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; };
+1529: 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;
+1530: if isinstance(a, int):
__pyx_t_3 = PyLong_Check(__pyx_v_a);
if (__pyx_t_3) {
/* … */
}
+1531: return monomorphic_operator(a, 1, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __pyx_v_monomorphic_operator(__pyx_v_a, __pyx_mstate_global->__pyx_int_1, __pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1531, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1532: 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, 1532, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { /* … */ }
+1533: return monomorphic_operator(a.numerator, a.denominator, bn, bd)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1533, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1533, __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, 1533, __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;
+1534: 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, 1534, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_3) { /* … */ }
+1535: return pyoperator(float(a), _as_float(bn, bd))
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_2 = __pyx_v_pyoperator; __pyx_t_5 = __Pyx_PyNumber_Float(__pyx_v_a); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1535, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __pyx_f_10quicktions__as_float(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1535, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_2); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_2, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_t_5, __pyx_t_6}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1535, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1536: 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, 1536, __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, 1536, __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) { /* … */ }
+1537: return pyoperator(complex(a), float(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = NULL; __Pyx_INCREF(__pyx_v_pyoperator); __pyx_t_6 = __pyx_v_pyoperator; __pyx_t_1 = NULL; __Pyx_INCREF((PyObject *)(&PyComplex_Type)); __pyx_t_9 = ((PyObject *)(&PyComplex_Type)); __pyx_t_7 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_1, __pyx_v_a}; __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_t_9 = __Pyx_PyNumber_Float(__pyx_v_b); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_7 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_6))) { __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_6); assert(__pyx_t_2); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6); __Pyx_INCREF(__pyx_t_2); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_6, __pyx__function); __pyx_t_7 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_t_5, __pyx_t_9}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1537, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1538: else:
+1539: return NotImplemented
/*else*/ { __Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0; }
1540:
1541:
+1542: ctypedef char* charptr
typedef char *__pyx_t_10quicktions_charptr;
1543:
1544: ctypedef fused AnyString:
1545: unicode
1546: charptr
1547:
1548:
+1549: 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 };
1550: BEGIN_SPACE # '\s'* -> (BEGIN_SIGN, SMALL_NUM, START_DECIMAL_DOT)
1551: BEGIN_SIGN # [+-] -> (SMALL_NUM, SMALL_DECIMAL_DOT)
1552: SMALL_NUM # [0-9]+ -> (SMALL_NUM, SMALL_NUM_US, NUM, NUM_SPACE, SMALL_DECIMAL_DOT, EXP_E, DENOM_START)
1553: SMALL_NUM_US # '_' -> (SMALL_NUM, NUM)
1554: NUM # [0-9]+ -> (NUM, NUM_US, NUM_SPACE, DECIMAL_DOT, EXP_E, DENOM_START)
1555: NUM_US # '_' -> (NUM)
1556: NUM_SPACE # '\s'+ -> (DENOM_START)
1557:
1558: # 1) floating point syntax
1559: START_DECIMAL_DOT # '.' -> (SMALL_DECIMAL)
1560: SMALL_DECIMAL_DOT # '.' -> (SMALL_DECIMAL, EXP_E, SMALL_END_SPACE)
1561: DECIMAL_DOT # '.' -> (DECIMAL, EXP_E, END_SPACE)
1562: SMALL_DECIMAL # [0-9]+ -> (SMALL_DECIMAL, SMALL_DECIMAL_US, DECIMAL, EXP_E, SMALL_END_SPACE)
1563: SMALL_DECIMAL_US # '_' -> (SMALL_DECIMAL, DECIMAL)
1564: DECIMAL # [0-9]+ -> (DECIMAL, DECIMAL_US, EXP_E, END_SPACE)
1565: DECIMAL_US # '_' -> (DECIMAL)
1566: EXP_E # [eE] -> (EXP_SIGN, EXP)
1567: EXP_SIGN # [+-] -> (EXP)
1568: EXP # [0-9]+ -> (EXP_US, END_SPACE)
1569: EXP_US # '_' -> (EXP)
1570: END_SPACE # '\s'+
1571: SMALL_END_SPACE # '\s'+
1572:
1573: # 2) "NOM / DENOM" syntax
1574: DENOM_START # '/' -> (DENOM_SIGN, SMALL_DENOM)
1575: DENOM_SIGN # [+-] -> (SMALL_DENOM)
1576: SMALL_DENOM # [0-9]+ -> (SMALL_DENOM, SMALL_DENOM_US, DENOM, DENOM_SPACE)
1577: SMALL_DENOM_US # '_' -> (SMALL_DENOM)
1578: DENOM # [0-9]+ -> (DENOM, DENOM_US, DENOM_SPACE)
1579: DENOM_US # '_' -> (DENOM)
1580: DENOM_SPACE # '\s'+
1581:
1582:
+1583: 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_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __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; }
+1584: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1584, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1585: if s[:2] in ('b"', "b'"):
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 0, 2, NULL, NULL, &__pyx_mstate_global->__pyx_slice[0], 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_b_2, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1585, __pyx_L1_error) if (!__pyx_t_3) { } else { __pyx_t_2 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_b_3, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1585, __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_mstate_global->__pyx_slice[0] = PySlice_New(Py_None, __pyx_mstate_global->__pyx_int_2, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_slice[0])) __PYX_ERR(0, 1585, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[0]); /* … */ }
+1586: s = s[1:]
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 1, 0, NULL, NULL, &__pyx_mstate_global->__pyx_slice[1], 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0; /* … */ __pyx_mstate_global->__pyx_slice[1] = PySlice_New(__pyx_mstate_global->__pyx_int_1, Py_None, Py_None); if (unlikely(!__pyx_mstate_global->__pyx_slice[1])) __PYX_ERR(0, 1586, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[1]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[1]);
+1587: raise ValueError(f'Invalid literal for Fraction: {s}') from None
__pyx_t_4 = NULL; __Pyx_INCREF(__pyx_builtin_ValueError); __pyx_t_5 = __pyx_builtin_ValueError; __pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_v_s, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __Pyx_PyUnicode_Concat(__pyx_mstate_global->__pyx_kp_u_Invalid_literal_for_Fraction, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_8 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_7}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1587, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_Raise(__pyx_t_1, 0, 0, Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 1587, __pyx_L1_error)
1588:
1589:
+1590: 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_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __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; }
+1591: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1591, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1592: if s[0] == 'b':
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_s, 0, long, 1, __Pyx_PyLong_From_long, 0, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1592, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_b, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1592, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1593: s = s[1:]
__pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_s, 1, 0, NULL, NULL, &__pyx_mstate_global->__pyx_slice[1], 1, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1594: raise ValueError(f"Exponent too large for Fraction: {s}") from None
__pyx_t_3 = NULL; __Pyx_INCREF(__pyx_builtin_ValueError); __pyx_t_4 = __pyx_builtin_ValueError; __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_v_s, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_mstate_global->__pyx_kp_u_Exponent_too_large_for_Fraction, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_7 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_6}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_Raise(__pyx_t_1, 0, 0, Py_None); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __PYX_ERR(0, 1594, __pyx_L1_error)
1595:
1596:
1597: cdef extern from *:
1598: """
1599: static CYTHON_INLINE int __QUICKTIONS_unpack_ustring(
1600: PyObject* string, Py_ssize_t *length, void** data, int *kind) {
1601: if (PyUnicode_READY(string) < 0) return -1;
1602: *kind = PyUnicode_KIND(string);
1603: *length = PyUnicode_GET_LENGTH(string);
1604: *data = PyUnicode_DATA(string);
1605: return 0;
1606: }
1607: #define __QUICKTIONS_char_at(data, kind, index) \
1608: (((kind == 1) ? (Py_UCS4) ((char*) data)[index] : (Py_UCS4) PyUnicode_READ(kind, data, index)))
1609: """
1610: int _unpack_ustring "__QUICKTIONS_unpack_ustring" (
1611: object string, Py_ssize_t *length, void **data, int *kind) except -1
1612: Py_UCS4 _char_at "__QUICKTIONS_char_at" (void *data, int kind, Py_ssize_t index)
1613: Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)
1614:
1615:
+1616: 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; }
1617: cdef unsigned int unum
1618: cdef int num
+1619: 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'));
+1620: if unum > 9:
__pyx_t_1 = (__pyx_v_unum > 9); if (__pyx_t_1) { /* … */ }
+1621: if not allow_unicode:
__pyx_t_1 = (!(__pyx_v_allow_unicode != 0)); if (__pyx_t_1) { /* … */ }
+1622: return -1
__pyx_r = -1; goto __pyx_L0;
+1623: num = Py_UNICODE_TODECIMAL(c)
__pyx_v_num = Py_UNICODE_TODECIMAL(__pyx_v_c);
+1624: if num == -1:
__pyx_t_1 = (__pyx_v_num == -1L); if (__pyx_t_1) { /* … */ }
+1625: return -1
__pyx_r = -1; goto __pyx_L0;
+1626: unum = <unsigned int> num
__pyx_v_unum = ((unsigned int)__pyx_v_num);
+1627: c = <Py_UCS4> (num + c'0')
__pyx_v_c = ((Py_UCS4)(__pyx_v_num + '0'));
+1628: if c_digits:
__pyx_t_1 = (__pyx_v_c_digits != 0); if (__pyx_t_1) { /* … */ }
+1629: c_digits[0][0] = <char> c
((__pyx_v_c_digits[0])[0]) = ((char)__pyx_v_c);
+1630: c_digits[0] += 1
__pyx_t_2 = 0; (__pyx_v_c_digits[__pyx_t_2]) = ((__pyx_v_c_digits[__pyx_t_2]) + 1);
+1631: return <int> unum
__pyx_r = ((int)__pyx_v_unum); goto __pyx_L0;
1632:
1633:
+1634: 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; }
+1635: c_digits_end[0][0] = 0
((__pyx_v_c_digits_end[0])[0]) = 0;
+1636: 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, 1636, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_py_number = __pyx_t_1; __pyx_t_1 = 0;
+1637: c_digits_end[0] = c_digits_start # reset
(__pyx_v_c_digits_end[0]) = __pyx_v_c_digits_start;
+1638: return py_number
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_py_number); __pyx_r = __pyx_v_py_number; goto __pyx_L0;
1639:
1640:
+1641: @cython.cdivision(True)
static PyObject *__pyx_fuse_0__pyx_f_10quicktions__parse_fraction(PyObject *__pyx_v_s, Py_ssize_t __pyx_v_s_len, PyObject *__pyx_v_orig_str) { 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; int __pyx_v_is_normalised; 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_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, PyObject *__pyx_v_orig_str) { 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; int __pyx_v_is_normalised; PyObject *__pyx_r = NULL;
1642: cdef tuple _parse_fraction(AnyString s, Py_ssize_t s_len, orig_str):
1643: """
1644: Parse a string into a number tuple: (numerator, denominator, is_normalised)
1645: """
+1646: cdef Py_ssize_t pos, decimal_len = 0
__pyx_v_decimal_len = 0; /* … */ __pyx_v_decimal_len = 0;
1647: cdef Py_UCS4 c
+1648: cdef ParserState state = BEGIN_SPACE
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE;
1649:
+1650: 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;
1651: cdef int digit
1652: cdef unsigned int udigit
+1653: 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;
1654: cdef ullong igcd
+1655: cdef object num = None, decimal, denom
__Pyx_INCREF(Py_None); __pyx_v_num = Py_None; /* … */ __Pyx_INCREF(Py_None); __pyx_v_num = Py_None;
1656: # 2^n > 10^(n * 5/17)
+1657: 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);
1658:
1659: # Incremental Unicode iteration isn't in Cython yet.
+1660: cdef int allow_unicode = AnyString is unicode
__pyx_v_allow_unicode = 1; /* … */ __pyx_v_allow_unicode = 0;
+1661: cdef int s_kind = 1
__pyx_v_s_kind = 1; /* … */ __pyx_v_s_kind = 1;
+1662: cdef void* s_data = NULL
__pyx_v_s_data = NULL; /* … */ __pyx_v_s_data = NULL;
+1663: cdef char* cdata = NULL
__pyx_v_cdata = NULL; /* … */ __pyx_v_cdata = NULL;
1664:
1665: if AnyString is unicode:
+1666: _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, 1666, __pyx_L1_error)
+1667: if s_kind == 1:
__pyx_t_2 = (__pyx_v_s_kind == 1); if (__pyx_t_2) { /* … */ }
+1668: return _parse_fraction(<char*> s_data, s_len, orig_str)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __pyx_fuse_1__pyx_f_10quicktions__parse_fraction(((char *)__pyx_v_s_data), __pyx_v_s_len, __pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1668, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0;
+1669: cdata = <char*> s_data
__pyx_v_cdata = ((char *)__pyx_v_s_data);
+1670: cdata += 0 # mark used
__pyx_v_cdata = (__pyx_v_cdata + 0);
1671: else:
+1672: cdata = s
__pyx_v_cdata = __pyx_v_s;
1673:
1674: # We collect the digits in inum / idenum as long as the value fits their integer size
1675: # and additionally in a char* buffer in case it grows too large.
+1676: cdef bytes digits = b'\0' * s_len
__pyx_t_3 = __Pyx_PySequence_Multiply(__pyx_mstate_global->__pyx_kp_b__14, __pyx_v_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1676, __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_mstate_global->__pyx_kp_b__14, __pyx_v_s_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1676, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_digits = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1677: 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, 1677, __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, 1677, __pyx_L1_error) __pyx_v_c_digits_start = __pyx_t_2;
+1678: 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;
1679:
+1680: pos = 0
__pyx_v_pos = 0; /* … */ __pyx_v_pos = 0;
+1681: 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;
+1682: 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;
+1683: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1684: 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, 1684, __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, 1684, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1685: 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) { /* … */ }
+1686: if c == u'/':
switch (__pyx_v_c) { case 47: /* … */ break; case 46: /* … */ switch (__pyx_v_c) { case 47: /* … */ break; case 46:
+1687: 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:
+1688: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1688, __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_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1688, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1689: elif state in (NUM, NUM_SPACE):
case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; default: /* … */ case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; default:
+1690: 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, 1690, __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, 1690, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1691: else:
+1692: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1692, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1693: state = DENOM_START
__pyx_v_state = __pyx_e_10quicktions_DENOM_START; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_START;
+1694: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1695: elif c == u'.':
break; case 69: /* … */ break; case 69:
+1696: 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:
+1697: state = START_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
+1698: elif state == SMALL_NUM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1699: state = SMALL_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
+1700: elif state == NUM:
break; default: /* … */ break; default:
+1701: state = DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
1702: else:
+1703: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1703, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1703, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1704: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1705: elif c in u'eE':
case 0x65: /* … */ break; case 43: /* … */ case 0x65: /* … */ break; case 43:
+1706: 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:
+1707: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1707, __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_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1707, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1708: elif state == NUM:
break; default: /* … */ break; default:
+1709: 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, 1709, __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, 1709, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1710: else:
+1711: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1711, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1712: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1713: break
goto __pyx_L5_break; /* … */ goto __pyx_L4_break;
+1714: elif c in u'-+':
case 45: /* … */ break; case 95: /* … */ case 45: /* … */ break; case 95:
+1715: 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; }
+1716: is_neg = c == u'-'
__pyx_v_is_neg = (__pyx_v_c == 45); /* … */ __pyx_v_is_neg = (__pyx_v_c == 45);
+1717: state = BEGIN_SIGN
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
1718: else:
+1719: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L7:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1719, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L6:;
+1720: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
+1721: elif c == u'_':
break; default: /* … */ break; default:
+1722: 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:
+1723: state = SMALL_NUM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
+1724: elif state == NUM:
break; default: /* … */ break; default:
+1725: state = NUM_US
__pyx_v_state = __pyx_e_10quicktions_NUM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_US;
1726: else:
+1727: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1727, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1728: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
1729: else:
+1730: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1731: 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;
+1732: 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]);
+1733: if not c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_3); if (__pyx_t_6) { /* … */ }
+1734: break
goto __pyx_L10_break; /* … */ goto __pyx_L9_break;
+1735: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L10_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L9_break:;
1736:
+1737: 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:
+1738: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
+1739: elif state == SMALL_NUM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+1740: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1740, __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_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1740, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1741: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
+1742: elif state == NUM:
break; default: /* … */ break; default:
+1743: 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, 1743, __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, 1743, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1744: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
1745: else:
+1746: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1746, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1747: continue
goto __pyx_L4_continue; /* … */ goto __pyx_L3_continue;
1748:
+1749: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); 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; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1749, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1750: continue
goto __pyx_L4_continue; break; } /* … */ goto __pyx_L3_continue; break; }
1751:
1752: # normal digit found
+1753: 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:
+1754: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1755: state = SMALL_NUM
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
1756:
1757: # fast-path for consecutive digits
+1758: 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_6 = __pyx_t_3; goto __pyx_L13_bool_binop_done; } __pyx_t_3 = (__pyx_v_inum <= (PY_LLONG_MAX / 100)); __pyx_t_6 = __pyx_t_3; __pyx_L13_bool_binop_done:; if (!__pyx_t_6) break;
+1759: 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]);
+1760: 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, 1760, __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, 1760, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1761: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ }
+1762: break
goto __pyx_L13_break; /* … */ goto __pyx_L12_break;
+1763: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1764: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L13_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L12_break:;
1765:
+1766: if inum > MAX_SMALL_NUMBER:
__pyx_t_6 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ }
+1767: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM;
+1768: elif state == NUM_US:
break; default: break; } /* … */ break; default: break; }
+1769: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM; /* … */ __pyx_v_state = __pyx_e_10quicktions_NUM;
1770:
1771: # We might have switched to NUM above, so continue right here in that case.
+1772: 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:
1773: pass # handled above
+1774: elif state == NUM:
break; default: /* … */ break; default:
1775: # fast-path for consecutive digits
+1776: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break;
+1777: 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]);
+1778: 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, 1778, __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, 1778, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1779: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ }
+1780: break
goto __pyx_L19_break; /* … */ goto __pyx_L18_break;
+1781: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L19_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L18_break:;
1782: else:
+1783: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1783, __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_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L3_continue:; } __pyx_L4_break:;
1784:
+1785: 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:
1786: # NUM '/' | SMALL_NUM '/'
+1787: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break;
+1788: 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]);
+1789: if not c.isspace():
__pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_2 = (!__pyx_t_6); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_3 = (!__pyx_t_6); if (__pyx_t_3) { /* … */ }
+1790: break
goto __pyx_L22_break; /* … */ goto __pyx_L21_break;
+1791: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L22_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L21_break:;
1792:
1793: # Start fresh digits collection.
+1794: c_digits = c_digits_start
__pyx_v_c_digits = __pyx_v_c_digits_start; /* … */ __pyx_v_c_digits = __pyx_v_c_digits_start;
+1795: 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;
+1796: 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]);
+1797: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1798: 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, 1798, __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, 1798, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1799: 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) { /* … */ }
+1800: 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:
+1801: 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; }
+1802: 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));
+1803: state = DENOM_SIGN
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
1804: else:
+1805: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1805, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L27:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1805, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L26:;
+1806: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
+1807: elif c == u'_':
break; default: /* … */ break; default:
+1808: 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:
+1809: state = SMALL_DENOM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
+1810: elif state == DENOM:
break; default: /* … */ break; default:
+1811: state = DENOM_US
__pyx_v_state = __pyx_e_10quicktions_DENOM_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_US;
1812: else:
+1813: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1813, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1813, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1814: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
1815: else:
+1816: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1817: while pos < s_len:
while (1) { __pyx_t_2 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_2) break; /* … */ while (1) { __pyx_t_3 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_3) break;
+1818: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos); /* … */ __pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+1819: if not c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_3); if (__pyx_t_6) { /* … */ }
+1820: break
goto __pyx_L30_break; /* … */ goto __pyx_L29_break;
+1821: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L30_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L29_break:;
1822:
+1823: 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:
1824: pass
+1825: elif state == SMALL_DENOM:
break; case __pyx_e_10quicktions_DENOM: /* … */ break; case __pyx_e_10quicktions_DENOM:
+1826: denom = idenom
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1826, __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_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1826, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
+1827: elif state == DENOM:
break; default: /* … */ break; default:
+1828: 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, 1828, __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, 1828, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
1829: else:
+1830: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1831: state = DENOM_SPACE
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
+1832: continue
goto __pyx_L24_continue; /* … */ goto __pyx_L23_continue;
1833:
+1834: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1834, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1835: continue
goto __pyx_L24_continue; break; } /* … */ goto __pyx_L23_continue; break; }
1836:
1837: # normal digit found
+1838: 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:
+1839: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit); /* … */ __pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+1840: state = SMALL_DENOM
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
1841:
1842: # fast-path for consecutive digits
+1843: 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_6 = __pyx_t_3; goto __pyx_L33_bool_binop_done; } __pyx_t_3 = (__pyx_v_idenom <= (PY_LLONG_MAX / 100)); __pyx_t_6 = __pyx_t_3; __pyx_L33_bool_binop_done:; if (!__pyx_t_6) break;
+1844: 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]);
+1845: 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, 1845, __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, 1845, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1846: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ }
+1847: break
goto __pyx_L33_break; /* … */ goto __pyx_L32_break;
+1848: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit); /* … */ __pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+1849: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L33_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L32_break:;
1850:
+1851: if idenom > MAX_SMALL_NUMBER:
__pyx_t_6 = (__pyx_v_idenom > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_idenom > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ }
+1852: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM;
+1853: elif state == DENOM_US:
break; default: break; } /* … */ break; default: break; }
+1854: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM; /* … */ __pyx_v_state = __pyx_e_10quicktions_DENOM;
1855:
1856: # We might have switched to DENOM above, so continue right here in that case.
+1857: 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:
1858: pass # handled above
+1859: elif state == DENOM:
break; default: /* … */ break; default:
1860: # fast-path for consecutive digits
+1861: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break;
+1862: 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]);
+1863: 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, 1863, __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, 1863, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1864: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ }
+1865: break
goto __pyx_L39_break; /* … */ goto __pyx_L38_break;
+1866: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L39_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L38_break:;
1867: else:
+1868: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1868, __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_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L23_continue:; }
1869:
+1870: 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; }
1871: # SMALL_NUM '.' | '.'
+1872: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break;
+1873: 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]);
+1874: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1875: 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, 1875, __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, 1875, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1876: if digit == -1:
__pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_digit == -1L); if (__pyx_t_6) { /* … */ }
+1877: if c == u'_':
switch (__pyx_v_c) { case 95: /* … */ break; case 69: /* … */ switch (__pyx_v_c) { case 95: /* … */ break; case 69:
+1878: if state == SMALL_DECIMAL:
__pyx_t_6 = (__pyx_v_state == __pyx_e_10quicktions_SMALL_DECIMAL); if (__pyx_t_6) { /* … */ goto __pyx_L44; } /* … */ __pyx_t_6 = (__pyx_v_state == __pyx_e_10quicktions_SMALL_DECIMAL); if (__pyx_t_6) { /* … */ goto __pyx_L43; }
+1879: state = SMALL_DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
1880: else:
+1881: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1881, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L44:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1881, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L43:;
+1882: continue
goto __pyx_L41_continue; /* … */ goto __pyx_L40_continue;
+1883: elif c in u'eE':
case 0x65: /* … */ break; default: /* … */ case 0x65: /* … */ break; default:
+1884: 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:
+1885: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1885, __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_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1885, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1886: else:
+1887: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1887, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1887, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1888: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1889: break
goto __pyx_L42_break; /* … */ goto __pyx_L41_break;
1890: else:
+1891: if c.isspace():
__pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_6) { /* … */ }
+1892: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (!__pyx_t_6) break;
+1893: 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]);
+1894: if not c.isspace():
__pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_2 = (!__pyx_t_6); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_3 = (!__pyx_t_6); if (__pyx_t_3) { /* … */ }
+1895: break
goto __pyx_L47_break; /* … */ goto __pyx_L46_break;
+1896: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L47_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L46_break:;
1897:
+1898: 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:
+1899: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1899, __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_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1899, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1900: state = SMALL_END_SPACE
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
1901: else:
+1902: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1902, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1902, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1903: continue
goto __pyx_L41_continue; /* … */ goto __pyx_L40_continue;
1904:
+1905: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1905, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1905, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1906: continue
goto __pyx_L41_continue; break; } /* … */ goto __pyx_L40_continue; break; }
1907:
1908: # normal digit found
+1909: 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:
+1910: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1911: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1912: state = SMALL_DECIMAL
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
1913:
1914: # fast-path for consecutive digits
+1915: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L50_bool_binop_done; } __pyx_t_6 = (__pyx_v_inum <= (PY_LLONG_MAX / 100)); if (__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L50_bool_binop_done; } __pyx_t_6 = (__pyx_v_decimal_len < __pyx_v_max_decimal_len); __pyx_t_3 = __pyx_t_6; __pyx_L50_bool_binop_done:; if (!__pyx_t_3) break;
+1916: 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]);
+1917: 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, 1917, __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, 1917, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1918: 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) { /* … */ }
+1919: break
goto __pyx_L50_break; /* … */ goto __pyx_L49_break;
+1920: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit); /* … */ __pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1921: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1922: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L50_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L49_break:;
1923:
+1924: 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_6 = (__pyx_v_inum > (PY_LLONG_MAX / 100)); if (!__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L55_bool_binop_done; } __pyx_t_6 = (__pyx_v_decimal_len >= __pyx_v_max_decimal_len); __pyx_t_3 = __pyx_t_6; __pyx_L55_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1925: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL;
+1926: break
goto __pyx_L42_break; /* … */ goto __pyx_L41_break;
1927: else:
+1928: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1928, __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_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1928, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L40_continue:; } __pyx_L41_break:;
1929:
+1930: 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; }
1931: # NUM '.' | SMALL_DECIMAL->DECIMAL
+1932: 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;
+1933: 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]);
+1934: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1935: 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, 1935, __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, 1935, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1936: 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) { /* … */ }
+1937: if c == u'_':
switch (__pyx_v_c) { case 95: /* … */ break; case 69: /* … */ switch (__pyx_v_c) { case 95: /* … */ break; case 69:
+1938: 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; }
+1939: state = DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
1940: else:
+1941: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L61:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L60:;
+1942: continue
goto __pyx_L58_continue; /* … */ goto __pyx_L57_continue;
+1943: elif c in u'eE':
case 0x65: /* … */ break; default: /* … */ case 0x65: /* … */ break; default:
+1944: 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:
+1945: 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, 1945, __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, 1945, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1946: else:
+1947: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1947, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1947, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1948: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1949: break
goto __pyx_L59_break; /* … */ goto __pyx_L58_break;
1950: else:
+1951: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1952: 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:
+1953: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_END_SPACE;
1954: else:
+1955: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1955, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1955, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1956: break
goto __pyx_L59_break; /* … */ goto __pyx_L58_break;
1957:
+1958: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1958, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1958, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1959: continue
goto __pyx_L58_continue; break; } /* … */ goto __pyx_L57_continue; break; }
1960:
1961: # normal digit found
+1962: 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:
+1963: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1964: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL; /* … */ __pyx_v_state = __pyx_e_10quicktions_DECIMAL;
1965:
1966: # fast-path for consecutive digits
+1967: 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;
+1968: 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]);
+1969: 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, 1969, __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, 1969, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1970: 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) { /* … */ }
+1971: break
goto __pyx_L64_break; /* … */ goto __pyx_L63_break;
+1972: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1); /* … */ __pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+1973: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L64_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L63_break:;
1974: else:
+1975: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1975, __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_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1975, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L57_continue:; } __pyx_L58_break:;
1976:
+1977: 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) { /* … */ }
1978: # (SMALL_) NUM ['.' DECIMAL] 'E'
+1979: 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;
+1980: 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]);
+1981: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); /* … */ __pyx_v_pos = (__pyx_v_pos + 1);
+1982: 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, 1982, __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, 1982, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1983: 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) { /* … */ }
+1984: 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:
+1985: 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; }
+1986: exp_is_neg = c == u'-'
__pyx_v_exp_is_neg = (__pyx_v_c == 45); /* … */ __pyx_v_exp_is_neg = (__pyx_v_c == 45);
+1987: state = EXP_SIGN
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
1988: else:
+1989: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L70:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1989, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L69:;
+1990: continue
goto __pyx_L67_continue; /* … */ goto __pyx_L66_continue;
+1991: elif c == u'_':
break; default: /* … */ break; default:
+1992: 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; }
+1993: state = EXP_US
__pyx_v_state = __pyx_e_10quicktions_EXP_US; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP_US;
1994: else:
+1995: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1995, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L71:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1995, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L70:;
+1996: continue
goto __pyx_L67_continue; /* … */ goto __pyx_L66_continue;
1997: else:
+1998: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (__pyx_t_3) { /* … */ }
+1999: 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; }
+2000: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2001: else:
+2002: _raise_invalid_input(orig_str)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2002, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; } __pyx_L73:; /* … */ /*else*/ { __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2002, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; } __pyx_L72:;
+2003: break
goto __pyx_L68_break; /* … */ goto __pyx_L67_break;
2004:
+2005: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2005, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2005, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2006: continue
goto __pyx_L67_continue; break; } /* … */ goto __pyx_L66_continue; break; }
2007:
2008: # normal digit found
+2009: 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:
+2010: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit); /* … */ __pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2011: state = EXP
__pyx_v_state = __pyx_e_10quicktions_EXP; /* … */ __pyx_v_state = __pyx_e_10quicktions_EXP;
2012:
2013: # fast-path for consecutive digits
+2014: 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_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L75_bool_binop_done; } __pyx_t_6 = (__pyx_v_iexp <= (PY_LLONG_MAX / 100)); __pyx_t_3 = __pyx_t_6; __pyx_L75_bool_binop_done:; if (!__pyx_t_3) break;
+2015: 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]);
+2016: 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, 2016, __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, 2016, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2017: 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) { /* … */ }
+2018: break
goto __pyx_L75_break; /* … */ goto __pyx_L74_break;
+2019: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit); /* … */ __pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2020: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L75_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L74_break:;
2021:
+2022: 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) { /* … */ }
+2023: _raise_parse_overflow(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2023, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2023, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2024: else:
+2025: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2025, __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_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2025, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L66_continue:; } __pyx_L67_break:;
2026:
+2027: 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; }
+2028: 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;
+2029: 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]);
+2030: if not c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); __pyx_t_6 = (!__pyx_t_3); if (__pyx_t_6) { /* … */ }
+2031: break
goto __pyx_L81_break; /* … */ goto __pyx_L80_break;
+2032: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L81_break:; /* … */ __pyx_v_pos = (__pyx_v_pos + 1); } __pyx_L80_break:;
2033:
+2034: if pos < s_len :
__pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_pos < __pyx_v_s_len); if (__pyx_t_6) { /* … */ }
+2035: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2035, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2036:
+2037: cdef bint is_normalised = False
__pyx_v_is_normalised = 0; /* … */ __pyx_v_is_normalised = 0;
+2038: 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:
2039: # Special case for 'small' numbers: normalise directly in C space.
+2040: 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_6 = __pyx_t_3; goto __pyx_L84_bool_binop_done; } __pyx_t_3 = (__pyx_v_decimal_len != 0); __pyx_t_6 = __pyx_t_3; __pyx_L84_bool_binop_done:; if (__pyx_t_6) { /* … */ goto __pyx_L83; }
2041: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2042: 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_6 = __pyx_t_3; goto __pyx_L87_bool_binop_done; } __pyx_t_3 = ((__pyx_v_inum % 5) == 0); __pyx_t_6 = __pyx_t_3; __pyx_L87_bool_binop_done:; if (__pyx_t_6) { /* … */ goto __pyx_L86; }
+2043: 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, 2043, __pyx_L1_error) __pyx_v_idenom = __pyx_t_7; /* … */ __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, 2043, __pyx_L1_error) __pyx_v_idenom = __pyx_t_7;
+2044: 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, 2044, __pyx_L1_error) __pyx_v_igcd = __pyx_t_8; /* … */ __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, 2044, __pyx_L1_error) __pyx_v_igcd = __pyx_t_8;
+2045: if igcd > 1:
__pyx_t_6 = (__pyx_v_igcd > 1); if (__pyx_t_6) { /* … */ goto __pyx_L90; } /* … */ __pyx_t_6 = (__pyx_v_igcd > 1); if (__pyx_t_6) { /* … */ goto __pyx_L89; }
+2046: inum //= igcd
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd); /* … */ __pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
+2047: denom = idenom // igcd
__pyx_t_3 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG((__pyx_v_idenom / __pyx_v_igcd)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2047, __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_PyLong_From_unsigned_PY_LONG_LONG((__pyx_v_idenom / __pyx_v_igcd)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2047, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2048: else:
+2049: denom = pow10(decimal_len)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2049, __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, 2049, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L89:;
2050: else:
+2051: denom = pow10(decimal_len)
/*else*/ { __pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2051, __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, 2051, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0; } __pyx_L86:;
2052: else:
+2053: denom = 1
/*else*/ { __Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_mstate_global->__pyx_int_1); } __pyx_L84:; /* … */ /*else*/ { __Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_mstate_global->__pyx_int_1); } __pyx_L83:;
+2054: if is_neg:
if (__pyx_v_is_neg) { /* … */ } /* … */ if (__pyx_v_is_neg) { /* … */ }
+2055: inum = -inum
__pyx_v_inum = (-__pyx_v_inum); /* … */ __pyx_v_inum = (-__pyx_v_inum);
+2056: return inum, denom, True
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2056, __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) != (0)) __PYX_ERR(0, 2056, __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) != (0)) __PYX_ERR(0, 2056, __pyx_L1_error); __Pyx_INCREF(Py_True); __Pyx_GIVEREF(Py_True); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, Py_True) != (0)) __PYX_ERR(0, 2056, __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_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2056, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_t_1) != (0)) __PYX_ERR(0, 2056, __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) != (0)) __PYX_ERR(0, 2056, __pyx_L1_error); __Pyx_INCREF(Py_True); __Pyx_GIVEREF(Py_True); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, Py_True) != (0)) __PYX_ERR(0, 2056, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = ((PyObject*)__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L0;
2057:
+2058: elif state == SMALL_DENOM:
break; case __pyx_e_10quicktions_NUM: /* … */ break; case __pyx_e_10quicktions_NUM:
+2059: denom = idenom
__pyx_t_9 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2059, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_t_9 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2059, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0;
+2060: 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:
+2061: is_normalised = True # will be repaired below for iexp < 0
__pyx_v_is_normalised = 1; /* … */ __pyx_v_is_normalised = 1;
+2062: denom = 1
__Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_mstate_global->__pyx_int_1); /* … */ __Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_mstate_global->__pyx_int_1);
+2063: 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, 2063, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_9); __pyx_t_9 = 0; /* … */ __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, 2063, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_9); __pyx_t_9 = 0;
+2064: elif state == DENOM:
break; case __pyx_e_10quicktions_NUM_SPACE: /* … */ break; case __pyx_e_10quicktions_NUM_SPACE:
+2065: 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, 2065, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0; /* … */ __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, 2065, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0;
+2066: 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:
+2067: is_normalised = True
__pyx_v_is_normalised = 1; /* … */ __pyx_v_is_normalised = 1;
+2068: denom = 1
__Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_mstate_global->__pyx_int_1); /* … */ __Pyx_INCREF(__pyx_mstate_global->__pyx_int_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_mstate_global->__pyx_int_1);
+2069: elif state == DENOM_SPACE:
break; default: /* … */ break; default:
2070: pass
2071: else:
+2072: _raise_invalid_input(orig_str)
__pyx_t_9 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2072, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; break; } /* … */ __pyx_t_9 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2072, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; break; }
2073:
+2074: if decimal_len > MAX_SMALL_NUMBER:
__pyx_t_6 = (__pyx_v_decimal_len > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_6 = (__pyx_v_decimal_len > (PY_LLONG_MAX / 100)); if (__pyx_t_6) { /* … */ }
+2075: _raise_parse_overflow(orig_str)
__pyx_t_9 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_orig_str); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2075, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; /* … */ __pyx_t_9 = __pyx_f_10quicktions__raise_parse_overflow(__pyx_v_orig_str); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2075, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+2076: if exp_is_neg:
if (__pyx_v_exp_is_neg) { /* … */ } /* … */ if (__pyx_v_exp_is_neg) { /* … */ }
+2077: iexp = -iexp
__pyx_v_iexp = (-__pyx_v_iexp); /* … */ __pyx_v_iexp = (-__pyx_v_iexp);
+2078: iexp -= decimal_len
__pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len); /* … */ __pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len);
2079:
+2080: if iexp > 0:
__pyx_t_6 = (__pyx_v_iexp > 0); if (__pyx_t_6) { /* … */ goto __pyx_L94; } /* … */ __pyx_t_6 = (__pyx_v_iexp > 0); if (__pyx_t_6) { /* … */ goto __pyx_L93; }
+2081: num *= pow10(iexp)
__pyx_t_9 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2081, __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, 2081, __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_9 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = PyNumber_InPlaceMultiply(__pyx_v_num, __pyx_t_9); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2081, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+2082: elif iexp < 0:
__pyx_t_6 = (__pyx_v_iexp < 0); if (__pyx_t_6) { /* … */ } __pyx_L94:; /* … */ __pyx_t_6 = (__pyx_v_iexp < 0); if (__pyx_t_6) { /* … */ } __pyx_L93:;
2083: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2084: is_normalised = num & 1 != 0 and num % 5 != 0
__pyx_t_3 = __Pyx_PyLong_AndObjC(__pyx_v_num, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = (__Pyx_PyLong_BoolNeObjC(__pyx_t_3, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_2) { } else { __pyx_t_6 = __pyx_t_2; goto __pyx_L95_bool_binop_done; } __pyx_t_3 = __Pyx_PyLong_RemainderObjC(__pyx_v_num, __pyx_mstate_global->__pyx_int_5, 5, 0, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = (__Pyx_PyLong_BoolNeObjC(__pyx_t_3, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_6 = __pyx_t_2; __pyx_L95_bool_binop_done:; __pyx_v_is_normalised = __pyx_t_6; /* … */ __pyx_t_1 = __Pyx_PyLong_AndObjC(__pyx_v_num, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = (__Pyx_PyLong_BoolNeObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_3) { } else { __pyx_t_6 = __pyx_t_3; goto __pyx_L94_bool_binop_done; } __pyx_t_1 = __Pyx_PyLong_RemainderObjC(__pyx_v_num, __pyx_mstate_global->__pyx_int_5, 5, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = (__Pyx_PyLong_BoolNeObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_0, 0, 0)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 2084, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_6 = __pyx_t_3; __pyx_L94_bool_binop_done:; __pyx_v_is_normalised = __pyx_t_6;
+2085: denom = pow10(-iexp)
__pyx_t_3 = __pyx_f_10quicktions_pow10((-__pyx_v_iexp)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2085, __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, 2085, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2086:
+2087: if is_neg:
if (__pyx_v_is_neg) { /* … */ } /* … */ if (__pyx_v_is_neg) { /* … */ }
+2088: num = -num
__pyx_t_3 = PyNumber_Negative(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2088, __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, 2088, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2089:
+2090: return num, denom, is_normalised
__Pyx_XDECREF(__pyx_r); if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2090, __pyx_L1_error) } __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_is_normalised); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2090, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2090, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_INCREF(__pyx_v_num); __Pyx_GIVEREF(__pyx_v_num); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_num) != (0)) __PYX_ERR(0, 2090, __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) != (0)) __PYX_ERR(0, 2090, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 2090, __pyx_L1_error); __pyx_t_3 = 0; __pyx_r = ((PyObject*)__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L0; /* … */ __Pyx_XDECREF(__pyx_r); if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2090, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_is_normalised); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2090, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2090, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_INCREF(__pyx_v_num); __Pyx_GIVEREF(__pyx_v_num); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 0, __pyx_v_num) != (0)) __PYX_ERR(0, 2090, __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) != (0)) __PYX_ERR(0, 2090, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_1) != (0)) __PYX_ERR(0, 2090, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = ((PyObject*)__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L0;