Generated by Cython 3.1.3
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.22'
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_version, __pyx_mstate_global->__pyx_kp_u_1_22) < 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_ULONGLONG = (<unsigned long long> PY_LLONG_MAX) * 2 + 1
__pyx_t_2 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(((((unsigned PY_LONG_LONG)PY_LLONG_MAX) * 2) + 1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 39, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_XGOTREF(__pyx_v_10quicktions_PY_MAX_ULONGLONG); __Pyx_DECREF_SET(__pyx_v_10quicktions_PY_MAX_ULONGLONG, __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_2); 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 defined(__Pyx_PyLong_DigitCount)
0089: #define __Quicktions_HAS_ISLONGLONG (1)
0090: #define __Quicktions_PyLong_IsLongLong(x) (__Pyx_PyLong_DigitCount(x) <= 2)
0091: #else
0092: #define __Quicktions_HAS_ISLONGLONG (0)
0093: #define __Quicktions_PyLong_IsLongLong(x) (0)
0094: #endif
0095:
0096: #if PY_VERSION_HEX >= 0x030c00a5 && defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue)
0097: #define __Quicktions_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) (x))
0098: #if CYTHON_COMPILING_IN_CPYTHON
0099: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) (((PyLongObject*)x)->long_value.ob_digit[0]))
0100: #else
0101: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) PyUnstable_Long_CompactValue((PyLongObject*) (x))))
0102: #endif
0103: #elif PY_VERSION_HEX < 0x030c0000 && CYTHON_COMPILING_IN_CPYTHON
0104: #define __Quicktions_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1)
0105: #define __Quicktions_PyLong_CompactValueUnsigned(x) ((unsigned long long) ((Py_SIZE(x) == 0) ? 0 : (((PyLongObject*)x)->ob_digit)[0]))
0106: #else
0107: #define __Quicktions_PyLong_IsCompact(x) (0)
0108: #define __Quicktions_PyLong_CompactValueUnsigned(x) (0U)
0109: #endif
0110: #if PY_VERSION_HEX >= 0x030d0000 || !CYTHON_COMPILING_IN_CPYTHON
0111: #define _PyLong_GCD(a, b) (NULL)
0112: #endif
0113:
0114: #ifdef __has_builtin
0115: #if __has_builtin(__builtin_ctzg)
0116: #define __Quicktions_HAS_FAST_CTZ_uint (1)
0117: #define __Quicktions_trailing_zeros_uint(x) __builtin_ctzg(x)
0118: #define __Quicktions_HAS_FAST_CTZ_ulong (1)
0119: #define __Quicktions_trailing_zeros_ulong(x) __builtin_ctzg(x)
0120: #define __Quicktions_HAS_FAST_CTZ_ullong (1)
0121: #define __Quicktions_trailing_zeros_ullong(x) __builtin_ctzg(x)
0122: #else
0123: #if __has_builtin(__builtin_ctz)
0124: #define __Quicktions_HAS_FAST_CTZ_uint (1)
0125: #define __Quicktions_trailing_zeros_uint(x) __builtin_ctz(x)
0126: #endif
0127: #if __has_builtin(__builtin_ctzl)
0128: #define __Quicktions_HAS_FAST_CTZ_ulong (1)
0129: #define __Quicktions_trailing_zeros_ulong(x) __builtin_ctzl(x)
0130: #endif
0131: #if __has_builtin(__builtin_ctzll)
0132: #define __Quicktions_HAS_FAST_CTZ_ullong (1)
0133: #define __Quicktions_trailing_zeros_ullong(x) __builtin_ctzll(x)
0134: #endif
0135: #endif
0136: #elif defined(_MSC_VER) && SIZEOF_INT == 4
0137: /* Typical Windows64 config (Win32 does not define "_BitScanForward64"). */
0138: #define __Quicktions_HAS_FAST_CTZ_uint (1)
0139: #pragma intrinsic(_BitScanForward)
0140: static CYTHON_INLINE int __Quicktions_trailing_zeros_uint(uint32_t x) {
0141: unsigned long bits;
0142: _BitScanForward(&bits, x);
0143: return (int) bits;
0144: }
0145: #if SIZEOF_LONG == 4
0146: #define __Quicktions_HAS_FAST_CTZ_ulong (1)
0147: #define __Quicktions_trailing_zeros_ulong(x) __Quicktions_trailing_zeros_uint(x)
0148: #endif
0149:
0150: /* Win32 does not define "_BitScanForward64". */
0151: #if defined(_WIN64) && SIZEOF_LONG_LONG == 8
0152: #define __Quicktions_HAS_FAST_CTZ_ullong (1)
0153: #pragma intrinsic(_BitScanForward64)
0154: static CYTHON_INLINE int __Quicktions_trailing_zeros_ullong(uint64_t x) {
0155: unsigned long bits;
0156: _BitScanForward64(&bits, x);
0157: return (int) bits;
0158: }
0159: #if SIZEOF_LONG == 8
0160: #define __Quicktions_HAS_FAST_CTZ_ulong (1)
0161: #define __Quicktions_trailing_zeros_ulong(x) __Quicktions_trailing_zeros_ullong(x)
0162: #endif
0163: #endif
0164: #endif
0165:
0166: #if !defined(__Quicktions_HAS_FAST_CTZ_uint)
0167: #define __Quicktions_HAS_FAST_CTZ_uint (0)
0168: #define __Quicktions_trailing_zeros_uint(x) (0)
0169: #endif
0170: #if !defined(__Quicktions_HAS_FAST_CTZ_ulong)
0171: #define __Quicktions_HAS_FAST_CTZ_ulong (0)
0172: #define __Quicktions_trailing_zeros_ulong(x) (0)
0173: #endif
0174: #if !defined(__Quicktions_HAS_FAST_CTZ_ullong)
0175: #define __Quicktions_HAS_FAST_CTZ_ullong (0)
0176: #define __Quicktions_trailing_zeros_ullong(x) (0)
0177: #endif
0178: """
0179: bint PyLong_IsCompact "__Quicktions_PyLong_IsCompact" (x)
0180: unsigned long long PyLong_CompactValueUnsigned "__Quicktions_PyLong_CompactValueUnsigned" (x)
0181: const unsigned long long PY_ULLONG_MAX
0182:
0183: bint PyLong_IsLongLong "__Quicktions_PyLong_IsLongLong" (x)
0184: const bint HAS_ISLONGLONG "__Quicktions_HAS_ISLONGLONG"
0185:
0186: # CPython 3.5-3.12 has a fast PyLong GCD implementation that we can use.
0187: # In CPython 3.13, math.gcd() is fast enough to call it directly.
0188: const bint HAS_FAST_MATH_GCD "(PY_VERSION_HEX >= 0x030d0000)"
0189: const bint HAS_OLD_PYLONG_GCD "(CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000)"
0190: object _PyLong_GCD(object a, object b)
0191:
0192: const bint HAS_FAST_CTZ_uint "__Quicktions_HAS_FAST_CTZ_uint"
0193: int trailing_zeros_uint "__Quicktions_trailing_zeros_uint" (unsigned int x)
0194: const bint HAS_FAST_CTZ_ulong "__Quicktions_HAS_FAST_CTZ_ulong"
0195: int trailing_zeros_ulong "__Quicktions_trailing_zeros_ulong" (unsigned long x)
0196: const bint HAS_FAST_CTZ_ullong "__Quicktions_HAS_FAST_CTZ_ullong"
0197: int trailing_zeros_ullong "__Quicktions_trailing_zeros_ullong" (unsigned long long x)
0198:
0199:
+0200: def _gcd(a, b):
/* 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, 200, __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, 200, __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, 200, __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, 200, __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, 200, __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, 200, __pyx_L3_error) values[1] = __Pyx_ArgRef_FASTCALL(__pyx_args, 1); if (!CYTHON_ASSUME_SAFE_MACROS && unlikely(!values[1])) __PYX_ERR(0, 200, __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, 200, __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; /* … */ /* function exit code */ __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_3); __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("quicktions._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, 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, 200, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_gcd, __pyx_t_2) < 0) __PYX_ERR(0, 200, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0201: """Calculate the Greatest Common Divisor of a and b as a non-negative number.
0202: """
+0203: if not isinstance(a, int):
__pyx_t_1 = PyLong_Check(__pyx_v_a);
__pyx_t_2 = (!__pyx_t_1);
if (unlikely(__pyx_t_2)) {
/* … */
}
+0204: raise ValueError(f"Expected int, got {type(a).__name__}")
__pyx_t_4 = NULL;
__Pyx_INCREF(__pyx_builtin_ValueError);
__pyx_t_5 = __pyx_builtin_ValueError;
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_a)), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_t_6, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 204, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyUnicode_Concat(__pyx_mstate_global->__pyx_kp_u_Expected_int_got, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 204, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_8 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_6};
__pyx_t_3 = __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_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 204, __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, 204, __pyx_L1_error)
+0205: if not isinstance(b, int):
__pyx_t_2 = PyLong_Check(__pyx_v_b);
__pyx_t_1 = (!__pyx_t_2);
if (unlikely(__pyx_t_1)) {
/* … */
}
+0206: raise ValueError(f"Expected int, got {type(b).__name__}")
__pyx_t_5 = NULL;
__Pyx_INCREF(__pyx_builtin_ValueError);
__pyx_t_6 = __pyx_builtin_ValueError;
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_b)), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_4 = __Pyx_PyUnicode_Concat(__pyx_mstate_global->__pyx_kp_u_Expected_int_got, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 206, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_8 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_4};
__pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_8, (2-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 206, __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, 206, __pyx_L1_error)
0207:
+0208: return _igcd(int(a), int(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_v_a); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PyNumber_Int(__pyx_v_b); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_4 = __pyx_f_10quicktions__igcd(__pyx_t_3, __pyx_t_6); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 208, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0209:
0210:
+0211: cdef _igcd(a, b):
static PyObject *__pyx_f_10quicktions__igcd(PyObject *__pyx_v_a, PyObject *__pyx_v_b) {
PyObject *__pyx_r = NULL;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_6);
__Pyx_XDECREF(__pyx_t_7);
__Pyx_XDECREF(__pyx_t_8);
__Pyx_AddTraceback("quicktions._igcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = 0;
__pyx_L0:;
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+0212: if HAS_ISLONGLONG:
__pyx_t_1 = (__Quicktions_HAS_ISLONGLONG != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+0213: if PyLong_IsLongLong(a) and PyLong_IsLongLong(b):
__pyx_t_2 = __Quicktions_PyLong_IsLongLong(__pyx_v_a); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L5_bool_binop_done; } __pyx_t_2 = __Quicktions_PyLong_IsLongLong(__pyx_v_b); __pyx_t_1 = __pyx_t_2; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0214: return _c_gcd(<unsigned long long> a, <unsigned long long> b)
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = __Pyx_PyLong_As_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_3 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_t_4 = __Pyx_PyLong_As_unsigned_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_4 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_t_5 = __pyx_v_10quicktions__c_gcd(((unsigned PY_LONG_LONG)__pyx_t_3), ((unsigned PY_LONG_LONG)__pyx_t_4)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 214, __pyx_L1_error) __pyx_t_6 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 214, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
+0215: elif 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_L7_bool_binop_done; } __pyx_t_2 = __Quicktions_PyLong_IsCompact(__pyx_v_b); __pyx_t_1 = __pyx_t_2; __pyx_L7_bool_binop_done:; if (__pyx_t_1) { /* … */ } __pyx_L3:;
+0216: return _c_gcd(PyLong_CompactValueUnsigned(a), PyLong_CompactValueUnsigned(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __pyx_v_10quicktions__c_gcd(__Quicktions_PyLong_CompactValueUnsigned(__pyx_v_a), __Quicktions_PyLong_CompactValueUnsigned(__pyx_v_b)); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 216, __pyx_L1_error) __pyx_t_6 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 216, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
0217:
+0218: if HAS_FAST_MATH_GCD:
__pyx_t_1 = ((PY_VERSION_HEX >= 0x030d0000) != 0);
if (__pyx_t_1) {
/* … */
}
+0219: return math_gcd(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_7 = NULL; __Pyx_INCREF(__pyx_v_10quicktions_math_gcd); __pyx_t_8 = __pyx_v_10quicktions_math_gcd; __pyx_t_9 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_8); assert(__pyx_t_7); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_8, __pyx__function); __pyx_t_9 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_v_a, __pyx_v_b}; __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+__pyx_t_9, (3-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 219, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); } __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
+0220: if HAS_OLD_PYLONG_GCD:
__pyx_t_1 = ((CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000) != 0);
if (__pyx_t_1) {
/* … */
}
+0221: return _PyLong_GCD(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = _PyLong_GCD(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 221, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0;
0222:
+0223: return _gcd_fallback(int(a), int(b))
__Pyx_XDECREF(__pyx_r); __pyx_t_6 = __Pyx_PyNumber_Int(__pyx_v_a); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 223, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_8 = __Pyx_PyNumber_Int(__pyx_v_b); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 223, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_7 = __pyx_f_10quicktions__gcd_fallback(((PyObject*)__pyx_t_6), ((PyObject*)__pyx_t_8)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 223, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
0224:
0225:
+0226: ctypedef unsigned long long ullong
typedef unsigned PY_LONG_LONG __pyx_t_10quicktions_ullong;
+0227: ctypedef unsigned long ulong
typedef unsigned long __pyx_t_10quicktions_ulong;
0228: ctypedef unsigned int uint
0229:
0230: ctypedef fused cunumber:
0231: ullong
0232: ulong
0233: uint
0234:
0235:
+0236: cdef ullong _abs(long long x) noexcept:
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;
}
+0237: if x == PY_LLONG_MIN:
__pyx_t_1 = (__pyx_v_x == PY_LLONG_MIN);
if (__pyx_t_1) {
/* … */
}
+0238: return (<ullong>PY_LLONG_MAX) + 1
__pyx_r = (((__pyx_t_10quicktions_ullong)PY_LLONG_MAX) + 1);
goto __pyx_L0;
+0239: return abs(x)
__pyx_t_2 = __Pyx_abs_longlong(__pyx_v_x); __pyx_r = __pyx_t_2; goto __pyx_L0;
0240:
0241:
+0242: @cython.cdivision(True)
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_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_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_L0:;
return __pyx_r;
}
0243: cdef cunumber _euclid_gcd(cunumber a, cunumber b) noexcept:
0244: """Euclid's GCD algorithm"""
+0245: 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;
+0246: a, b = b, a%b
__pyx_t_2 = __pyx_v_b;
__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;
__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;
__pyx_t_3 = (__pyx_v_a % __pyx_v_b);
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
}
+0247: 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;
0248:
0249:
+0250: cdef inline int trailing_zeros(cunumber x) noexcept:
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;
}
0251: if cunumber is uint:
+0252: return trailing_zeros_uint(x)
__pyx_r = __Quicktions_trailing_zeros_uint(__pyx_v_x); goto __pyx_L0;
0253: elif cunumber is ulong:
+0254: return trailing_zeros_ulong(x)
__pyx_r = __Quicktions_trailing_zeros_ulong(__pyx_v_x); goto __pyx_L0;
0255: else:
+0256: return trailing_zeros_ullong(x)
__pyx_r = __Quicktions_trailing_zeros_ullong(__pyx_v_x); goto __pyx_L0;
0257:
0258:
+0259: cdef cunumber _binary_gcd(cunumber a, cunumber b) noexcept:
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_az;
int __pyx_v_bz;
int __pyx_v_shift;
__pyx_t_10quicktions_ullong __pyx_r;
/* … */
/* function exit code */
__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_az;
int __pyx_v_bz;
int __pyx_v_shift;
__pyx_t_10quicktions_ulong __pyx_r;
/* … */
/* function exit code */
__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_az;
int __pyx_v_bz;
int __pyx_v_shift;
__pyx_t_10quicktions_uint __pyx_r;
/* … */
/* function exit code */
__pyx_r = 0;
__pyx_L0:;
return __pyx_r;
}
0260: # See https://en.wikipedia.org/wiki/Binary_GCD_algorithm
+0261: 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) {
/* … */
}
+0262: 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;
+0263: 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) {
/* … */
}
+0264: 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;
0265:
+0266: cdef int az = trailing_zeros(a)
__pyx_v_az = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); /* … */ __pyx_v_az = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); /* … */ __pyx_v_az = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_a);
+0267: a >>= az
__pyx_v_a = (__pyx_v_a >> __pyx_v_az); /* … */ __pyx_v_a = (__pyx_v_a >> __pyx_v_az); /* … */ __pyx_v_a = (__pyx_v_a >> __pyx_v_az);
+0268: cdef int bz = trailing_zeros(b)
__pyx_v_bz = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); /* … */ __pyx_v_bz = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); /* … */ __pyx_v_bz = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_b);
+0269: b >>= bz
__pyx_v_b = (__pyx_v_b >> __pyx_v_bz); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_bz); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_bz);
0270:
+0271: cdef int shift = min(az, bz)
__pyx_t_2 = __pyx_v_bz;
__pyx_t_3 = __pyx_v_az;
__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_shift = __pyx_t_4;
/* … */
__pyx_t_2 = __pyx_v_bz;
__pyx_t_3 = __pyx_v_az;
__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_shift = __pyx_t_4;
/* … */
__pyx_t_2 = __pyx_v_bz;
__pyx_t_3 = __pyx_v_az;
__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_shift = __pyx_t_4;
0272:
+0273: while True:
while (1) {
/* … */
while (1) {
/* … */
while (1) {
+0274: 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) {
/* … */
}
+0275: 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;
+0276: 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);
+0277: 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) {
/* … */
}
+0278: return a << shift
__pyx_r = (__pyx_v_a << __pyx_v_shift);
goto __pyx_L0;
/* … */
__pyx_r = (__pyx_v_a << __pyx_v_shift);
goto __pyx_L0;
/* … */
__pyx_r = (__pyx_v_a << __pyx_v_shift);
goto __pyx_L0;
+0279: b >>= trailing_zeros(b)
__pyx_v_b = (__pyx_v_b >> __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_b));
}
/* … */
__pyx_v_b = (__pyx_v_b >> __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_b));
}
/* … */
__pyx_v_b = (__pyx_v_b >> __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_b));
}
0280:
0281:
+0282: @cython.cdivision(True)
static __pyx_t_10quicktions_ullong __pyx_fuse_0__pyx_f_10quicktions__hybrid_binary_gcd(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) {
int __pyx_v_az;
int __pyx_v_bz;
int __pyx_v_shift;
PY_LONG_LONG __pyx_v_diff;
__pyx_t_10quicktions_ullong __pyx_r;
/* … */
/* function exit code */
__pyx_r = 0;
__pyx_L0:;
return __pyx_r;
}
static __pyx_t_10quicktions_ulong __pyx_fuse_1__pyx_f_10quicktions__hybrid_binary_gcd(__pyx_t_10quicktions_ulong __pyx_v_a, __pyx_t_10quicktions_ulong __pyx_v_b) {
int __pyx_v_az;
int __pyx_v_bz;
int __pyx_v_shift;
long __pyx_v_diff;
__pyx_t_10quicktions_ulong __pyx_r;
/* … */
/* function exit code */
__pyx_r = 0;
__pyx_L0:;
return __pyx_r;
}
static __pyx_t_10quicktions_uint __pyx_fuse_2__pyx_f_10quicktions__hybrid_binary_gcd(__pyx_t_10quicktions_uint __pyx_v_a, __pyx_t_10quicktions_uint __pyx_v_b) {
int __pyx_v_az;
int __pyx_v_bz;
int __pyx_v_shift;
int __pyx_v_diff;
__pyx_t_10quicktions_uint __pyx_r;
/* … */
/* function exit code */
__pyx_r = 0;
__pyx_L0:;
return __pyx_r;
}
0283: cdef cunumber _hybrid_binary_gcd(cunumber a, cunumber b) noexcept:
0284: # See https://lemire.me/blog/2024/04/13/greatest-common-divisor-the-extended-euclidean-algorithm-and-speed/
+0285: 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) {
/* … */
}
+0286: a,b = b,a
__pyx_t_2 = __pyx_v_b;
__pyx_t_3 = __pyx_v_a;
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
/* … */
__pyx_t_2 = __pyx_v_b;
__pyx_t_3 = __pyx_v_a;
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
/* … */
__pyx_t_2 = __pyx_v_b;
__pyx_t_3 = __pyx_v_a;
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
+0287: 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) {
/* … */
}
+0288: 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;
+0289: a %= b
__pyx_v_a = (__pyx_v_a % __pyx_v_b); /* … */ __pyx_v_a = (__pyx_v_a % __pyx_v_b); /* … */ __pyx_v_a = (__pyx_v_a % __pyx_v_b);
+0290: 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) {
/* … */
}
+0291: 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;
0292:
+0293: cdef int az = trailing_zeros(a)
__pyx_v_az = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); /* … */ __pyx_v_az = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); /* … */ __pyx_v_az = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_a);
+0294: cdef int bz = trailing_zeros(b)
__pyx_v_bz = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); /* … */ __pyx_v_bz = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); /* … */ __pyx_v_bz = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_b);
+0295: cdef int shift = min(az, bz)
__pyx_t_4 = __pyx_v_bz;
__pyx_t_5 = __pyx_v_az;
__pyx_t_1 = (__pyx_t_4 < __pyx_t_5);
if (__pyx_t_1) {
__pyx_t_6 = __pyx_t_4;
} else {
__pyx_t_6 = __pyx_t_5;
}
__pyx_v_shift = __pyx_t_6;
/* … */
__pyx_t_4 = __pyx_v_bz;
__pyx_t_5 = __pyx_v_az;
__pyx_t_1 = (__pyx_t_4 < __pyx_t_5);
if (__pyx_t_1) {
__pyx_t_6 = __pyx_t_4;
} else {
__pyx_t_6 = __pyx_t_5;
}
__pyx_v_shift = __pyx_t_6;
/* … */
__pyx_t_4 = __pyx_v_bz;
__pyx_t_5 = __pyx_v_az;
__pyx_t_1 = (__pyx_t_4 < __pyx_t_5);
if (__pyx_t_1) {
__pyx_t_6 = __pyx_t_4;
} else {
__pyx_t_6 = __pyx_t_5;
}
__pyx_v_shift = __pyx_t_6;
+0296: a >>= az
__pyx_v_a = (__pyx_v_a >> __pyx_v_az); /* … */ __pyx_v_a = (__pyx_v_a >> __pyx_v_az); /* … */ __pyx_v_a = (__pyx_v_a >> __pyx_v_az);
+0297: b >>= bz
__pyx_v_b = (__pyx_v_b >> __pyx_v_bz); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_bz); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_bz);
0298:
0299: if cunumber is uint:
0300: diff: cython.int
0301: elif cunumber is ulong:
0302: diff: cython.long
0303: else:
0304: diff: cython.longlong
0305:
+0306: while True:
while (1) {
/* … */
while (1) {
/* … */
while (1) {
+0307: diff = a - b
__pyx_v_diff = (__pyx_v_a - __pyx_v_b);
/* … */
__pyx_v_diff = (__pyx_v_a - __pyx_v_b);
/* … */
__pyx_v_diff = (__pyx_v_a - __pyx_v_b);
+0308: if a > b:
__pyx_t_1 = (__pyx_v_a > __pyx_v_b);
if (__pyx_t_1) {
/* … */
goto __pyx_L8;
}
/* … */
__pyx_t_1 = (__pyx_v_a > __pyx_v_b);
if (__pyx_t_1) {
/* … */
goto __pyx_L8;
}
/* … */
__pyx_t_1 = (__pyx_v_a > __pyx_v_b);
if (__pyx_t_1) {
/* … */
goto __pyx_L8;
}
+0309: a,b = b,diff
__pyx_t_3 = __pyx_v_b;
__pyx_t_7 = __pyx_v_diff;
__pyx_v_a = __pyx_t_3;
__pyx_v_b = __pyx_t_7;
/* … */
__pyx_t_3 = __pyx_v_b;
__pyx_t_7 = __pyx_v_diff;
__pyx_v_a = __pyx_t_3;
__pyx_v_b = __pyx_t_7;
/* … */
__pyx_t_3 = __pyx_v_b;
__pyx_t_6 = __pyx_v_diff;
__pyx_v_a = __pyx_t_3;
__pyx_v_b = __pyx_t_6;
0310: else:
+0311: b -= a
/*else*/ {
__pyx_v_b = (__pyx_v_b - __pyx_v_a);
}
__pyx_L8:;
/* … */
/*else*/ {
__pyx_v_b = (__pyx_v_b - __pyx_v_a);
}
__pyx_L8:;
/* … */
/*else*/ {
__pyx_v_b = (__pyx_v_b - __pyx_v_a);
}
__pyx_L8:;
+0312: 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) {
/* … */
}
+0313: return a << shift
__pyx_r = (__pyx_v_a << __pyx_v_shift);
goto __pyx_L0;
/* … */
__pyx_r = (__pyx_v_a << __pyx_v_shift);
goto __pyx_L0;
/* … */
__pyx_r = (__pyx_v_a << __pyx_v_shift);
goto __pyx_L0;
+0314: b >>= trailing_zeros(diff)
__pyx_v_b = (__pyx_v_b >> __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_diff));
}
/* … */
__pyx_v_b = (__pyx_v_b >> __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_diff));
}
/* … */
__pyx_v_b = (__pyx_v_b >> __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_diff));
}
0315:
0316:
+0317: @cython.cdivision(True)
static __pyx_t_10quicktions_ullong __pyx_fuse_0__pyx_f_10quicktions__hybrid_binary_gcd2(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) {
int __pyx_v_az;
int __pyx_v_bz;
int __pyx_v_shift;
__pyx_t_10quicktions_ullong __pyx_v_diff;
__pyx_t_10quicktions_ullong __pyx_r;
/* … */
/* function exit code */
__pyx_L0:;
return __pyx_r;
}
static __pyx_t_10quicktions_ulong __pyx_fuse_1__pyx_f_10quicktions__hybrid_binary_gcd2(__pyx_t_10quicktions_ulong __pyx_v_a, __pyx_t_10quicktions_ulong __pyx_v_b) {
int __pyx_v_az;
int __pyx_v_bz;
int __pyx_v_shift;
__pyx_t_10quicktions_ulong __pyx_v_diff;
__pyx_t_10quicktions_ulong __pyx_r;
/* … */
/* function exit code */
__pyx_L0:;
return __pyx_r;
}
static __pyx_t_10quicktions_uint __pyx_fuse_2__pyx_f_10quicktions__hybrid_binary_gcd2(__pyx_t_10quicktions_uint __pyx_v_a, __pyx_t_10quicktions_uint __pyx_v_b) {
int __pyx_v_az;
int __pyx_v_bz;
int __pyx_v_shift;
__pyx_t_10quicktions_uint __pyx_v_diff;
__pyx_t_10quicktions_uint __pyx_r;
/* … */
/* function exit code */
__pyx_L0:;
return __pyx_r;
}
0318: cdef cunumber _hybrid_binary_gcd2(cunumber a, cunumber b) noexcept:
0319: # See https://en.algorithmica.org/hpc/algorithms/gcd/
0320: # See https://lemire.me/blog/2024/04/13/greatest-common-divisor-the-extended-euclidean-algorithm-and-speed/
+0321: 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) {
/* … */
}
+0322: a,b = b,a
__pyx_t_2 = __pyx_v_b;
__pyx_t_3 = __pyx_v_a;
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
/* … */
__pyx_t_2 = __pyx_v_b;
__pyx_t_3 = __pyx_v_a;
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
/* … */
__pyx_t_2 = __pyx_v_b;
__pyx_t_3 = __pyx_v_a;
__pyx_v_a = __pyx_t_2;
__pyx_v_b = __pyx_t_3;
+0323: 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) {
/* … */
}
+0324: 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;
+0325: a %= b
__pyx_v_a = (__pyx_v_a % __pyx_v_b); /* … */ __pyx_v_a = (__pyx_v_a % __pyx_v_b); /* … */ __pyx_v_a = (__pyx_v_a % __pyx_v_b);
+0326: 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) {
/* … */
}
+0327: 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;
0328:
+0329: cdef int az = trailing_zeros(a)
__pyx_v_az = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); /* … */ __pyx_v_az = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_a); /* … */ __pyx_v_az = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_a);
+0330: cdef int bz = trailing_zeros(b)
__pyx_v_bz = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); /* … */ __pyx_v_bz = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_b); /* … */ __pyx_v_bz = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_b);
+0331: cdef int shift = min(az, bz)
__pyx_t_4 = __pyx_v_bz;
__pyx_t_5 = __pyx_v_az;
__pyx_t_1 = (__pyx_t_4 < __pyx_t_5);
if (__pyx_t_1) {
__pyx_t_6 = __pyx_t_4;
} else {
__pyx_t_6 = __pyx_t_5;
}
__pyx_v_shift = __pyx_t_6;
/* … */
__pyx_t_4 = __pyx_v_bz;
__pyx_t_5 = __pyx_v_az;
__pyx_t_1 = (__pyx_t_4 < __pyx_t_5);
if (__pyx_t_1) {
__pyx_t_6 = __pyx_t_4;
} else {
__pyx_t_6 = __pyx_t_5;
}
__pyx_v_shift = __pyx_t_6;
/* … */
__pyx_t_4 = __pyx_v_bz;
__pyx_t_5 = __pyx_v_az;
__pyx_t_1 = (__pyx_t_4 < __pyx_t_5);
if (__pyx_t_1) {
__pyx_t_6 = __pyx_t_4;
} else {
__pyx_t_6 = __pyx_t_5;
}
__pyx_v_shift = __pyx_t_6;
+0332: b >>= bz
__pyx_v_b = (__pyx_v_b >> __pyx_v_bz); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_bz); /* … */ __pyx_v_b = (__pyx_v_b >> __pyx_v_bz);
0333:
0334: cdef cunumber diff
0335:
+0336: while a != 0:
while (1) {
__pyx_t_1 = (__pyx_v_a != 0);
if (!__pyx_t_1) break;
/* … */
while (1) {
__pyx_t_1 = (__pyx_v_a != 0);
if (!__pyx_t_1) break;
/* … */
while (1) {
__pyx_t_1 = (__pyx_v_a != 0);
if (!__pyx_t_1) break;
+0337: a >>= az
__pyx_v_a = (__pyx_v_a >> __pyx_v_az);
/* … */
__pyx_v_a = (__pyx_v_a >> __pyx_v_az);
/* … */
__pyx_v_a = (__pyx_v_a >> __pyx_v_az);
+0338: diff = b - a if b > a else a - b
__pyx_t_1 = (__pyx_v_b > __pyx_v_a);
if (__pyx_t_1) {
__pyx_t_3 = (__pyx_v_b - __pyx_v_a);
} else {
__pyx_t_3 = (__pyx_v_a - __pyx_v_b);
}
__pyx_v_diff = __pyx_t_3;
/* … */
__pyx_t_1 = (__pyx_v_b > __pyx_v_a);
if (__pyx_t_1) {
__pyx_t_3 = (__pyx_v_b - __pyx_v_a);
} else {
__pyx_t_3 = (__pyx_v_a - __pyx_v_b);
}
__pyx_v_diff = __pyx_t_3;
/* … */
__pyx_t_1 = (__pyx_v_b > __pyx_v_a);
if (__pyx_t_1) {
__pyx_t_3 = (__pyx_v_b - __pyx_v_a);
} else {
__pyx_t_3 = (__pyx_v_a - __pyx_v_b);
}
__pyx_v_diff = __pyx_t_3;
+0339: if b > a:
__pyx_t_1 = (__pyx_v_b > __pyx_v_a);
if (__pyx_t_1) {
/* … */
}
/* … */
__pyx_t_1 = (__pyx_v_b > __pyx_v_a);
if (__pyx_t_1) {
/* … */
}
/* … */
__pyx_t_1 = (__pyx_v_b > __pyx_v_a);
if (__pyx_t_1) {
/* … */
}
+0340: b = a
__pyx_v_b = __pyx_v_a;
/* … */
__pyx_v_b = __pyx_v_a;
/* … */
__pyx_v_b = __pyx_v_a;
+0341: az = trailing_zeros(diff)
__pyx_v_az = __pyx_fuse_0__pyx_f_10quicktions_trailing_zeros(__pyx_v_diff);
/* … */
__pyx_v_az = __pyx_fuse_1__pyx_f_10quicktions_trailing_zeros(__pyx_v_diff);
/* … */
__pyx_v_az = __pyx_fuse_2__pyx_f_10quicktions_trailing_zeros(__pyx_v_diff);
+0342: a = diff
__pyx_v_a = __pyx_v_diff;
}
/* … */
__pyx_v_a = __pyx_v_diff;
}
/* … */
__pyx_v_a = __pyx_v_diff;
}
0343:
+0344: return b << shift
__pyx_r = (__pyx_v_b << __pyx_v_shift); goto __pyx_L0; /* … */ __pyx_r = (__pyx_v_b << __pyx_v_shift); goto __pyx_L0; /* … */ __pyx_r = (__pyx_v_b << __pyx_v_shift); goto __pyx_L0;
0345:
0346:
+0347: 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_1);
__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;
}
+0348: return _c_gcd(a, b) if b else a
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = (__pyx_v_b != 0); if (__pyx_t_2) { __pyx_t_3 = __pyx_v_10quicktions__c_gcd(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 348, __pyx_L1_error) __pyx_t_4 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(__pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 348, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __pyx_t_4; __pyx_t_4 = 0; } else { __pyx_t_4 = __Pyx_PyLong_From_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 348, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __pyx_t_4; __pyx_t_4 = 0; } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0349:
0350:
+0351: cdef ullong _c_gcd_euclid(ullong a, ullong b):
static __pyx_t_10quicktions_ullong __pyx_f_10quicktions__c_gcd_euclid(__pyx_t_10quicktions_ullong __pyx_v_a, __pyx_t_10quicktions_ullong __pyx_v_b) {
__pyx_t_10quicktions_ullong __pyx_r;
/* … */
/* function exit code */
__pyx_L0:;
return __pyx_r;
}
+0352: if not b:
__pyx_t_1 = (!(__pyx_v_b != 0));
if (__pyx_t_1) {
/* … */
}
+0353: return a
__pyx_r = __pyx_v_a;
goto __pyx_L0;
+0354: if a <= <ullong>INT_MAX*2+1 and b <= <ullong>INT_MAX*2+1:
__pyx_t_2 = (__pyx_v_a <= ((((__pyx_t_10quicktions_ullong)INT_MAX) * 2) + 1));
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((((__pyx_t_10quicktions_ullong)INT_MAX) * 2) + 1));
__pyx_t_1 = __pyx_t_2;
__pyx_L5_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0355: return _euclid_gcd[uint](<uint> a, <uint> b)
__pyx_r = __pyx_fuse_2__pyx_f_10quicktions__euclid_gcd(((__pyx_t_10quicktions_uint)__pyx_v_a), ((__pyx_t_10quicktions_uint)__pyx_v_b));
goto __pyx_L0;
+0356: elif a <= <ullong>LONG_MAX*2+1 and b <= <ullong>LONG_MAX*2+1:
__pyx_t_2 = (__pyx_v_a <= ((((__pyx_t_10quicktions_ullong)LONG_MAX) * 2) + 1));
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L7_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((((__pyx_t_10quicktions_ullong)LONG_MAX) * 2) + 1));
__pyx_t_1 = __pyx_t_2;
__pyx_L7_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0357: return _euclid_gcd[ulong](<ulong> a, <ulong> b)
__pyx_r = __pyx_fuse_1__pyx_f_10quicktions__euclid_gcd(((__pyx_t_10quicktions_ulong)__pyx_v_a), ((__pyx_t_10quicktions_ulong)__pyx_v_b));
goto __pyx_L0;
0358: else:
+0359: return _euclid_gcd[ullong](a, b)
/*else*/ {
__pyx_r = __pyx_fuse_0__pyx_f_10quicktions__euclid_gcd(__pyx_v_a, __pyx_v_b);
goto __pyx_L0;
}
0360:
0361:
+0362: cdef ullong _c_gcd_binary(ullong a, ullong b):
static __pyx_t_10quicktions_ullong __pyx_f_10quicktions__c_gcd_binary(__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_binary", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
return __pyx_r;
}
+0363: if not b:
__pyx_t_1 = (!(__pyx_v_b != 0));
if (__pyx_t_1) {
/* … */
}
+0364: return a
__pyx_r = __pyx_v_a;
goto __pyx_L0;
+0365: if HAS_FAST_CTZ_uint and a <= <ullong>INT_MAX*2+1 and b <= <ullong>INT_MAX*2+1:
__pyx_t_2 = (__Quicktions_HAS_FAST_CTZ_uint != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_a <= ((((__pyx_t_10quicktions_ullong)INT_MAX) * 2) + 1));
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((((__pyx_t_10quicktions_ullong)INT_MAX) * 2) + 1));
__pyx_t_1 = __pyx_t_2;
__pyx_L5_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0366: return _binary_gcd[uint](<uint> a, <uint> b)
__pyx_r = __pyx_fuse_2__pyx_f_10quicktions__binary_gcd(((__pyx_t_10quicktions_uint)__pyx_v_a), ((__pyx_t_10quicktions_uint)__pyx_v_b));
goto __pyx_L0;
+0367: elif HAS_FAST_CTZ_ulong and a <= <ullong>LONG_MAX*2+1 and b <= <ullong>LONG_MAX*2+1:
__pyx_t_2 = (__Quicktions_HAS_FAST_CTZ_ulong != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L8_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_a <= ((((__pyx_t_10quicktions_ullong)LONG_MAX) * 2) + 1));
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L8_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((((__pyx_t_10quicktions_ullong)LONG_MAX) * 2) + 1));
__pyx_t_1 = __pyx_t_2;
__pyx_L8_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0368: return _binary_gcd[ulong](<ulong> a, <ulong> b)
__pyx_r = __pyx_fuse_1__pyx_f_10quicktions__binary_gcd(((__pyx_t_10quicktions_ulong)__pyx_v_a), ((__pyx_t_10quicktions_ulong)__pyx_v_b));
goto __pyx_L0;
+0369: elif HAS_FAST_CTZ_ullong:
__pyx_t_1 = (__Quicktions_HAS_FAST_CTZ_ullong != 0);
if (__pyx_t_1) {
/* … */
}
+0370: return _binary_gcd[ullong](a, b)
__pyx_r = __pyx_fuse_0__pyx_f_10quicktions__binary_gcd(__pyx_v_a, __pyx_v_b);
goto __pyx_L0;
0371: else:
+0372: return _c_gcd_euclid(a, b)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions__c_gcd_euclid(__pyx_v_a, __pyx_v_b); if (unlikely(__pyx_t_3 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 372, __pyx_L1_error)
__pyx_r = __pyx_t_3;
goto __pyx_L0;
}
0373:
0374:
+0375: cdef ullong _c_gcd_hybrid2(ullong a, ullong b):
static __pyx_t_10quicktions_ullong __pyx_f_10quicktions__c_gcd_hybrid2(__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_hybrid2", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
return __pyx_r;
}
+0376: if not b:
__pyx_t_1 = (!(__pyx_v_b != 0));
if (__pyx_t_1) {
/* … */
}
+0377: return a
__pyx_r = __pyx_v_a;
goto __pyx_L0;
+0378: if HAS_FAST_CTZ_uint and a <= <ullong>INT_MAX*2+1 and b <= <ullong>INT_MAX*2+1:
__pyx_t_2 = (__Quicktions_HAS_FAST_CTZ_uint != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_a <= ((((__pyx_t_10quicktions_ullong)INT_MAX) * 2) + 1));
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L5_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((((__pyx_t_10quicktions_ullong)INT_MAX) * 2) + 1));
__pyx_t_1 = __pyx_t_2;
__pyx_L5_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0379: return _hybrid_binary_gcd2[uint](<uint> a, <uint> b)
__pyx_r = __pyx_fuse_2__pyx_f_10quicktions__hybrid_binary_gcd2(((__pyx_t_10quicktions_uint)__pyx_v_a), ((__pyx_t_10quicktions_uint)__pyx_v_b));
goto __pyx_L0;
+0380: elif HAS_FAST_CTZ_ulong and a <= <ullong>LONG_MAX*2+1 and b <= <ullong>LONG_MAX*2+1:
__pyx_t_2 = (__Quicktions_HAS_FAST_CTZ_ulong != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L8_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_a <= ((((__pyx_t_10quicktions_ullong)LONG_MAX) * 2) + 1));
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L8_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((((__pyx_t_10quicktions_ullong)LONG_MAX) * 2) + 1));
__pyx_t_1 = __pyx_t_2;
__pyx_L8_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0381: return _hybrid_binary_gcd2[ulong](<ulong> a, <ulong> b)
__pyx_r = __pyx_fuse_1__pyx_f_10quicktions__hybrid_binary_gcd2(((__pyx_t_10quicktions_ulong)__pyx_v_a), ((__pyx_t_10quicktions_ulong)__pyx_v_b));
goto __pyx_L0;
+0382: elif HAS_FAST_CTZ_ullong:
__pyx_t_1 = (__Quicktions_HAS_FAST_CTZ_ullong != 0);
if (__pyx_t_1) {
/* … */
}
+0383: return _hybrid_binary_gcd2[ullong](a, b)
__pyx_r = __pyx_fuse_0__pyx_f_10quicktions__hybrid_binary_gcd2(__pyx_v_a, __pyx_v_b);
goto __pyx_L0;
0384: else:
+0385: return _c_gcd_euclid(a, b)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions__c_gcd_euclid(__pyx_v_a, __pyx_v_b); if (unlikely(__pyx_t_3 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 385, __pyx_L1_error)
__pyx_r = __pyx_t_3;
goto __pyx_L0;
}
0386:
0387:
+0388: cdef ullong _c_gcd_hybrid(ullong a, ullong b):
static __pyx_t_10quicktions_ullong __pyx_f_10quicktions__c_gcd_hybrid(__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_hybrid", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
return __pyx_r;
}
+0389: if not b:
__pyx_t_1 = (!(__pyx_v_b != 0));
if (__pyx_t_1) {
/* … */
}
+0390: return a
__pyx_r = __pyx_v_a;
goto __pyx_L0;
+0391: if HAS_FAST_CTZ_uint and a <= <ullong>INT_MAX and b <= <ullong>INT_MAX:
__pyx_t_2 = (__Quicktions_HAS_FAST_CTZ_uint != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L5_bool_binop_done;
}
__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_L5_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((__pyx_t_10quicktions_ullong)INT_MAX));
__pyx_t_1 = __pyx_t_2;
__pyx_L5_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0392: return _hybrid_binary_gcd[uint](<uint> a, <uint> b)
__pyx_r = __pyx_fuse_2__pyx_f_10quicktions__hybrid_binary_gcd(((__pyx_t_10quicktions_uint)__pyx_v_a), ((__pyx_t_10quicktions_uint)__pyx_v_b));
goto __pyx_L0;
+0393: elif HAS_FAST_CTZ_ulong and a <= <ullong>LONG_MAX and b <= <ullong>LONG_MAX:
__pyx_t_2 = (__Quicktions_HAS_FAST_CTZ_ulong != 0);
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L8_bool_binop_done;
}
__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_L8_bool_binop_done;
}
__pyx_t_2 = (__pyx_v_b <= ((__pyx_t_10quicktions_ullong)LONG_MAX));
__pyx_t_1 = __pyx_t_2;
__pyx_L8_bool_binop_done:;
if (__pyx_t_1) {
/* … */
}
+0394: return _hybrid_binary_gcd[ulong](<ulong> a, <ulong> b)
__pyx_r = __pyx_fuse_1__pyx_f_10quicktions__hybrid_binary_gcd(((__pyx_t_10quicktions_ulong)__pyx_v_a), ((__pyx_t_10quicktions_ulong)__pyx_v_b));
goto __pyx_L0;
+0395: elif HAS_FAST_CTZ_ullong:
__pyx_t_1 = (__Quicktions_HAS_FAST_CTZ_ullong != 0);
if (__pyx_t_1) {
/* … */
}
+0396: return _hybrid_binary_gcd[ullong](a, b)
__pyx_r = __pyx_fuse_0__pyx_f_10quicktions__hybrid_binary_gcd(__pyx_v_a, __pyx_v_b);
goto __pyx_L0;
0397: else:
+0398: return _c_gcd_euclid(a, b)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions__c_gcd_euclid(__pyx_v_a, __pyx_v_b); if (unlikely(__pyx_t_3 == ((__pyx_t_10quicktions_ullong)-1) && PyErr_Occurred())) __PYX_ERR(0, 398, __pyx_L1_error)
__pyx_r = __pyx_t_3;
goto __pyx_L0;
}
0399:
0400:
+0401: ctypedef ullong (*fast_cgcd)(ullong a, ullong b)
typedef __pyx_t_10quicktions_ullong (*__pyx_t_10quicktions_fast_cgcd)(__pyx_t_10quicktions_ullong, __pyx_t_10quicktions_ullong);
0402:
+0403: cdef fast_cgcd _c_gcd = NULL
__pyx_v_10quicktions__c_gcd = NULL;
+0404: cdef fast_cgcd _c_gcd_best_hybrid = NULL
__pyx_v_10quicktions__c_gcd_best_hybrid = NULL;
0405:
0406:
+0407: def use_gcd_impl(name):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_3use_gcd_impl(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_2use_gcd_impl, "Change the internal GCD implementation.\n\n 'name' is one of: 'euclid', 'binary', 'hybrid'\n "); static PyMethodDef __pyx_mdef_10quicktions_3use_gcd_impl = {"use_gcd_impl", (PyCFunction)(void(*)(void))(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_10quicktions_3use_gcd_impl, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_10quicktions_2use_gcd_impl}; static PyObject *__pyx_pw_10quicktions_3use_gcd_impl(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_name = 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("use_gcd_impl (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_name_2,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, 407, __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, 407, __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, "use_gcd_impl", 0) < 0) __PYX_ERR(0, 407, __pyx_L3_error) for (Py_ssize_t i = __pyx_nargs; i < 1; i++) { if (unlikely(!values[i])) { __Pyx_RaiseArgtupleInvalid("use_gcd_impl", 1, 1, 1, i); __PYX_ERR(0, 407, __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, 407, __pyx_L3_error) } __pyx_v_name = values[0]; } goto __pyx_L6_skip; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("use_gcd_impl", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 407, __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.use_gcd_impl", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; __pyx_r = __pyx_pf_10quicktions_2use_gcd_impl(__pyx_self, __pyx_v_name); 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_2use_gcd_impl(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_name) { PyObject *__pyx_r = NULL; /* … */ /* function exit code */ __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __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.use_gcd_impl", __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_3use_gcd_impl, 0, __pyx_mstate_global->__pyx_n_u_use_gcd_impl, 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_2)) __PYX_ERR(0, 407, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_use_gcd_impl, __pyx_t_2) < 0) __PYX_ERR(0, 407, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0408: """Change the internal GCD implementation.
0409:
0410: 'name' is one of: 'euclid', 'binary', 'hybrid'
0411: """
+0412: if name not in ('euclid', 'binary', 'hybrid'):
__Pyx_INCREF(__pyx_v_name); __pyx_t_1 = __pyx_v_name; __pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_euclid, Py_NE)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 412, __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_n_u_binary, Py_NE)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 412, __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_n_u_hybrid, Py_NE)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 412, __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 (unlikely(__pyx_t_3)) { /* … */ }
+0413: raise ValueError(f"{name!r} is not one of: 'euclid', 'binary', 'hybrid'")
__pyx_t_4 = NULL;
__Pyx_INCREF(__pyx_builtin_ValueError);
__pyx_t_5 = __pyx_builtin_ValueError;
__pyx_t_6 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_name), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 413, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_6, __pyx_mstate_global->__pyx_kp_u_is_not_one_of_euclid_binary_hyb); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 413, __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, 413, __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, 413, __pyx_L1_error)
0414:
0415: global _c_gcd, GCD_IMPL
0416:
+0417: if name == 'euclid':
__pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_name, __pyx_mstate_global->__pyx_n_u_euclid, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 417, __pyx_L1_error) if (__pyx_t_3) { /* … */ goto __pyx_L7; }
+0418: _c_gcd = _c_gcd_euclid
__pyx_v_10quicktions__c_gcd = __pyx_f_10quicktions__c_gcd_euclid;
+0419: elif name == 'binary':
__pyx_t_3 = (__Pyx_PyUnicode_Equals(__pyx_v_name, __pyx_mstate_global->__pyx_n_u_binary, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 419, __pyx_L1_error) if (__pyx_t_3) { /* … */ goto __pyx_L7; }
+0420: _c_gcd = _c_gcd_binary
__pyx_v_10quicktions__c_gcd = __pyx_f_10quicktions__c_gcd_binary;
0421: else:
+0422: _c_gcd = _c_gcd_best_hybrid
/*else*/ {
__pyx_v_10quicktions__c_gcd = __pyx_v_10quicktions__c_gcd_best_hybrid;
}
__pyx_L7:;
+0423: GCD_IMPL = name
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_GCD_IMPL, __pyx_v_name) < 0) __PYX_ERR(0, 423, __pyx_L1_error)
0424:
0425:
+0426: cdef double _measure_gcd_performance(fast_cgcd func):
static double __pyx_f_10quicktions__measure_gcd_performance(__pyx_t_10quicktions_fast_cgcd __pyx_v_func) {
PyObject *__pyx_v_timer = NULL;
int __pyx_v_i;
int __pyx_v_j;
CYTHON_UNUSED int __pyx_v_e;
PyObject *__pyx_v_t = NULL;
unsigned PY_LONG_LONG __pyx_v_a;
unsigned PY_LONG_LONG __pyx_v_b;
unsigned PY_LONG_LONG __pyx_v_c;
unsigned PY_LONG_LONG __pyx_v_num;
unsigned PY_LONG_LONG __pyx_v_denom;
unsigned PY_LONG_LONG __pyx_v_n;
double __pyx_r;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_3);
__Pyx_AddTraceback("quicktions._measure_gcd_performance", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_timer);
__Pyx_XDECREF(__pyx_v_t);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
+0427: from time import perf_counter as timer
__pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_perf_counter); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_n_u_perf_counter); if (__Pyx_PyList_SET_ITEM(__pyx_t_1, 0, __pyx_mstate_global->__pyx_n_u_perf_counter) != (0)) __PYX_ERR(0, 427, __pyx_L1_error); __pyx_t_2 = __Pyx_Import(__pyx_mstate_global->__pyx_n_u_time, __pyx_t_1, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_perf_counter); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 427, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_INCREF(__pyx_t_1); __pyx_v_timer = __pyx_t_1; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
0428: cdef int i, j, e
0429:
+0430: t = timer()
__pyx_t_1 = NULL; __Pyx_INCREF(__pyx_v_timer); __pyx_t_3 = __pyx_v_timer; __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 430, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_t = __pyx_t_2; __pyx_t_2 = 0;
0431:
0432: # Fibonacci numbers:
+0433: cdef unsigned long long a = 1, b = 1, c = 2
__pyx_v_a = 1; __pyx_v_b = 1; __pyx_v_c = 2;
0434:
+0435: for i in range(1, 91):
for (__pyx_t_5 = 1; __pyx_t_5 < 91; __pyx_t_5+=1) {
__pyx_v_i = __pyx_t_5;
+0436: a, b, c = b, a+b, b+c
__pyx_t_6 = __pyx_v_b;
__pyx_t_7 = (__pyx_v_a + __pyx_v_b);
__pyx_t_8 = (__pyx_v_b + __pyx_v_c);
__pyx_v_a = __pyx_t_6;
__pyx_v_b = __pyx_t_7;
__pyx_v_c = __pyx_t_8;
+0437: if a & 3 == 0:
__pyx_t_9 = ((__pyx_v_a & 3) == 0);
if (__pyx_t_9) {
/* … */
}
}
+0438: func(a, b)
__pyx_v_func(__pyx_v_a, __pyx_v_b); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 438, __pyx_L1_error)
+0439: func(a, c)
__pyx_v_func(__pyx_v_a, __pyx_v_c); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 439, __pyx_L1_error)
0440:
0441: # Close numbers:
+0442: for i in range(1, 20):
for (__pyx_t_5 = 1; __pyx_t_5 < 20; __pyx_t_5+=1) {
__pyx_v_i = __pyx_t_5;
+0443: func(209865, 209797)
__pyx_v_func(0x333C9, 0x33385); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 443, __pyx_L1_error)
}
0444:
0445: # 'Parsed' digits with 10^n denominator:
+0446: cdef unsigned long long num = 3
__pyx_v_num = 3;
+0447: cdef unsigned long long denom = 1
__pyx_v_denom = 1;
0448: cdef unsigned long long n
0449:
+0450: for i in range(1, 18):
for (__pyx_t_5 = 1; __pyx_t_5 < 18; __pyx_t_5+=1) {
__pyx_v_i = __pyx_t_5;
+0451: num = 10 * num + (i & 7)
__pyx_v_num = ((10 * __pyx_v_num) + (__pyx_v_i & 7));
+0452: denom *= 10
__pyx_v_denom = (__pyx_v_denom * 10);
+0453: n = num
__pyx_v_n = __pyx_v_num;
+0454: for e in range(3):
for (__pyx_t_10 = 0; __pyx_t_10 < 3; __pyx_t_10+=1) {
__pyx_v_e = __pyx_t_10;
+0455: n *= 10
__pyx_v_n = (__pyx_v_n * 10);
+0456: for j in range(8):
for (__pyx_t_11 = 0; __pyx_t_11 < 8; __pyx_t_11+=1) {
__pyx_v_j = __pyx_t_11;
+0457: func(n + j, denom)
__pyx_v_func((__pyx_v_n + __pyx_v_j), __pyx_v_denom); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 457, __pyx_L1_error)
}
}
}
0458:
+0459: t = timer() - t
__pyx_t_3 = NULL; __Pyx_INCREF(__pyx_v_timer); __pyx_t_1 = __pyx_v_timer; __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_1))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_1); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_1, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+__pyx_t_4, (1-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 459, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_t_1 = PyNumber_Subtract(__pyx_t_2, __pyx_v_t); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 459, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF_SET(__pyx_v_t, __pyx_t_1); __pyx_t_1 = 0;
0460:
+0461: return t
__pyx_t_12 = __Pyx_PyFloat_AsDouble(__pyx_v_t); if (unlikely((__pyx_t_12 == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 461, __pyx_L1_error) __pyx_r = __pyx_t_12; goto __pyx_L0;
0462:
0463:
+0464: cdef int _tune_cgcd():
static int __pyx_f_10quicktions__tune_cgcd(void) {
double __pyx_v_t_binary;
double __pyx_v_t_euclid;
double __pyx_v_t_hybrid;
double __pyx_v_t_hybrid2;
PyObject *__pyx_v_name = NULL;
double __pyx_v_best_time;
int __pyx_r;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_4);
__Pyx_XDECREF(__pyx_t_5);
__Pyx_XDECREF(__pyx_t_6);
__Pyx_AddTraceback("quicktions._tune_cgcd", __pyx_clineno, __pyx_lineno, __pyx_filename);
__pyx_r = -1;
__pyx_L0:;
__Pyx_XDECREF(__pyx_v_name);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
0465: # Find fastest GCD implementation for this machine.
+0466: t_binary = _measure_gcd_performance(_c_gcd_binary)
__pyx_t_1 = __pyx_f_10quicktions__measure_gcd_performance(__pyx_f_10quicktions__c_gcd_binary); if (unlikely(__pyx_t_1 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 466, __pyx_L1_error) __pyx_v_t_binary = __pyx_t_1;
+0467: t_euclid = _measure_gcd_performance(_c_gcd_euclid)
__pyx_t_1 = __pyx_f_10quicktions__measure_gcd_performance(__pyx_f_10quicktions__c_gcd_euclid); if (unlikely(__pyx_t_1 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 467, __pyx_L1_error) __pyx_v_t_euclid = __pyx_t_1;
+0468: t_hybrid = _measure_gcd_performance(_c_gcd_hybrid)
__pyx_t_1 = __pyx_f_10quicktions__measure_gcd_performance(__pyx_f_10quicktions__c_gcd_hybrid); if (unlikely(__pyx_t_1 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 468, __pyx_L1_error) __pyx_v_t_hybrid = __pyx_t_1;
+0469: t_hybrid2 = _measure_gcd_performance(_c_gcd_hybrid2)
__pyx_t_1 = __pyx_f_10quicktions__measure_gcd_performance(__pyx_f_10quicktions__c_gcd_hybrid2); if (unlikely(__pyx_t_1 == ((double)-1) && PyErr_Occurred())) __PYX_ERR(0, 469, __pyx_L1_error) __pyx_v_t_hybrid2 = __pyx_t_1;
0470:
+0471: name = 'euclid'
__Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_euclid);
__pyx_v_name = __pyx_mstate_global->__pyx_n_u_euclid;
+0472: best_time = t_euclid
__pyx_v_best_time = __pyx_v_t_euclid;
0473:
+0474: if t_binary < best_time:
__pyx_t_2 = (__pyx_v_t_binary < __pyx_v_best_time);
if (__pyx_t_2) {
/* … */
}
+0475: name = 'binary'
__Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_binary); __Pyx_DECREF_SET(__pyx_v_name, __pyx_mstate_global->__pyx_n_u_binary);
+0476: best_time = t_binary
__pyx_v_best_time = __pyx_v_t_binary;
0477:
+0478: if t_hybrid < best_time:
__pyx_t_2 = (__pyx_v_t_hybrid < __pyx_v_best_time);
if (__pyx_t_2) {
/* … */
}
+0479: name = 'hybrid'
__Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_hybrid); __Pyx_DECREF_SET(__pyx_v_name, __pyx_mstate_global->__pyx_n_u_hybrid);
+0480: best_time = t_hybrid
__pyx_v_best_time = __pyx_v_t_hybrid;
0481:
+0482: if t_hybrid2 < best_time:
__pyx_t_2 = (__pyx_v_t_hybrid2 < __pyx_v_best_time);
if (__pyx_t_2) {
/* … */
}
+0483: name = 'hybrid'
__Pyx_INCREF(__pyx_mstate_global->__pyx_n_u_hybrid); __Pyx_DECREF_SET(__pyx_v_name, __pyx_mstate_global->__pyx_n_u_hybrid);
+0484: best_time = t_hybrid2
__pyx_v_best_time = __pyx_v_t_hybrid2;
0485:
0486: global _c_gcd_best_hybrid
+0487: _c_gcd_best_hybrid = _c_gcd_hybrid if t_hybrid < t_hybrid2 else _c_gcd_hybrid2
__pyx_t_2 = (__pyx_v_t_hybrid < __pyx_v_t_hybrid2);
if (__pyx_t_2) {
__pyx_t_3 = __pyx_f_10quicktions__c_gcd_hybrid;
} else {
__pyx_t_3 = __pyx_f_10quicktions__c_gcd_hybrid2;
}
__pyx_v_10quicktions__c_gcd_best_hybrid = __pyx_t_3;
0488:
0489: #print(f"E: {t_euclid * 1_000_000:.2f}, B: {t_binary * 1_000_000:.2f}, H1: {t_hybrid * 1_000_000:.2f}, H2: {t_hybrid2 * 1_000_000:.2f}")
+0490: use_gcd_impl(name)
__pyx_t_5 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_mstate_global->__pyx_n_u_use_gcd_impl); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __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[2] = {__pyx_t_5, __pyx_v_name}; __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+__pyx_t_7, (2-__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, 490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
0491:
+0492: return 0
__pyx_r = 0; goto __pyx_L0;
0493:
+0494: _tune_cgcd()
__pyx_t_4 = __pyx_f_10quicktions__tune_cgcd(); if (unlikely(__pyx_t_4 == ((int)-1) && PyErr_Occurred())) __PYX_ERR(0, 494, __pyx_L1_error)
0495:
0496:
+0497: cdef _gcd_fallback(a: int, b: int):
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_5);
__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;
}
0498: """Fallback GCD implementation if _PyLong_GCD() is not available.
0499: """
0500: # Try doing the computation in C space. If the numbers are too
0501: # large at the beginning, do object calculations until they are small enough.
0502: cdef ullong au, bu
0503: cdef long long ai, bi
0504:
+0505: if HAS_ISLONGLONG:
__pyx_t_1 = (__Quicktions_HAS_ISLONGLONG != 0);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+0506: if PyLong_IsLongLong(a) and PyLong_IsLongLong(b):
__pyx_t_2 = __Quicktions_PyLong_IsLongLong(__pyx_v_a); if (__pyx_t_2) { } else { __pyx_t_1 = __pyx_t_2; goto __pyx_L5_bool_binop_done; } __pyx_t_2 = __Quicktions_PyLong_IsLongLong(__pyx_v_b); __pyx_t_1 = __pyx_t_2; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+0507: ai, bi = a, b
__pyx_t_3 = __Pyx_PyLong_As_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 507, __pyx_L1_error) __pyx_t_4 = __Pyx_PyLong_As_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_4 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 507, __pyx_L1_error) __pyx_v_ai = __pyx_t_3; __pyx_v_bi = __pyx_t_4;
+0508: au = _abs(ai)
__pyx_v_au = __pyx_f_10quicktions__abs(__pyx_v_ai);
+0509: bu = _abs(bi)
__pyx_v_bu = __pyx_f_10quicktions__abs(__pyx_v_bi);
+0510: return _py_gcd(au, bu)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __pyx_f_10quicktions__py_gcd(__pyx_v_au, __pyx_v_bu); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 510, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0511: else:
0512: # Optimistically try to switch to C space.
+0513: try:
/*else*/ {
{
/*try:*/ {
/* … */
}
/* … */
__pyx_L9_except_error:;
__Pyx_XGIVEREF(__pyx_t_6);
__Pyx_XGIVEREF(__pyx_t_7);
__Pyx_XGIVEREF(__pyx_t_8);
__Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
goto __pyx_L1_error;
__pyx_L10_except_return:;
__Pyx_XGIVEREF(__pyx_t_6);
__Pyx_XGIVEREF(__pyx_t_7);
__Pyx_XGIVEREF(__pyx_t_8);
__Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
goto __pyx_L0;
__pyx_L8_exception_handled:;
__Pyx_XGIVEREF(__pyx_t_6);
__Pyx_XGIVEREF(__pyx_t_7);
__Pyx_XGIVEREF(__pyx_t_8);
__Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8);
}
}
__pyx_L3:;
+0514: 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, 514, __pyx_L7_error) __pyx_t_3 = __Pyx_PyLong_As_PY_LONG_LONG(__pyx_v_b); if (unlikely((__pyx_t_3 == (PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 514, __pyx_L7_error) __pyx_v_ai = __pyx_t_4; __pyx_v_bi = __pyx_t_3;
+0515: except OverflowError:
__pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_OverflowError); if (__pyx_t_9) { __Pyx_ErrRestore(0,0,0); goto __pyx_L8_exception_handled; } goto __pyx_L9_except_error;
0516: pass
0517: else:
+0518: au = _abs(ai)
/*else:*/ {
__pyx_v_au = __pyx_f_10quicktions__abs(__pyx_v_ai);
+0519: bu = _abs(bi)
__pyx_v_bu = __pyx_f_10quicktions__abs(__pyx_v_bi);
+0520: return _py_gcd(au, bu)
__Pyx_XDECREF(__pyx_r); __pyx_t_5 = __pyx_f_10quicktions__py_gcd(__pyx_v_au, __pyx_v_bu); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 520, __pyx_L9_except_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L10_except_return; } __pyx_L7_error:; __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
0521:
0522: # Do object calculation until we reach the C space limit.
+0523: a = abs(a)
__pyx_t_5 = __Pyx_PyNumber_Absolute(__pyx_v_a); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 523, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (!(likely(PyLong_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_t_5))) __PYX_ERR(0, 523, __pyx_L1_error) __Pyx_DECREF_SET(__pyx_v_a, ((PyObject*)__pyx_t_5)); __pyx_t_5 = 0;
+0524: b = abs(b)
__pyx_t_5 = __Pyx_PyNumber_Absolute(__pyx_v_b); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 524, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (!(likely(PyLong_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None) || __Pyx_RaiseUnexpectedTypeError("int", __pyx_t_5))) __PYX_ERR(0, 524, __pyx_L1_error) __Pyx_DECREF_SET(__pyx_v_b, ((PyObject*)__pyx_t_5)); __pyx_t_5 = 0;
+0525: while b > PY_MAX_ULONGLONG:
while (1) {
__pyx_t_5 = PyObject_RichCompare(__pyx_v_b, __pyx_v_10quicktions_PY_MAX_ULONGLONG, Py_GT); __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) break;
+0526: a, b = b, a%b
__pyx_t_5 = __pyx_v_b;
__Pyx_INCREF(__pyx_t_5);
__pyx_t_10 = PyNumber_Remainder(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 526, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_10);
__Pyx_DECREF_SET(__pyx_v_a, ((PyObject*)__pyx_t_5));
__pyx_t_5 = 0;
__Pyx_DECREF_SET(__pyx_v_b, ((PyObject*)__pyx_t_10));
__pyx_t_10 = 0;
}
+0527: while b and a > PY_MAX_ULONGLONG:
while (1) {
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_v_b); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 527, __pyx_L1_error)
if (__pyx_t_2) {
} else {
__pyx_t_1 = __pyx_t_2;
goto __pyx_L19_bool_binop_done;
}
__pyx_t_10 = PyObject_RichCompare(__pyx_v_a, __pyx_v_10quicktions_PY_MAX_ULONGLONG, Py_GT); __Pyx_XGOTREF(__pyx_t_10); if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 527, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_10); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 527, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0;
__pyx_t_1 = __pyx_t_2;
__pyx_L19_bool_binop_done:;
if (!__pyx_t_1) break;
+0528: a, b = b, a%b
__pyx_t_10 = __pyx_v_b;
__Pyx_INCREF(__pyx_t_10);
__pyx_t_5 = PyNumber_Remainder(__pyx_v_a, __pyx_v_b); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 528, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF_SET(__pyx_v_a, ((PyObject*)__pyx_t_10));
__pyx_t_10 = 0;
__Pyx_DECREF_SET(__pyx_v_b, ((PyObject*)__pyx_t_5));
__pyx_t_5 = 0;
}
+0529: if not b:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_b); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 529, __pyx_L1_error) __pyx_t_2 = (!__pyx_t_1); if (__pyx_t_2) { /* … */ }
+0530: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_a); __pyx_r = __pyx_v_a; goto __pyx_L0;
+0531: return _py_gcd(a, b)
__Pyx_XDECREF(__pyx_r); __pyx_t_11 = __Pyx_PyLong_As_unsigned_PY_LONG_LONG(__pyx_v_a); if (unlikely((__pyx_t_11 == (unsigned PY_LONG_LONG)-1) && PyErr_Occurred())) __PYX_ERR(0, 531, __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, 531, __pyx_L1_error) __pyx_t_5 = __pyx_f_10quicktions__py_gcd(__pyx_t_11, __pyx_t_12); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 531, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
0532:
0533:
0534: # Constants related to the hash implementation; hash(x) is based
0535: # on the reduction of x modulo the prime _PyHASH_MODULUS.
0536:
+0537: 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, 537, __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, 537, __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, 537, __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, 537, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0538:
+0539: 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, 539, __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, 539, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_5 = __Pyx_PyLong_AsHash_t(__pyx_t_2); if (unlikely((__pyx_t_5 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 539, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_10quicktions__PyHASH_MODULUS = __pyx_t_5;
0540:
0541: # Value to be used for rationals that reduce to infinity modulo
0542: # _PyHASH_MODULUS.
+0543: 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, 543, __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, 543, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_5 = __Pyx_PyLong_AsHash_t(__pyx_t_3); if (unlikely((__pyx_t_5 == (Py_hash_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 543, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_v_10quicktions__PyHASH_INF = __pyx_t_5;
0544:
+0545: del hash_info
if (__Pyx_PyObject_DelAttrStr(__pyx_m, __pyx_mstate_global->__pyx_n_u_hash_info) < 0) __PYX_ERR(0, 545, __pyx_L1_error)
0546:
0547:
0548: # Helpers for formatting
0549:
+0550: 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;
};
0551: """Round a rational number to the nearest multiple of a given power of 10.
0552:
0553: Rounds the rational number n/d to the nearest integer multiple of
0554: 10**exponent, rounding to the nearest even integer multiple in the case of
0555: a tie. Returns a pair (sign: bool, significand: int) representing the
0556: rounded value (-1)**sign * significand * 10**exponent.
0557:
0558: If no_neg_zero is true, then the returned sign will always be False when
0559: the significand is zero. Otherwise, the sign reflects the sign of the
0560: input.
0561:
0562: d must be positive, but n and d need not be relatively prime.
0563: """
+0564: 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, 564, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 564, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0565: 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, 565, __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, 565, __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;
0566: else:
+0567: n *= 10**-exponent
/*else*/ {
__pyx_t_3 = PyNumber_Negative(__pyx_v_exponent); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 567, __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, 567, __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, 567, __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:;
0568:
0569: # The divmod quotient is correct for round-ties-towards-positive-infinity;
0570: # In the case of a tie, we zero out the least significant bit of q.
+0571: 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, 571, __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, 571, __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, 571, __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, 571, __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, 571, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __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, 571, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 571, __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, 571, __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, 571, __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, 571, __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;
+0572: 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, 572, __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, 572, __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, 572, __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) { /* … */ }
+0573: 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, 573, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_q, __pyx_t_3); __pyx_t_3 = 0;
0574:
+0575: 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, 575, __pyx_L1_error)
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 575, __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, 575, __pyx_L1_error)
__pyx_t_7 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_7 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 575, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_2 = __pyx_t_7;
}
__pyx_v_sign = __pyx_t_2;
+0576: 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, 576, __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, 576, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 576, __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, 576, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_4) != (0)) __PYX_ERR(0, 576, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_4 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0577:
0578:
+0579: 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;
}
0580: """Round a rational number to a given number of significant figures.
0581:
0582: Rounds the rational number n/d to the given number of significant figures
0583: using the round-ties-to-even rule, and returns a triple
0584: (sign: bool, significand: int, exponent: int) representing the rounded
0585: value (-1)**sign * significand * 10**exponent.
0586:
0587: In the special case where n = 0, returns a significand of zero and
0588: an exponent of 1 - figures, for compatibility with formatting.
0589: Otherwise, the returned significand satisfies
0590: 10**(figures - 1) <= significand < 10**figures.
0591:
0592: d must be positive, but n and d need not be relatively prime.
0593: figures must be positive.
0594: """
0595: # Special case for n == 0.
+0596: 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, 596, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0597: 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, 597, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 597, __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, 597, __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, 597, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_2); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 2, __pyx_t_2) != (0)) __PYX_ERR(0, 597, __pyx_L1_error); __pyx_t_2 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0598:
0599: cdef bint sign
0600:
0601: # Find integer m satisfying 10**(m - 1) <= abs(n)/d <= 10**m. (If abs(n)/d
0602: # is a power of 10, either of the two possible values for m is fine.)
+0603: 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, 603, __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, 603, __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, 603, __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;
+0604: 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, 604, __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, 604, __pyx_L1_error) __pyx_t_3 = PyLong_FromSsize_t((__pyx_t_4 - __pyx_t_5)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 604, __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, 604, __pyx_L1_error) __pyx_t_6 = PyNumber_Add(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 604, __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, 604, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_v_m = __pyx_t_5;
0605:
0606: # Round to a multiple of 10**(m - figures). The significand we get
0607: # satisfies 10**(figures - 1) <= significand <= 10**figures.
+0608: exponent = m - figures
__pyx_t_6 = PyLong_FromSsize_t((__pyx_v_m - __pyx_v_figures)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 608, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_v_exponent = __pyx_t_6; __pyx_t_6 = 0;
+0609: 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, 609, __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, 609, __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, 609, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 609, __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, 609, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 609, __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, 609, __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, 609, __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, 609, __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, 609, __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;
0610:
0611: # Adjust in the case where significand == 10**figures, to ensure that
0612: # 10**(figures - 1) <= significand < 10**figures.
+0613: if len(str(significand)) == figures + 1:
__pyx_t_6 = __Pyx_PyObject_Unicode(__pyx_v_significand); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 613, __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, 613, __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) { /* … */ }
+0614: 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, 614, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_significand, __pyx_t_6); __pyx_t_6 = 0;
+0615: 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, 615, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF_SET(__pyx_v_exponent, __pyx_t_6); __pyx_t_6 = 0;
0616:
+0617: 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, 617, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = PyTuple_New(3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 617, __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, 617, __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, 617, __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, 617, __pyx_L1_error); __pyx_t_6 = 0; __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0618:
0619:
0620: # Pattern for matching non-float-style format specifications.
+0621: cdef object _GENERAL_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
__pyx_t_2 = __pyx_v_10quicktions_re;
__Pyx_INCREF(__pyx_t_2);
0622: (?:
0623: (?P<fill>.)?
0624: (?P<align>[<>=^])
0625: )?
0626: (?P<sign>[-+ ]?)
0627: # Alt flag forces a slash and denominator in the output, even for
0628: # integer-valued Fraction objects.
0629: (?P<alt>\#)?
0630: # We don't implement the zeropad flag since there's no single obvious way
0631: # to interpret it.
0632: (?P<minimumwidth>0|[1-9][0-9]*)?
0633: (?P<thousands_sep>[,_])?
0634: $
+0635: """, re.DOTALL | re.VERBOSE).match
__pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_DOTALL); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_VERBOSE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = PyNumber_Or(__pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_9 = 0; { PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_mstate_global->__pyx_kp_u_P_fill_P_align_P_sign_Alt_flag, __pyx_t_8}; __pyx_t_3 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_compile, __pyx_callargs+__pyx_t_9, (3-__pyx_t_9) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 621, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_match); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __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_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0;
0636:
0637:
0638: # Pattern for matching float-style format specifications;
0639: # supports 'e', 'E', 'f', 'F', 'g', 'G' and '%' presentation types.
+0640: cdef object _FLOAT_FORMAT_SPECIFICATION_MATCHER = re.compile(r"""
__pyx_t_3 = __pyx_v_10quicktions_re;
__Pyx_INCREF(__pyx_t_3);
0641: (?:
0642: (?P<fill>.)?
0643: (?P<align>[<>=^])
0644: )?
0645: (?P<sign>[-+ ]?)
0646: (?P<no_neg_zero>z)?
0647: (?P<alt>\#)?
0648: # A '0' that's *not* followed by another digit is parsed as a minimum width
0649: # rather than a zeropad flag.
0650: (?P<zeropad>0(?=[0-9]))?
0651: (?P<minimumwidth>[0-9]+)?
0652: (?P<thousands_sep>[,_])?
0653: (?:\.(?P<precision>[0-9]+))?
0654: (?P<presentation_type>[eEfFgG%])
0655: $
+0656: """, 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, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_re, __pyx_mstate_global->__pyx_n_u_VERBOSE); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_6 = PyNumber_Or(__pyx_t_2, __pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_9 = 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_6}; __pyx_t_8 = __Pyx_PyObject_FastCallMethod(__pyx_mstate_global->__pyx_n_u_compile, __pyx_callargs+__pyx_t_9, (3-__pyx_t_9) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 640, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_match); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 656, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_XGOTREF(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER); __Pyx_DECREF_SET(__pyx_v_10quicktions__FLOAT_FORMAT_SPECIFICATION_MATCHER, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0;
0657:
+0658: cdef object NOINIT = object()
__pyx_t_8 = NULL; __Pyx_INCREF(__pyx_builtin_object); __pyx_t_3 = __pyx_builtin_object; __pyx_t_9 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_9, (1-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 658, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); } __Pyx_XGOTREF(__pyx_v_10quicktions_NOINIT); __Pyx_DECREF_SET(__pyx_v_10quicktions_NOINIT, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0;
0659:
0660:
+0661: 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;
0662: """A Rational number.
0663:
0664: Takes a string like '3/2' or '1.5', another Rational instance, a
0665: numerator/denominator pair, or a float.
0666:
0667: Examples
0668: --------
0669:
0670: >>> Fraction(10, -8)
0671: Fraction(-5, 4)
0672: >>> Fraction(Fraction(1, 7), 5)
0673: Fraction(1, 35)
0674: >>> Fraction(Fraction(1, 7), Fraction(2, 3))
0675: Fraction(3, 14)
0676: >>> Fraction('314')
0677: Fraction(314, 1)
0678: >>> Fraction('-35/4')
0679: Fraction(-35, 4)
0680: >>> Fraction('3.1415') # conversion from numeric string
0681: Fraction(6283, 2000)
0682: >>> Fraction('-47e-2') # string may include a decimal exponent
0683: Fraction(-47, 100)
0684: >>> Fraction(1.47) # direct construction from float (exact conversion)
0685: Fraction(6620291452234629, 4503599627370496)
0686: >>> Fraction(2.25)
0687: Fraction(9, 4)
0688: >>> from decimal import Decimal
0689: >>> Fraction(Decimal('1.47'))
0690: Fraction(147, 100)
0691:
0692: """
0693: cdef _numerator
0694: cdef _denominator
0695: cdef Py_hash_t _hash
0696:
+0697: 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, 697, __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, 697, __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, 697, __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, 697, __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, 697, __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, 697, __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, 697, __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;
}
+0698: self._hash = -1
__pyx_v_self->_hash = -1L;
+0699: if numerator is NOINIT:
__pyx_t_1 = (__pyx_v_numerator == __pyx_v_10quicktions_NOINIT);
if (__pyx_t_1) {
/* … */
}
+0700: return # fast-path for external initialisation
__pyx_r = 0;
goto __pyx_L0;
0701:
+0702: cdef bint _normalize = True
__pyx_v__normalize = 1;
+0703: if denominator is None:
__pyx_t_1 = (__pyx_v_denominator == Py_None);
if (__pyx_t_1) {
/* … */
goto __pyx_L4;
}
+0704: if type(numerator) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyLong_Type)));
if (__pyx_t_1) {
/* … */
}
+0705: 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;
+0706: 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;
+0707: return
__pyx_r = 0;
goto __pyx_L0;
0708:
+0709: elif type(numerator) is float:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_numerator)) == ((PyObject *)(&PyFloat_Type)));
if (__pyx_t_1) {
/* … */
}
0710: # Exact conversion
+0711: 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, 711, __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, 711, __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, 711, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_3);
__pyx_t_5 = __Pyx_PyList_GetItemRef(sequence, 1);
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 711, __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, 711, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_5 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 711, __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, 711, __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, 711, __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, 711, __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;
+0712: return
__pyx_r = 0;
goto __pyx_L0;
0713:
+0714: 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) {
/* … */
}
+0715: 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;
+0716: 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;
+0717: return
__pyx_r = 0;
goto __pyx_L0;
0718:
+0719: elif isinstance(numerator, unicode):
__pyx_t_1 = PyUnicode_Check(__pyx_v_numerator);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+0720: 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, 720, __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, 720, __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, 720, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 720, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 720, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); #endif __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } else { __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 720, __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;
+0721: <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, 721, __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, 721, __pyx_L1_error)
+0722: if is_normalised:
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_is_normalised); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 722, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0723: _normalize = False
__pyx_v__normalize = 0;
0724: # fall through to normalisation below
0725:
+0726: 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) {
/* … */
}
+0727: 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, 727, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_L9_bool_binop_done:;
0728: # Exact conversion
+0729: 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, 729, __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, 729, __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, 729, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_6);
__pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1);
if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 729, __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, 729, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 729, __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, 729, __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, 729, __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, 729, __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;
+0730: return
__pyx_r = 0;
goto __pyx_L0;
0731:
+0732: 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) { /* … */ }
+0733: 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, 733, __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;
+0734: 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, 734, __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;
+0735: return
__pyx_r = 0;
goto __pyx_L0;
0736:
+0737: 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, 737, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (likely(__pyx_t_1)) {
/* … */
}
+0738: 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, 738, __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, 738, __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, 738, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_3);
__pyx_t_6 = __Pyx_PyList_GetItemRef(sequence, 1);
if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 738, __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, 738, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 738, __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, 738, __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, 738, __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, 738, __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;
+0739: return
__pyx_r = 0;
goto __pyx_L0;
0740:
0741: else:
+0742: 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, 742, __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, 742, __pyx_L1_error)
}
__pyx_L5:;
0743: "instance or have the as_integer_ratio() method")
0744:
+0745: 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;
}
0746: pass # *very* normal case
0747:
+0748: 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;
}
0749: numerator, denominator = (
+0750: (<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, 750, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+0751: (<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, 751, __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;
0752: )
0753:
+0754: 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; }
+0755: 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:;
0756: numerator, denominator = (
+0757: 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, 757, __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, 757, __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, 757, __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;
+0758: 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, 758, __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, 758, __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, 758, __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;
0759: )
0760:
0761: else:
+0762: 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, 762, __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, 762, __pyx_L1_error)
}
__pyx_L4:;
0763: "Rational instances")
0764:
+0765: 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, 765, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+0766: 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, 766, __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, 766, __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, 766, __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, 766, __pyx_L1_error)
+0767: if _normalize:
if (__pyx_v__normalize) {
/* … */
}
+0768: if not isinstance(numerator, int):
__pyx_t_1 = PyLong_Check(__pyx_v_numerator);
__pyx_t_10 = (!__pyx_t_1);
if (__pyx_t_10) {
/* … */
}
+0769: numerator = int(numerator)
__pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 769, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0;
+0770: if not isinstance(denominator, int):
__pyx_t_10 = PyLong_Check(__pyx_v_denominator);
__pyx_t_1 = (!__pyx_t_10);
if (__pyx_t_1) {
/* … */
}
+0771: denominator = int(denominator)
__pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 771, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
+0772: g = _igcd(numerator, denominator)
__pyx_t_5 = __pyx_f_10quicktions__igcd(__pyx_v_numerator, __pyx_v_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 772, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_v_g = __pyx_t_5; __pyx_t_5 = 0;
0773: # NOTE: 'is' tests on integers are generally a bad idea, but
0774: # they are fast and if they fail here, it'll still be correct
+0775: 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, 775, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 775, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+0776: if g is 1:
__pyx_t_1 = (__pyx_v_g == __pyx_mstate_global->__pyx_int_1);
if (__pyx_t_1) {
/* … */
goto __pyx_L29;
}
+0777: numerator = -numerator
__pyx_t_5 = PyNumber_Negative(__pyx_v_numerator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 777, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0;
+0778: denominator = -denominator
__pyx_t_5 = PyNumber_Negative(__pyx_v_denominator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 778, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
0779: else:
+0780: g = -g
/*else*/ {
__pyx_t_5 = PyNumber_Negative(__pyx_v_g); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 780, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF_SET(__pyx_v_g, __pyx_t_5);
__pyx_t_5 = 0;
}
__pyx_L29:;
+0781: if g is not 1:
__pyx_t_1 = (__pyx_v_g != __pyx_mstate_global->__pyx_int_1);
if (__pyx_t_1) {
/* … */
}
+0782: numerator //= g
__pyx_t_5 = PyNumber_InPlaceFloorDivide(__pyx_v_numerator, __pyx_v_g); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 782, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_numerator, __pyx_t_5); __pyx_t_5 = 0;
+0783: denominator //= g
__pyx_t_5 = PyNumber_InPlaceFloorDivide(__pyx_v_denominator, __pyx_v_g); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF_SET(__pyx_v_denominator, __pyx_t_5); __pyx_t_5 = 0;
+0784: 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;
+0785: 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;
0786:
+0787: @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, 787, __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, 787, __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, 787, __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, 787, __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, 787, __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, 787, __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_6 = __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[2])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 787, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_number, __pyx_t_6) < 0) __PYX_ERR(0, 787, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GetNameInClass(__pyx_t_6, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_number); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 787, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 787, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 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, 787, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0788: def from_number(cls, number):
0789: """Converts a finite real number to a rational number, exactly.
0790:
0791: Beware that Fraction.from_number(0.3) != Fraction(3, 10).
0792:
0793: """
+0794: 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) {
/* … */
}
+0795: 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, 795, __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;
0796:
+0797: elif isinstance(number, int):
__pyx_t_1 = PyLong_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0798: 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, 798, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0799:
+0800: elif isinstance(number, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0801: 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, 801, __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, 801, __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, 801, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1);
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __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, 801, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 801, __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, 801, __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, 801, __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, 801, __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;
+0802: 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, 802, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
0803:
+0804: 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, 804, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+0805: 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, 805, __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, 805, __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, 805, __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;
0806:
+0807: 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, 807, __pyx_L1_error) __pyx_t_1 = __pyx_t_10; __pyx_L6_bool_binop_done:; if (likely(__pyx_t_1)) { /* … */ }
+0808: 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, 808, __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, 808, __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, 808, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PyList_GetItemRef(sequence, 1);
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 808, __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, 808, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 808, __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, 808, __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, 808, __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, 808, __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;
+0809: 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, 809, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
0810:
0811: else:
+0812: 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, 812, __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, 812, __pyx_L1_error)
}
0813: "have the as_integer_ratio() method")
0814:
+0815: @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, 815, __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, 815, __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, 815, __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, 815, __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, 815, __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, 815, __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[3])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 815, __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, 815, __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, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_6 = __Pyx_Method_ClassMethod(__pyx_t_3); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 815, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __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_6) < 0) __PYX_ERR(0, 815, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
0816: def from_float(cls, f):
0817: """Converts a finite float to a rational number, exactly.
0818:
0819: Beware that Fraction.from_float(0.3) != Fraction(3, 10).
0820:
0821: """
+0822: 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);
}
+0823: 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, 823, __pyx_L3_error)
__Pyx_GOTREF(__pyx_t_4);
}
__pyx_v_ratio = __pyx_t_4;
__pyx_t_4 = 0;
+0824: 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;
0825: pass # not something we can convert, raise concrete exceptions below
0826: else:
+0827: 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, 827, __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, 827, __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;
0828:
+0829: 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, 829, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_8) { /* … */ }
+0830: 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, 830, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
+0831: elif not isinstance(f, float):
__pyx_t_8 = PyFloat_Check(__pyx_v_f);
__pyx_t_10 = (!__pyx_t_8);
if (unlikely(__pyx_t_10)) {
/* … */
}
+0832: 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, 832, __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, 832, __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, 832, __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, 832, __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, 832, __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__2;
__pyx_t_15[4] = __pyx_t_14;
__pyx_t_15[5] = __pyx_mstate_global->__pyx_kp_u__3;
__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, 832, __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, 832, __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, 832, __pyx_L1_error)
+0833: 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, 833, __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, 833, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_t_10)) { /* … */ }
+0834: 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, 834, __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, 834, __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, 834, __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_;
__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, 834, __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, 834, __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, 834, __pyx_L1_error)
+0835: 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, 835, __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, 835, __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, 835, __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_; __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, 835, __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, 835, __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, 835, __pyx_L1_error)
0836:
+0837: @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, 837, __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, 837, __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, 837, __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, 837, __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, 837, __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, 837, __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_6 = __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[4])); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 837, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); if (__Pyx_SetItemOnTypeDict(__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_decimal, __pyx_t_6) < 0) __PYX_ERR(0, 837, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_GetNameInClass(__pyx_t_6, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_from_decimal); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 837, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __pyx_t_3 = __Pyx_Method_ClassMethod(__pyx_t_6); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 837, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 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, 837, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0838: def from_decimal(cls, dec):
0839: """Converts a finite Decimal instance to a rational number, exactly."""
0840: cdef Py_ssize_t exp
+0841: 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, 841, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ goto __pyx_L3; }
+0842: 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, 842, __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, 842, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
}
__Pyx_DECREF_SET(__pyx_v_dec, __pyx_t_1);
__pyx_t_1 = 0;
+0843: 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, 843, __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:;
+0844: raise TypeError(
__pyx_t_4 = NULL;
__Pyx_INCREF(__pyx_builtin_TypeError);
__pyx_t_5 = __pyx_builtin_TypeError;
+0845: 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, 845, __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, 845, __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, 845, __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, 845, __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, 845, __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__2; __pyx_t_11[4] = __pyx_t_10; __pyx_t_11[5] = __pyx_mstate_global->__pyx_kp_u__3; __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, 845, __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, 844, __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, 844, __pyx_L1_error)
+0846: 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, 846, __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, 846, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0847: 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, 847, __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, 847, __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, 847, __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_;
__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, 847, __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, 847, __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, 847, __pyx_L1_error)
+0848: 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, 848, __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, 848, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_7)) { /* … */ }
+0849: 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, 849, __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, 849, __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, 849, __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_;
__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, 849, __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, 849, __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, 849, __pyx_L1_error)
0850:
+0851: 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, 851, __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, 851, __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, 851, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_10); __pyx_t_3 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 851, __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, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_10); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 851, __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, 851, __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, 851, __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, 851, __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;
+0852: 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, 852, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0853:
+0854: 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[5])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 854, __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, 854, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0855: """Return True if the Fraction is an integer."""
+0856: 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, 856, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0857:
+0858: 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[6])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 858, __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, 858, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
0859: """Return a pair of integers, whose ratio is equal to the original Fraction.
0860:
0861: The ratio is in lowest terms and has a positive denominator.
0862: """
+0863: return (self._numerator, self._denominator)
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 863, __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, 863, __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, 863, __pyx_L1_error); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0864:
+0865: 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, 865, __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, 865, __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, 865, __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, 865, __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, 865, __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[7])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 865, __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, 865, __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, 865, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]);
0866: """Closest Fraction to self with denominator at most max_denominator.
0867:
0868: >>> Fraction('3.141592653589793').limit_denominator(10)
0869: Fraction(22, 7)
0870: >>> Fraction('3.141592653589793').limit_denominator(100)
0871: Fraction(311, 99)
0872: >>> Fraction(4321, 8765).limit_denominator(10000)
0873: Fraction(4321, 8765)
0874:
0875: """
0876: # Algorithm notes: For any real number x, define a *best upper
0877: # approximation* to x to be a rational number p/q such that:
0878: #
0879: # (1) p/q >= x, and
0880: # (2) if p/q > r/s >= x then s > q, for any rational r/s.
0881: #
0882: # Define *best lower approximation* similarly. Then it can be
0883: # proved that a rational number is a best upper or lower
0884: # approximation to x if, and only if, it is a convergent or
0885: # semiconvergent of the (unique shortest) continued fraction
0886: # associated to x.
0887: #
0888: # To find a best rational approximation with denominator <= M,
0889: # we find the best upper and lower approximations with
0890: # denominator <= M and take whichever of these is closer to x.
0891: # In the event of a tie, the bound with smaller denominator is
0892: # chosen. If both denominators are equal (which can happen
0893: # only when max_denominator == 1 and self is midway between
0894: # two integers) the lower bound---i.e., the floor of self, is
0895: # taken.
0896:
+0897: 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, 897, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 897, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (unlikely(__pyx_t_2)) { /* … */ }
+0898: 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, 898, __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, 898, __pyx_L1_error)
+0899: 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, 899, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 899, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0900: 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, 900, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_1); } __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;
0901:
+0902: 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;
+0903: 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;
+0904: while True:
while (1) {
+0905: a = n//d
__pyx_t_4 = PyNumber_FloorDivide(__pyx_v_n, __pyx_v_d); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 905, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_4); __pyx_t_4 = 0;
+0906: q2 = q0+a*q1
__pyx_t_4 = PyNumber_Multiply(__pyx_v_a, __pyx_v_q1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 906, __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, 906, __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;
+0907: 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, 907, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_6); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 907, __pyx_L1_error) __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; if (__pyx_t_2) { /* … */ }
+0908: break
goto __pyx_L6_break;
+0909: 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, 909, __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, 909, __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;
+0910: 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, 910, __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, 910, __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:;
0911:
+0912: 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, 912, __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, 912, __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;
0913:
0914: # Determine which of the candidates (p0+k*p1)/(q0+k*q1) and p1/q1 is
0915: # closer to self. The distance between them is 1/(q1*(q0+k*q1)), while
0916: # the distance from p1/q1 to self is d/(q1*self._denominator). So we
0917: # need to compare 2*(q0+k*q1) with self._denominator/d.
+0918: 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, 918, __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, 918, __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, 918, __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, 918, __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, 918, __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, 918, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+0919: 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, 919, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
0920: else:
+0921: 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, 921, __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, 921, __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, 921, __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, 921, __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, 921, __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;
}
0922:
+0923: @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;
}
0924: def numerator(self):
+0925: return self._numerator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_numerator); __pyx_r = __pyx_v_self->_numerator; goto __pyx_L0;
0926:
+0927: @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;
}
0928: def denominator(self):
+0929: return self._denominator
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_self->_denominator); __pyx_r = __pyx_v_self->_denominator; goto __pyx_L0;
0930:
+0931: 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; }
0932: """repr(self)"""
+0933: 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, 933, __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, 933, __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, 933, __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, 933, __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;
+0934: 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, 934, __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, 934, __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__3;
0935:
+0936: 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; }
0937: """str(self)"""
+0938: 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, 938, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0939: 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, 939, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0940: else:
+0941: 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, 941, __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, 941, __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, 941, __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;
}
0942:
+0943: @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_n = NULL;
PyObject *__pyx_v_d = NULL;
PyObject *__pyx_v_body = NULL;
PyObject *__pyx_v_sign = NULL;
PyObject *__pyx_v_padding = NULL;
Py_ssize_t __pyx_v_half;
PyObject *__pyx_r = NULL;
/* … */
/* function exit code */
__pyx_L1_error:;
__Pyx_XDECREF(__pyx_t_1);
__Pyx_XDECREF(__pyx_t_2);
__Pyx_XDECREF(__pyx_t_7);
__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_n);
__Pyx_XDECREF(__pyx_v_d);
__Pyx_XDECREF(__pyx_v_body);
__Pyx_XDECREF(__pyx_v_sign);
__Pyx_XDECREF(__pyx_v_padding);
__Pyx_XGIVEREF(__pyx_r);
__Pyx_RefNannyFinishContext();
return __pyx_r;
}
0944: cdef _format_general(self, dict match):
0945: """Helper method for __format__.
0946:
0947: Handles fill, alignment, signs, and thousands separators in the
0948: case of no presentation type.
0949: """
0950: # Validate and parse the format specifier.
+0951: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 951, __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, 951, __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, 951, __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;
+0952: 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, 952, __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, 952, __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, 952, __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, 952, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_align = __pyx_t_4;
+0953: 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, 953, __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, 953, __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, 953, __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, 953, __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, 953, __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;
+0954: 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, 954, __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, 954, __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, 954, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_alternate_form = __pyx_t_3;
+0955: 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, 955, __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, 955, __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, 955, __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, 955, __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, 955, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_minimumwidth = __pyx_t_5;
+0956: 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, 956, __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, 956, __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, 956, __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;
0957:
0958: cdef Py_ssize_t first_pos # Py2/3.5-only
0959:
0960: # Determine the body and sign representation.
+0961: n, d = self._numerator, self._denominator
__pyx_t_2 = __pyx_v_self->_numerator; __Pyx_INCREF(__pyx_t_2); __pyx_t_1 = __pyx_v_self->_denominator; __Pyx_INCREF(__pyx_t_1); __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_1; __pyx_t_1 = 0;
+0962: if d > 1 or alternate_form:
__pyx_t_1 = PyObject_RichCompare(__pyx_v_d, __pyx_mstate_global->__pyx_int_1, Py_GT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 962, __pyx_L1_error) __pyx_t_6 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 962, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (!__pyx_t_6) { } else { __pyx_t_3 = __pyx_t_6; goto __pyx_L12_bool_binop_done; } __pyx_t_3 = __pyx_v_alternate_form; __pyx_L12_bool_binop_done:; if (__pyx_t_3) { /* … */ goto __pyx_L11; }
+0963: body = f"{abs(n):{thousands_sep}}/{d:{thousands_sep}}"
__pyx_t_1 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = __Pyx_PyObject_Format(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 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, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_Format(__pyx_v_d, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_8[0] = __pyx_t_7; __pyx_t_8[1] = __pyx_mstate_global->__pyx_kp_u__6; __pyx_t_8[2] = __pyx_t_1; __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_8, 3, __Pyx_PyUnicode_GET_LENGTH(__pyx_t_7) + 1 + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_1), 127 | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_7) | __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_1)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_body = ((PyObject*)__pyx_t_2); __pyx_t_2 = 0;
0964: else:
+0965: body = f"{abs(n):{thousands_sep}}"
/*else*/ {
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 965, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_1 = __Pyx_PyObject_FormatSimple(__pyx_v_thousands_sep, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 965, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_7 = __Pyx_PyObject_Format(__pyx_t_2, __pyx_t_1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 965, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_body = ((PyObject*)__pyx_t_7);
__pyx_t_7 = 0;
}
__pyx_L11:;
+0966: sign = '-' if n < 0 else pos_sign
__pyx_t_1 = PyObject_RichCompare(__pyx_v_n, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 966, __pyx_L1_error) __pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 966, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_3) { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__9); __pyx_t_7 = __pyx_mstate_global->__pyx_kp_u__9; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_7 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_7; __pyx_t_7 = 0;
0967:
0968: # Pad with fill character if necessary and return.
+0969: 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, 969, __pyx_L1_error) __pyx_t_9 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_body); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 969, __pyx_L1_error) __pyx_t_7 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_5) - __pyx_t_9)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 969, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = PyNumber_Multiply(__pyx_v_fill, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 969, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_v_padding = __pyx_t_1; __pyx_t_1 = 0;
+0970: if align == u">":
switch (__pyx_v_align) {
case 62:
/* … */
break;
case 60:
+0971: return padding + sign + body
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Add(__pyx_v_padding, __pyx_v_sign); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 971, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_v_body); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 971, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0;
+0972: elif align == u"<":
break;
case 94:
+0973: return sign + body + padding
__Pyx_XDECREF(__pyx_r); __pyx_t_7 = PyNumber_Add(__pyx_v_sign, __pyx_v_body); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 973, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_v_padding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 973, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+0974: elif align == u"^":
break;
default:
+0975: half = len(padding) // 2
__pyx_t_9 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_9 == ((Py_ssize_t)-1))) __PYX_ERR(0, 975, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_9, 2, 1);
+0976: return padding[:half] + sign + body + padding[half:]
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_PyObject_GetSlice(__pyx_v_padding, 0, __pyx_v_half, NULL, NULL, NULL, 0, 1, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 976, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = PyNumber_Add(__pyx_t_1, __pyx_v_sign); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 976, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Add(__pyx_t_7, __pyx_v_body); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 976, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = __Pyx_PyObject_GetSlice(__pyx_v_padding, __pyx_v_half, 0, NULL, NULL, NULL, 1, 0, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 976, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 976, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
0977: else: # align == u"="
+0978: 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, 978, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_7 = PyNumber_Add(__pyx_t_2, __pyx_v_body); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 978, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = __pyx_t_7; __pyx_t_7 = 0; goto __pyx_L0; break; }
0979:
+0980: @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_7genexpr__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;
}
0981: cdef _format_float_style(self, dict match):
0982: """Helper method for __format__; handles float presentation types."""
+0983: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 983, __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, 983, __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, 983, __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;
+0984: align = match["align"] or ">"
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 984, __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, 984, __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, 984, __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;
+0985: 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, 985, __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, 985, __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, 985, __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, 985, __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, 985, __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;
+0986: 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, 986, __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, 986, __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, 986, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_no_neg_zero = __pyx_t_3;
+0987: 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, 987, __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, 987, __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, 987, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_alternate_form = __pyx_t_3;
+0988: cdef bint zeropad = match["zeropad"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 988, __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, 988, __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, 988, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_zeropad = __pyx_t_3;
+0989: 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, 989, __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, 989, __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, 989, __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, 989, __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, 989, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_minimumwidth = __pyx_t_4;
+0990: thousands_sep = match["thousands_sep"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable");
__PYX_ERR(0, 990, __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, 990, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_v_thousands_sep = __pyx_t_2;
__pyx_t_2 = 0;
+0991: 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, 991, __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, 991, __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, 991, __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, 991, __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, 991, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_precision = __pyx_t_4;
+0992: 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, 992, __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, 992, __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, 992, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_presentation_type = __pyx_t_5;
+0993: 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;
+0994: cdef bint trim_point = not alternate_form
__pyx_v_trim_point = (!__pyx_v_alternate_form);
+0995: 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;
0996:
0997: cdef bint negative, scientific
0998: cdef Py_ssize_t exponent, figures
0999:
1000: # Round to get the digits we need, figure out where to place the point,
1001: # and decide whether to use scientific notation. 'point_pos' is the
1002: # relative to the _end_ of the digit string: that is, it's the number
1003: # of digits that should follow the point.
+1004: if presentation_type in u"fF%":
switch (__pyx_v_presentation_type) {
case 37:
case 70:
case 0x66:
/* … */
break;
default:
+1005: exponent = -precision
__pyx_v_exponent = (-__pyx_v_precision);
+1006: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37);
if (__pyx_t_3) {
/* … */
}
+1007: exponent -= 2
__pyx_v_exponent = (__pyx_v_exponent - 2);
+1008: 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, 1008, __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, 1008, __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, 1008, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_8);
__pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1);
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1008, __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, 1008, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1008, __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, 1008, __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, 1008, __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, 1008, __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, 1008, __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;
+1009: 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, 1009, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
+1010: scientific = False
__pyx_v_scientific = 0;
+1011: point_pos = precision
__pyx_t_9 = PyLong_FromSsize_t(__pyx_v_precision); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1011, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_v_point_pos = __pyx_t_9; __pyx_t_9 = 0;
1012: else: # presentation_type in "eEgG"
1013: figures = (
+1014: 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:
+1015: if presentation_type in u"gG"
case 0x67:
+1016: else precision + 1
__pyx_t_4 = (__pyx_v_precision + 1);
break;
}
__pyx_v_figures = __pyx_t_4;
1017: )
+1018: 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, 1018, __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, 1018, __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, 1018, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_9); __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1018, __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, 1018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1018, __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, 1018, __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, 1018, __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, 1018, __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, 1018, __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, 1018, __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;
+1019: 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);
1020: scientific = (
+1021: 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;
}
+1022: 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;
}
+1023: 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;
1024: )
+1025: 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, 1025, __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, 1025, __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;
}
1026:
1027: # Get the suffix - the part following the digits, if any.
+1028: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37);
if (__pyx_t_3) {
/* … */
goto __pyx_L21;
}
+1029: suffix = "%"
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__11);
__pyx_v_suffix = __pyx_mstate_global->__pyx_kp_u__11;
+1030: elif scientific:
if (__pyx_v_scientific) {
/* … */
goto __pyx_L21;
}
1031: #suffix = f"{exponent_indicator}{exponent + point_pos:+03d}"
+1032: 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, 1032, __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, 1032, __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, 1032, __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, 1032, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 1032, __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, 1032, __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;
1033: else:
+1034: suffix = ""
/*else*/ {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__10);
__pyx_v_suffix = __pyx_mstate_global->__pyx_kp_u__10;
}
__pyx_L21:;
1035:
1036: # String of output digits, padded sufficiently with zeros on the left
1037: # so that we'll have at least one digit before the decimal point.
+1038: 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, 1038, __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, 1038, __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, 1038, __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, 1038, __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;
1039:
1040: # Before padding, the output has the form f"{sign}{leading}{trailing}",
1041: # where `leading` includes thousands separators if necessary and
1042: # `trailing` includes the decimal separator where appropriate.
+1043: 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;
+1044: 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, 1044, __pyx_L1_error) __pyx_t_8 = PyLong_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1044, __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, 1044, __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, 1044, __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, 1044, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_leading = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1045: 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, 1045, __pyx_L1_error) __pyx_t_1 = PyLong_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1045, __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, 1045, __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, 1045, __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, 1045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_frac_part = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0;
+1046: if trim_zeros:
if (__pyx_v_trim_zeros) {
/* … */
}
+1047: 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, 1047, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF_SET(__pyx_v_frac_part, ((PyObject*)__pyx_t_8)); __pyx_t_8 = 0;
+1048: 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, 1048, __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_);
__pyx_t_8 = __pyx_mstate_global->__pyx_kp_u_;
}
__pyx_v_separator = ((PyObject*)__pyx_t_8);
__pyx_t_8 = 0;
+1049: 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, 1049, __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, 1049, __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;
1050:
1051: # Do zero padding if required.
+1052: if zeropad:
if (__pyx_v_zeropad) {
/* … */
}
+1053: 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, 1053, __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, 1053, __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, 1053, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_min_leading = __pyx_t_1; __pyx_t_1 = 0;
1054: # When adding thousands separators, they'll be added to the
1055: # zero-padded portion too, so we need to compensate.
+1056: 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, 1056, __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;
+1057: 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, 1057, __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, 1057, __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, 1057, __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, 1057, __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; }
1058: )
1059:
1060: # Insert thousands separators if required.
+1061: if thousands_sep:
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_thousands_sep); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1061, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+1062: 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, 1062, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_13 - 1), 3, 1));
+1063: 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, 1063, __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, 1063, __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, 1063, __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, 1063, __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;
+1064: thousands_sep + leading[pos : pos + 3]
__pyx_t_9 = __Pyx_PyUnicode_Substring(__pyx_v_leading, __pyx_7genexpr__pyx_v_pos, (__pyx_7genexpr__pyx_v_pos + 3)); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 1064, __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, 1064, __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, 1063, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; } } /* exit inner scope */
+1065: 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, 1065, __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_7genexpr__pyx_v_pos = __pyx_t_12;
1066: ])
1067:
1068: # We now have a sign and a body. Pad with fill character if necessary
1069: # and return.
+1070: body = leading + trailing
__pyx_t_1 = __Pyx_PyUnicode_Concat(__pyx_v_leading, __pyx_v_trailing); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1070, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_body = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1071: 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, 1071, __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, 1071, __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, 1071, __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, 1071, __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;
+1072: 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, 1072, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+1073: 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, 1073, __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, 1073, __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;
+1074: 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, 1074, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+1075: 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, 1075, __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, 1075, __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;
+1076: 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, 1076, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+1077: half = len(padding) // 2
__pyx_t_4 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1077, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_4, 2, 1);
+1078: 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, 1078, __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, 1078, __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, 1078, __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, 1078, __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, 1078, __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;
1079: else: # align == "="
+1080: 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, 1080, __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, 1080, __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;
}
1081:
+1082: 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[8])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1082, __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, 1082, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1083: """Format this fraction according to the given format specification."""
1084:
+1085: 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, 1085, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __Pyx_INCREF(__pyx_t_1); __pyx_v_match = __pyx_t_1; __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1085, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+1086: 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, 1086, __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, 1086, __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, 1086, __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;
1087:
+1088: 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, 1088, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_INCREF(__pyx_t_3); __Pyx_DECREF_SET(__pyx_v_match, __pyx_t_3); __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1088, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_5) { /* … */ }
1089: # Refuse the temptation to guess if both alignment _and_
1090: # zero padding are specified.
+1091: 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, 1091, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
}
__pyx_v_match_groups = __pyx_t_3;
__pyx_t_3 = 0;
+1092: 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, 1092, __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, 1092, __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) { /* … */ }
+1093: 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, 1093, __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, 1093, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1094:
+1095: raise ValueError(
__pyx_t_2 = NULL;
__Pyx_INCREF(__pyx_builtin_ValueError);
__pyx_t_1 = __pyx_builtin_ValueError;
+1096: 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, 1096, __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, 1096, __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, 1095, __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, 1095, __pyx_L1_error)
+1097: 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, 1097, __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, 1097, __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;
1098: )
1099:
+1100: 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; }
1101: """a + b"""
+1102: 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, 1102, __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;
1103:
+1104: 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; }
1105: """a + b"""
+1106: 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, 1106, __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;
1107:
+1108: 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; }
1109: """a - b"""
+1110: 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, 1110, __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;
1111:
+1112: 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; }
1113: """a - b"""
+1114: 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, 1114, __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;
1115:
+1116: 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; }
1117: """a * b"""
+1118: 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, 1118, __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;
1119:
+1120: 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; }
1121: """a * b"""
+1122: 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, 1122, __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;
1123:
+1124: 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, 1124, __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, 1124, __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, 1124, __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, 1124, __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, 1124, __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, 1124, __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[9])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1124, __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, 1124, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1125: """a / b"""
+1126: 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, 1126, __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;
1127:
+1128: 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, 1128, __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, 1128, __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, 1128, __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, 1128, __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, 1128, __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, 1128, __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[10])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1128, __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, 1128, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1129: """a / b"""
+1130: 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, 1130, __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;
1131:
+1132: 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; }
1133: """a / b"""
+1134: 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, 1134, __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;
1135:
+1136: 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; }
1137: """a / b"""
+1138: 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, 1138, __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;
1139:
+1140: 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; }
1141: """a // b"""
+1142: 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, 1142, __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;
1143:
+1144: 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; }
1145: """a // b"""
+1146: 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, 1146, __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;
1147:
+1148: 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; }
1149: """a % b"""
+1150: 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, 1150, __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;
1151:
+1152: 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; }
1153: """a % b"""
+1154: 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, 1154, __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;
1155:
+1156: 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; }
1157: """divmod(self, other): The pair (self // other, self % other).
1158:
1159: Sometimes this can be computed faster than the pair of
1160: operations.
1161: """
+1162: 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, 1162, __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;
1163:
+1164: 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; }
1165: """divmod(self, other): The pair (self // other, self % other).
1166:
1167: Sometimes this can be computed faster than the pair of
1168: operations.
1169: """
+1170: 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, 1170, __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;
1171:
+1172: 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; }
1173: """a ** b
1174:
1175: If b is not an integer, the result will be a float or complex
1176: since roots are generally irrational. If b is an integer, the
1177: result will be rational.
1178: """
+1179: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None);
if (__pyx_t_1) {
/* … */
}
+1180: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
1181:
+1182: if isinstance(b, int):
__pyx_t_1 = PyLong_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1183: 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, 1183, __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, 1183, __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, 1183, __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;
+1184: 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) { /* … */ }
+1185: 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, 1185, __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, 1185, __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, 1185, __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, 1185, __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, 1185, __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;
+1186: 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) { /* … */ }
+1187: 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, 1187, __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, 1187, __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, 1187, __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, 1187, __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;
1188: else:
+1189: return NotImplemented
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
goto __pyx_L0;
}
1190:
+1191: 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; }
1192: """a ** b
1193:
1194: If b is not an integer, the result will be a float or complex
1195: since roots are generally irrational. If b is an integer, the
1196: result will be rational.
1197: """
+1198: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None);
if (__pyx_t_1) {
/* … */
}
+1199: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
1200:
+1201: 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, 1201, __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, 1201, __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;
+1202: 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, 1202, __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, 1202, __pyx_L1_error) __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 1202, __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) { /* … */ }
1203: # If a is an int, keep it that way if possible.
+1204: 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, 1204, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
1205:
+1206: if isinstance(a, int):
__pyx_t_1 = PyLong_Check(__pyx_v_a);
if (__pyx_t_1) {
/* … */
}
+1207: 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, 1207, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = __pyx_t_3; __pyx_t_3 = 0; goto __pyx_L0;
+1208: 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) { /* … */ }
+1209: 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, 1209, __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, 1209, __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, 1209, __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;
1210:
+1211: 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, 1211, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1212: 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, 1212, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0;
1213:
+1214: 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, 1214, __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, 1214, __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;
1215:
+1216: 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; }
1217: """+a: Coerces a subclass instance to Fraction"""
+1218: 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) {
/* … */
}
+1219: return a
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_a); __pyx_r = ((PyObject *)__pyx_v_a); goto __pyx_L0;
+1220: 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, 1220, __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;
1221:
+1222: 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; }
1223: """-a"""
+1224: 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, 1224, __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, 1224, __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;
1225:
+1226: 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; }
1227: """abs(a)"""
+1228: 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, 1228, __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, 1228, __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;
1229:
+1230: 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; }
1231: """int(a)"""
+1232: 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, 1232, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1232, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1233: 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, 1233, __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, 1233, __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, 1233, __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, 1233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1234: else:
+1235: 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, 1235, __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, 1235, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
}
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
}
1236:
+1237: 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[11])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1237, __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, 1237, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1238: """math.trunc(a)"""
+1239: 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, 1239, __pyx_L1_error) __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1239, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1240: 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, 1240, __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, 1240, __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, 1240, __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;
1241: else:
+1242: 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, 1242, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_r = __pyx_t_1;
__pyx_t_1 = 0;
goto __pyx_L0;
}
1243:
+1244: 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[12])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1244, __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, 1244, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1245: """math.floor(a)"""
+1246: 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, 1246, __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, 1246, __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, 1246, __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;
1247:
+1248: 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[13])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1248, __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, 1248, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1249: """math.ceil(a)"""
1250: # The negations cleverly convince floordiv to return the ceiling.
+1251: 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, 1251, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1251, __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, 1251, __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, 1251, __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, 1251, __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;
1252:
+1253: 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, 1253, __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, 1253, __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, 1253, __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, 1253, __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, 1253, __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[14])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1253, __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, 1253, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1254: """round(self, ndigits)
1255:
1256: Rounds half toward even.
1257: """
+1258: if ndigits is None:
__pyx_t_1 = (__pyx_v_ndigits == Py_None);
if (__pyx_t_1) {
/* … */
}
+1259: 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, 1259, __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, 1259, __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, 1259, __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, 1259, __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, 1259, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1259, __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, 1259, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1259, __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, 1259, __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, 1259, __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, 1259, __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;
+1260: 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, 1260, __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, 1260, __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, 1260, __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, 1260, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_1) { /* … */ }
+1261: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
+1262: 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, 1262, __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, 1262, __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, 1262, __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, 1262, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1263: 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, 1263, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1264: # Deal with the half case:
+1265: 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, 1265, __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, 1265, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1266: return floor
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_floor); __pyx_r = __pyx_v_floor; goto __pyx_L0;
1267: else:
+1268: 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, 1268, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_r = __pyx_t_4;
__pyx_t_4 = 0;
goto __pyx_L0;
}
+1269: 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, 1269, __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, 1269, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_shift = __pyx_t_4; __pyx_t_4 = 0;
1270: # See _operator_fallbacks.forward to check that the results of
1271: # these operations will always be Fraction and therefore have
1272: # round().
+1273: 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, 1273, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1273, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1274: return Fraction(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, 1274, __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, 1274, __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, 1274, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_4); } __pyx_r = ((PyObject *)__pyx_t_4); __pyx_t_4 = 0; goto __pyx_L0;
1275: else:
+1276: 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, 1276, __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, 1276, __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, 1276, __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, 1276, __pyx_L1_error)
__Pyx_GOTREF((PyObject *)__pyx_t_4);
}
__pyx_r = ((PyObject *)__pyx_t_4);
__pyx_t_4 = 0;
goto __pyx_L0;
}
1277:
+1278: 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; }
1279: """float(self) = self.numerator / self.denominator
1280:
1281: It's important that this conversion use the integer's "true"
1282: division rather than casting one side to float before dividing
1283: so that ratios of huge integers convert without overflowing.
1284: """
+1285: 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, 1285, __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, 1285, __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, 1285, __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;
1286:
1287: # Concrete implementations of Complex abstract methods.
+1288: 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[15])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1288, __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, 1288, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1289: """complex(self) == complex(float(self), 0)"""
+1290: 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, 1290, __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, 1290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1291:
1292: # == +self
+1293: real = property(__pos__, doc="Real numbers are their real component.")
__pyx_t_6 = NULL; __Pyx_INCREF(__pyx_builtin_property); __pyx_t_8 = __pyx_builtin_property; __Pyx_GetNameInClass(__pyx_t_7, (PyObject*)__pyx_mstate_global->__pyx_ptype_10quicktions_Fraction, __pyx_mstate_global->__pyx_n_u_pos); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_9 = 1; { PyObject *__pyx_callargs[2 + ((CYTHON_VECTORCALL) ? 1 : 0)] = {__pyx_t_6, __pyx_t_7}; __pyx_t_2 = __Pyx_MakeVectorcallBuilderKwds(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1293, __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, 1293, __pyx_L1_error) __pyx_t_3 = __Pyx_Object_Vectorcall_CallFromBuilder(__pyx_t_8, __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET), __pyx_t_2); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1293, __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, 1293, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1294:
1295: # == 0
+1296: @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;
}
1297: def imag(self):
1298: "Real numbers have no imaginary component."
+1299: 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;
1300:
+1301: 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[16])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1301, __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, 1301, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1302: """Conjugate is a no-op for Reals."""
+1303: return +self
__Pyx_XDECREF(__pyx_r); __pyx_t_1 = PyNumber_Positive(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1303, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1304:
+1305: 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_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_7); __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; }
1306: """hash(self)"""
+1307: if self._hash != -1:
__pyx_t_1 = (__pyx_v_self->_hash != -1L);
if (__pyx_t_1) {
/* … */
}
+1308: return self._hash
__pyx_r = __pyx_v_self->_hash;
goto __pyx_L0;
1309:
1310: cdef Py_hash_t result
1311:
1312: # In order to make sure that the hash of a Fraction agrees
1313: # with the hash of a numerically equal integer, float or
1314: # Decimal instance, we follow the rules for numeric hashes
1315: # outlined in the documentation. (See library docs, 'Built-in
1316: # Types').
1317:
+1318: try:
{
/*try:*/ {
/* … */
}
/* … */
__pyx_L6_except_error:;
__Pyx_XGIVEREF(__pyx_t_2);
__Pyx_XGIVEREF(__pyx_t_3);
__Pyx_XGIVEREF(__pyx_t_4);
__Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
goto __pyx_L1_error;
__pyx_L5_exception_handled:;
__Pyx_XGIVEREF(__pyx_t_2);
__Pyx_XGIVEREF(__pyx_t_3);
__Pyx_XGIVEREF(__pyx_t_4);
__Pyx_ExceptionReset(__pyx_t_2, __pyx_t_3, __pyx_t_4);
__pyx_L9_try_end:;
}
+1319: dinv = pow(self._denominator, -1, _PyHASH_MODULUS)
__pyx_t_5 = __pyx_v_self->_denominator;
__Pyx_INCREF(__pyx_t_5);
__pyx_t_6 = __Pyx_PyLong_FromHash_t(__pyx_v_10quicktions__PyHASH_MODULUS); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1319, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = PyNumber_Power(__pyx_t_5, __pyx_mstate_global->__pyx_int_neg_1, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1319, __pyx_L4_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_v_dinv = __pyx_t_7;
__pyx_t_7 = 0;
+1320: except ValueError:
__pyx_t_9 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_ValueError); if (__pyx_t_9) { __Pyx_AddTraceback("quicktions.Fraction.__hash__", __pyx_clineno, __pyx_lineno, __pyx_filename); if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 1320, __pyx_L6_except_error) __Pyx_XGOTREF(__pyx_t_7); __Pyx_XGOTREF(__pyx_t_6); __Pyx_XGOTREF(__pyx_t_5);
1321: # ValueError means there is no modular inverse.
+1322: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF;
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
goto __pyx_L5_exception_handled;
}
goto __pyx_L6_except_error;
1323: else:
1324: # The general algorithm now specifies that the absolute value of
1325: # the hash is
1326: # (|N| * dinv) % P
1327: # where N is self._numerator and P is _PyHASH_MODULUS. That's
1328: # optimized here in two ways: first, for a non-negative int i,
1329: # hash(i) == i % P, but the int hash implementation doesn't need
1330: # to divide, and is faster than doing % P explicitly. So we do
1331: # hash(|N| * dinv)
1332: # instead. Second, N is unbounded, so its product with dinv may
1333: # be arbitrarily expensive to compute. The final answer is the
1334: # same if we use the bounded |N| % P instead, which can again
1335: # be done with an int hash() call. If 0 <= i < P, hash(i) == i,
1336: # so this nested hash() call wastes a bit of time making a
1337: # redundant copy when |N| < P, but can save an arbitrarily large
1338: # amount of computation for large |N|.
+1339: result = hash(hash(abs(self._numerator)) * dinv)
/*else:*/ {
__pyx_t_7 = __pyx_v_self->_numerator;
__Pyx_INCREF(__pyx_t_7);
__pyx_t_6 = __Pyx_PyNumber_Absolute(__pyx_t_7); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1339, __pyx_L6_except_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_8 = PyObject_Hash(__pyx_t_6); if (unlikely(__pyx_t_8 == ((Py_hash_t)-1))) __PYX_ERR(0, 1339, __pyx_L6_except_error)
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_6 = __Pyx_PyLong_FromHash_t(__pyx_t_8); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1339, __pyx_L6_except_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = PyNumber_Multiply(__pyx_t_6, __pyx_v_dinv); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1339, __pyx_L6_except_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_8 = PyObject_Hash(__pyx_t_7); if (unlikely(__pyx_t_8 == ((Py_hash_t)-1))) __PYX_ERR(0, 1339, __pyx_L6_except_error)
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_v_result = __pyx_t_8;
}
__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;
goto __pyx_L9_try_end;
__pyx_L4_error:;
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
1340:
+1341: if self._numerator < 0:
__pyx_t_5 = PyObject_RichCompare(__pyx_v_self->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); __Pyx_XGOTREF(__pyx_t_5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1341, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1341, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+1342: result = -result
__pyx_v_result = (-__pyx_v_result);
+1343: if result == -1:
__pyx_t_1 = (__pyx_v_result == -1L);
if (__pyx_t_1) {
/* … */
}
+1344: result = -2
__pyx_v_result = -2L;
+1345: self._hash = result
__pyx_v_self->_hash = __pyx_v_result;
+1346: return result
__pyx_r = __pyx_v_result; goto __pyx_L0;
1347:
+1348: 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;
}
+1349: 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;
}
+1350: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ);
if (__pyx_t_1) {
/* … */
}
+1351: 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, 1351, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1352: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE);
if (__pyx_t_1) {
/* … */
}
+1353: 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, 1353, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0;
+1354: 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, 1354, __pyx_L1_error) __pyx_t_4 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1354, __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;
1355: else:
+1356: 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, 1356, __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;
+1357: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ);
if (__pyx_t_1) {
/* … */
}
+1358: 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, 1358, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1359: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE);
if (__pyx_t_1) {
/* … */
}
+1360: 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, 1360, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_result = __pyx_t_4; __pyx_t_4 = 0;
+1361: 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, 1361, __pyx_L1_error) __pyx_t_2 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1361, __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;
+1362: elif op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1363: op = Py_GE
__pyx_v_op = Py_GE;
+1364: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1365: op = Py_LE
__pyx_v_op = Py_LE;
+1366: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1367: op = Py_GT
__pyx_v_op = Py_GT;
+1368: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1369: op = Py_LT
__pyx_v_op = Py_LT;
1370: else:
+1371: return NotImplemented
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
goto __pyx_L0;
}
__pyx_L5:;
}
__pyx_L3:;
+1372: 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, 1372, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1373:
+1374: @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;
}
1375: cdef _eq(a, b):
+1376: if type(b) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)(&PyLong_Type)));
if (__pyx_t_1) {
/* … */
}
+1377: 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, 1377, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1377, __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, 1377, __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;
+1378: 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) {
/* … */
}
+1379: 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, 1379, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1379, __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; }
+1380: 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, 1380, __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;
+1381: 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, 1381, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1382: 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, 1382, __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, 1382, __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, 1382, __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; }
+1383: 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, 1383, __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, 1383, __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;
+1384: 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, 1384, __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, 1384, __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, 1384, __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) { /* … */ }
+1385: 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, 1385, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_2); __pyx_t_2 = 0;
+1386: if isinstance(b, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1387: 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, 1387, __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, 1387, __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, 1387, __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, 1387, __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) {
/* … */
}
1388: # comparisons with an infinity or nan should behave in
1389: # the same way for any finite a, so treat a as zero.
+1390: 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, 1390, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1391: else:
+1392: 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, 1392, __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, 1392, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_r = __pyx_t_3;
__pyx_t_3 = 0;
goto __pyx_L0;
}
+1393: return NotImplemented
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_builtin_NotImplemented); __pyx_r = __pyx_builtin_NotImplemented; goto __pyx_L0;
1394:
+1395: @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;
}
1396: cdef _richcmp(self, other, int op):
1397: """Helper for comparison operators, for internal use only.
1398:
1399: Implement comparison between a Rational instance `self`, and
1400: either another Rational instance or a float `other`. If
1401: `other` is not a Rational instance or a float, return
1402: NotImplemented. `op` should be one of the six standard
1403: comparison operators.
1404:
1405: """
1406: # convert other to a Rational instance where reasonable.
+1407: if isinstance(other, int):
__pyx_t_1 = PyLong_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1408: 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;
+1409: b = self._denominator * other
__pyx_t_2 = PyNumber_Multiply(__pyx_v_self->_denominator, __pyx_v_other); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1409, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
+1410: 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;
}
+1411: 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, 1411, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_a = __pyx_t_2; __pyx_t_2 = 0;
+1412: 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, 1412, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
+1413: elif isinstance(other, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1414: 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, 1414, __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, 1414, __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, 1414, __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, 1414, __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;
}
+1415: 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;
1416: else:
+1417: 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, 1417, __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, 1417, __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:;
+1418: 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; }
+1419: 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, 1419, __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, 1419, __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;
+1420: 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, 1420, __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, 1420, __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;
1421: else:
1422: # comparisons with complex should raise a TypeError, for consistency
1423: # with int<->complex, float<->complex, and complex<->complex comparisons.
+1424: return NotImplemented
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
goto __pyx_L0;
}
__pyx_L3:;
1425:
+1426: if op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT);
if (__pyx_t_1) {
/* … */
}
+1427: 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, 1427, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1428: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT);
if (__pyx_t_1) {
/* … */
}
+1429: 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, 1429, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1430: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE);
if (__pyx_t_1) {
/* … */
}
+1431: 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, 1431, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1432: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE);
if (__pyx_t_1) {
/* … */
}
+1433: 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, 1433, __pyx_L1_error) __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1434: else:
+1435: return NotImplemented
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
goto __pyx_L0;
}
1436:
+1437: 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;
}
1438: """a != 0"""
1439: # Use bool() because (a._numerator != 0) can return an
1440: # object which is not a bool.
1441: # See https://bugs.python.org/issue39274
+1442: return bool(self._numerator)
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->_numerator); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1442, __pyx_L1_error) __pyx_r = (!(!__pyx_t_1)); goto __pyx_L0;
1443:
1444: # support for pickling, copy, and deepcopy
1445:
+1446: 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[17])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1446, __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, 1446, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1447: 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, 1447, __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, 1447, __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, 1447, __pyx_L1_error); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1447, __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, 1447, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 1447, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1448:
+1449: 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[18])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1449, __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, 1449, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1450: 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) {
/* … */
}
+1451: 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;
+1452: 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, 1452, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1453:
+1454: 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, 1454, __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, 1454, __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, 1454, __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, 1454, __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, 1454, __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, 1454, __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[19])); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1454, __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, 1454, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
+1455: 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) {
/* … */
}
+1456: 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;
+1457: 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, 1457, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1458:
1459:
1460: # Register with Python's numerical tower.
+1461: Rational.register(Fraction)
__pyx_t_8 = __pyx_v_10quicktions_Rational; __Pyx_INCREF(__pyx_t_8); __pyx_t_9 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_8, ((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_9, (2-__pyx_t_9) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1461, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); } __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
1462:
1463:
+1464: 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;
};
1465: """Convert a pair of ints to a rational number, for internal use.
1466:
1467: The ratio of integers should be in lowest terms and the denominator
1468: should be positive.
1469: """
1470: cdef Fraction obj
+1471: 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;
}
+1472: obj = Fraction.__new__(Fraction, NOINIT, NOINIT)
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1472, __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, 1472, __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, 1472, __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, 1472, __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;
1473: else:
+1474: 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, 1474, __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, 1474, __pyx_L1_error)
__pyx_v_obj = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_4);
__pyx_t_4 = 0;
}
__pyx_L3:;
+1475: 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;
+1476: 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;
+1477: return obj
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF((PyObject *)__pyx_v_obj); __pyx_r = ((PyObject *)__pyx_v_obj); goto __pyx_L0;
1478:
1479:
+1480: 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;
}
+1481: 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, 1481, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
1482: # power = bn
+1483: 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, 1483, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1483, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1484: 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, 1484, __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;
+1485: an ** bn,
__pyx_t_2 = PyNumber_Power(__pyx_v_an, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1485, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+1486: ad ** bn)
__pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1486, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+1487: 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, 1487, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1487, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1488: 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, 1488, __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;
+1489: ad ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1489, __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, 1489, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1490: an ** -bn)
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1490, __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, 1490, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1491: 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, 1491, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1492: 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, 1492, __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, 1492, __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, 1492, __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, 1492, __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, 1492, __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, 1492, __pyx_L1_error)
1493: else:
+1494: 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, 1494, __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;
}
+1495: (-ad) ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1495, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1495, __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, 1495, __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;
+1496: (-an) ** -bn)
__pyx_t_3 = PyNumber_Negative(__pyx_v_an); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1496, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1496, __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, 1496, __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;
1497: else:
1498: # A fractional power will generally produce an
1499: # irrational number.
+1500: 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, 1500, __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, 1500, __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, 1500, __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;
}
1501:
1502:
+1503: 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;
}
+1504: 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, 1504, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
1505:
1506:
1507: # Rational arithmetic algorithms: Knuth, TAOCP, Volume 2, 4.5.1.
1508: #
1509: # Assume input fractions a and b are normalized.
1510: #
1511: # 1) Consider addition/subtraction.
1512: #
1513: # Let g = gcd(da, db). Then
1514: #
1515: # na nb na*db ± nb*da
1516: # a ± b == -- ± -- == ------------- ==
1517: # da db da*db
1518: #
1519: # na*(db//g) ± nb*(da//g) t
1520: # == ----------------------- == -
1521: # (da*db)//g d
1522: #
1523: # Now, if g > 1, we're working with smaller integers.
1524: #
1525: # Note, that t, (da//g) and (db//g) are pairwise coprime.
1526: #
1527: # Indeed, (da//g) and (db//g) share no common factors (they were
1528: # removed) and da is coprime with na (since input fractions are
1529: # normalized), hence (da//g) and na are coprime. By symmetry,
1530: # (db//g) and nb are coprime too. Then,
1531: #
1532: # gcd(t, da//g) == gcd(na*(db//g), da//g) == 1
1533: # gcd(t, db//g) == gcd(nb*(da//g), db//g) == 1
1534: #
1535: # Above allows us optimize reduction of the result to lowest
1536: # terms. Indeed,
1537: #
1538: # g2 = gcd(t, d) == gcd(t, (da//g)*(db//g)*g) == gcd(t, g)
1539: #
1540: # t//g2 t//g2
1541: # a ± b == ----------------------- == ----------------
1542: # (da//g)*(db//g)*(g//g2) (da//g)*(db//g2)
1543: #
1544: # is a normalized fraction. This is useful because the unnormalized
1545: # denominator d could be much larger than g.
1546: #
1547: # We should special-case g == 1 (and g2 == 1), since 60.8% of
1548: # randomly-chosen integers are coprime:
1549: # https://en.wikipedia.org/wiki/Coprime_integers#Probability_of_coprimality
1550: # Note, that g2 == 1 always for fractions, obtained from floats: here
1551: # g is a power of 2 and the unnormalized numerator t is an odd integer.
1552: #
1553: # 2) Consider multiplication
1554: #
1555: # Let g1 = gcd(na, db) and g2 = gcd(nb, da), then
1556: #
1557: # na*nb na*nb (na//g1)*(nb//g2)
1558: # a*b == ----- == ----- == -----------------
1559: # da*db db*da (db//g1)*(da//g2)
1560: #
1561: # Note, that after divisions we're multiplying smaller integers.
1562: #
1563: # Also, the resulting fraction is normalized, because each of
1564: # two factors in the numerator is coprime to each of the two factors
1565: # in the denominator.
1566: #
1567: # Indeed, pick (na//g1). It's coprime with (da//g2), because input
1568: # fractions are normalized. It's also coprime with (db//g1), because
1569: # common factors are removed by g1 == gcd(na, db).
1570: #
1571: # As for addition/subtraction, we should special-case g1 == 1
1572: # and g2 == 1 for same reason. That happens also for multiplying
1573: # rationals, obtained from floats.
1574:
+1575: 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_2);
__Pyx_XDECREF(__pyx_t_3);
__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;
}
1576: """a + b"""
1577: # return Fraction(na * db + nb * da, da * db)
+1578: g = _gcd(da, db)
__pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __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[3] = {__pyx_t_2, __pyx_v_da, __pyx_v_db}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (3-__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, 1578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1579: if g == 1:
__pyx_t_5 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1579, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1580: 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, 1580, __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, 1580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_Add(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __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, 1580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1580, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+1581: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1581, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1582: 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, 1582, __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, 1582, __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, 1582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Add(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1582, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_t = __pyx_t_2; __pyx_t_2 = 0;
+1583: g2 = _gcd(t, g)
__pyx_t_1 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_v_t, __pyx_v_g}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (3-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1584: if g2 == 1:
__pyx_t_5 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1584, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1585: return _fraction_from_coprime_ints(t, s * db)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyNumber_Multiply(__pyx_v_s, __pyx_v_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1585, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_t, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1585, __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;
+1586: return _fraction_from_coprime_ints(t // g2, s * (db // g2))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyNumber_FloorDivide(__pyx_v_t, __pyx_v_g2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_FloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyNumber_Multiply(__pyx_v_s, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1586, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1587:
+1588: 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_2);
__Pyx_XDECREF(__pyx_t_3);
__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;
}
1589: """a - b"""
1590: # return Fraction(na * db - nb * da, da * db)
+1591: g = _gcd(da, db)
__pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1591, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __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[3] = {__pyx_t_2, __pyx_v_da, __pyx_v_db}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (3-__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, 1591, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1592: if g == 1:
__pyx_t_5 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1592, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1593: 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, 1593, __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, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_Subtract(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __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, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_1 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1593, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0;
+1594: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1594, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1595: 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, 1595, __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, 1595, __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, 1595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Subtract(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1595, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_t = __pyx_t_2; __pyx_t_2 = 0;
+1596: g2 = _gcd(t, g)
__pyx_t_1 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_1); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_1); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_v_t, __pyx_v_g}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (3-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1596, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1597: if g2 == 1:
__pyx_t_5 = (__Pyx_PyLong_BoolEqObjC(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, 1, 0)); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1597, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1598: return _fraction_from_coprime_ints(t, s * db)
__Pyx_XDECREF(__pyx_r); __pyx_t_2 = PyNumber_Multiply(__pyx_v_s, __pyx_v_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1598, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_t, __pyx_t_2, NULL); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1598, __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;
+1599: return _fraction_from_coprime_ints(t // g2, s * (db // g2))
__Pyx_XDECREF(__pyx_r); __pyx_t_3 = PyNumber_FloorDivide(__pyx_v_t, __pyx_v_g2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = PyNumber_FloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyNumber_Multiply(__pyx_v_s, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_3, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1599, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1600:
+1601: 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_2);
__Pyx_XDECREF(__pyx_t_3);
__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;
}
1602: """a * b"""
1603: # return Fraction(na * nb, da * db)
+1604: g1 = _gcd(na, db)
__pyx_t_2 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1604, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __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[3] = {__pyx_t_2, __pyx_v_na, __pyx_v_db}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+__pyx_t_4, (3-__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, 1604, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g1 = __pyx_t_1; __pyx_t_1 = 0;
+1605: 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, 1605, __pyx_L1_error) __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1605, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+1606: na //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1606, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_1); __pyx_t_1 = 0;
+1607: db //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1607, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_1); __pyx_t_1 = 0;
+1608: g2 = _gcd(nb, da)
__pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1608, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_2))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_2); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_2, __pyx__function); __pyx_t_4 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_v_nb, __pyx_v_da}; __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+__pyx_t_4, (3-__pyx_t_4) | (__pyx_t_4*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1608, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g2 = __pyx_t_1; __pyx_t_1 = 0;
+1609: 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, 1609, __pyx_L1_error) __pyx_t_5 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1609, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+1610: nb //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1610, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_1); __pyx_t_1 = 0;
+1611: da //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_1); __pyx_t_1 = 0;
+1612: 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, 1612, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Multiply(__pyx_v_db, __pyx_v_da); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1612, __pyx_L1_error) __Pyx_GOTREF(__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, 1612, __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;
1613:
+1614: 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;
}
1615: """a / b"""
1616: # return Fraction(na * db, da * nb)
1617: # Same as _mul(), with inversed b.
+1618: 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, 1618, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1619: 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, 1619, __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, 1619, __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, 1619, __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, 1619, __pyx_L1_error)
+1620: g1 = _gcd(na, nb)
__pyx_t_4 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1620, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_8 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_7))) { __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); assert(__pyx_t_4); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_7); __Pyx_INCREF(__pyx_t_4); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_7, __pyx__function); __pyx_t_8 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_v_na, __pyx_v_nb}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+__pyx_t_8, (3-__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; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1620, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g1 = __pyx_t_2; __pyx_t_2 = 0;
+1621: 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, 1621, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1621, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1622: na //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1622, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_2); __pyx_t_2 = 0;
+1623: nb //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1623, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_2); __pyx_t_2 = 0;
+1624: g2 = _gcd(db, da)
__pyx_t_7 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1624, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_8 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_4))) { __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_4); assert(__pyx_t_7); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_4); __Pyx_INCREF(__pyx_t_7); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_4, __pyx__function); __pyx_t_8 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_v_db, __pyx_v_da}; __pyx_t_2 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+__pyx_t_8, (3-__pyx_t_8) | (__pyx_t_8*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1624, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1625: 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, 1625, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_2); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1625, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1626: da //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1626, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_2); __pyx_t_2 = 0;
+1627: db //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1627, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_2); __pyx_t_2 = 0;
+1628: 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, 1628, __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, 1628, __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;
+1629: 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, 1629, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1629, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1630: n, d = -n, -d
__pyx_t_4 = PyNumber_Negative(__pyx_v_n); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1630, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_2 = PyNumber_Negative(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1630, __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;
+1631: 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, 1631, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1632:
+1633: 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;
}
1634: """a // b -> int"""
+1635: 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, 1635, __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, 1635, __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, 1635, __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;
1636:
+1637: 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;
}
+1638: 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, 1638, __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, 1638, __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, 1638, __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, 1638, __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, 1638, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyList_GetItemRef(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1638, __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, 1638, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1638, __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, 1638, __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, 1638, __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, 1638, __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;
+1639: 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, 1639, __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, 1639, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_3); } __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1639, __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, 1639, __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, 1639, __pyx_L1_error); __pyx_t_3 = 0; __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1640:
+1641: 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;
}
+1642: 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, 1642, __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, 1642, __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, 1642, __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, 1642, __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, 1642, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_1); } __pyx_r = ((PyObject *)__pyx_t_1); __pyx_t_1 = 0; goto __pyx_L0;
1643:
1644:
1645: """
1646: In general, we want to implement the arithmetic operations so
1647: that mixed-mode operations either call an implementation whose
1648: author knew about the types of both arguments, or convert both
1649: to the nearest built in type and do the operation there. In
1650: Fraction, that means that we define __add__ and __radd__ as:
1651:
1652: def __add__(self, other):
1653: # Both types have numerators/denominator attributes,
1654: # so do the operation directly
1655: if isinstance(other, (int, Fraction)):
1656: return Fraction(self.numerator * other.denominator +
1657: other.numerator * self.denominator,
1658: self.denominator * other.denominator)
1659: # float and complex don't have those operations, but we
1660: # know about those types, so special case them.
1661: elif isinstance(other, float):
1662: return float(self) + other
1663: elif isinstance(other, complex):
1664: return complex(self) + other
1665: # Let the other type take over.
1666: return NotImplemented
1667:
1668: def __radd__(self, other):
1669: # radd handles more types than add because there's
1670: # nothing left to fall back to.
1671: if isinstance(other, Rational):
1672: return Fraction(self.numerator * other.denominator +
1673: other.numerator * self.denominator,
1674: self.denominator * other.denominator)
1675: elif isinstance(other, Real):
1676: return float(other) + float(self)
1677: elif isinstance(other, Complex):
1678: return complex(other) + complex(self)
1679: return NotImplemented
1680:
1681:
1682: There are 5 different cases for a mixed-type addition on
1683: Fraction. I'll refer to all of the above code that doesn't
1684: refer to Fraction, float, or complex as "boilerplate". 'r'
1685: will be an instance of Fraction, which is a subtype of
1686: Rational (r : Fraction <: Rational), and b : B <:
1687: Complex. The first three involve 'r + b':
1688:
1689: 1. If B <: Fraction, int, float, or complex, we handle
1690: that specially, and all is well.
1691: 2. If Fraction falls back to the boilerplate code, and it
1692: were to return a value from __add__, we'd miss the
1693: possibility that B defines a more intelligent __radd__,
1694: so the boilerplate should return NotImplemented from
1695: __add__. In particular, we don't handle Rational
1696: here, even though we could get an exact answer, in case
1697: the other type wants to do something special.
1698: 3. If B <: Fraction, Python tries B.__radd__ before
1699: Fraction.__add__. This is ok, because it was
1700: implemented with knowledge of Fraction, so it can
1701: handle those instances before delegating to Real or
1702: Complex.
1703:
1704: The next two situations describe 'b + r'. We assume that b
1705: didn't know about Fraction in its implementation, and that it
1706: uses similar boilerplate code:
1707:
1708: 4. If B <: Rational, then __radd_ converts both to the
1709: builtin rational type (hey look, that's us) and
1710: proceeds.
1711: 5. Otherwise, __radd__ tries to find the nearest common
1712: base ABC, and fall back to its builtin type. Since this
1713: class doesn't subclass a concrete type, there's no
1714: implementation to fall back to, so we need to try as
1715: hard as possible to return an actual value, or the user
1716: will get a TypeError.
1717: """
1718:
1719: cdef:
+1720: _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, 1720, __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;
+1721: _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, 1721, __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;
+1722: _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, 1722, __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;
+1723: _math_op_div = getattr(operator, 'div', operator.truediv) # Py2/3
__pyx_t_3 = __pyx_v_10quicktions_operator; __Pyx_INCREF(__pyx_t_3); __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_10quicktions_operator, __pyx_mstate_global->__pyx_n_u_truediv); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = __Pyx_GetAttr3(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_div_2, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1723, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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;
+1724: _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, 1724, __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;
+1725: _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, 1725, __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;
+1726: _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, 1726, __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;
+1727: _math_op_divmod = divmod
__pyx_t_2 = __Pyx_GetBuiltinName(__pyx_mstate_global->__pyx_n_u_divmod); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1727, __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;
1728:
1729:
+1730: ctypedef object (*math_func)(an, ad, bn, bd)
typedef PyObject *(*__pyx_t_10quicktions_math_func)(PyObject *, PyObject *, PyObject *, PyObject *);
1731:
1732:
+1733: 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;
};
+1734: 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;
+1735: 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) {
/* … */
}
+1736: 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, 1736, __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;
+1737: elif isinstance(b, int):
__pyx_t_3 = PyLong_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1738: 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, 1738, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1739: elif isinstance(b, Fraction):
__pyx_t_3 = __Pyx_TypeCheck(__pyx_v_b, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction);
if (__pyx_t_3) {
/* … */
}
+1740: 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, 1740, __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, 1740, __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, 1740, __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;
+1741: elif isinstance(b, float):
__pyx_t_3 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1742: 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, 1742, __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, 1742, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1743: 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, 1743, __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) { /* … */ }
+1744: 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, 1744, __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, 1744, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
1745: else:
+1746: return NotImplemented
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
goto __pyx_L0;
}
1747:
1748:
+1749: 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;
};
+1750: 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;
+1751: if isinstance(a, int):
__pyx_t_3 = PyLong_Check(__pyx_v_a);
if (__pyx_t_3) {
/* … */
}
+1752: 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, 1752, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_r = __pyx_t_2; __pyx_t_2 = 0; goto __pyx_L0;
+1753: 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, 1753, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { /* … */ }
+1754: 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, 1754, __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, 1754, __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, 1754, __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;
+1755: 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, 1755, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_3) { /* … */ }
+1756: 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, 1756, __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, 1756, __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, 1756, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
+1757: 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, 1757, __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, 1757, __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) { /* … */ }
+1758: 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, 1758, __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, 1758, __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, 1758, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_r = __pyx_t_4; __pyx_t_4 = 0; goto __pyx_L0;
1759: else:
+1760: return NotImplemented
/*else*/ {
__Pyx_XDECREF(__pyx_r);
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
goto __pyx_L0;
}
1761:
1762:
+1763: ctypedef char* charptr
typedef char *__pyx_t_10quicktions_charptr;
1764:
1765: ctypedef fused AnyString:
1766: unicode
1767: charptr
1768:
1769:
+1770: 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
};
1771: BEGIN_SPACE # '\s'* -> (BEGIN_SIGN, SMALL_NUM, START_DECIMAL_DOT)
1772: BEGIN_SIGN # [+-] -> (SMALL_NUM, SMALL_DECIMAL_DOT)
1773: SMALL_NUM # [0-9]+ -> (SMALL_NUM, SMALL_NUM_US, NUM, NUM_SPACE, SMALL_DECIMAL_DOT, EXP_E, DENOM_START)
1774: SMALL_NUM_US # '_' -> (SMALL_NUM, NUM)
1775: NUM # [0-9]+ -> (NUM, NUM_US, NUM_SPACE, DECIMAL_DOT, EXP_E, DENOM_START)
1776: NUM_US # '_' -> (NUM)
1777: NUM_SPACE # '\s'+ -> (DENOM_START)
1778:
1779: # 1) floating point syntax
1780: START_DECIMAL_DOT # '.' -> (SMALL_DECIMAL)
1781: SMALL_DECIMAL_DOT # '.' -> (SMALL_DECIMAL, EXP_E, SMALL_END_SPACE)
1782: DECIMAL_DOT # '.' -> (DECIMAL, EXP_E, END_SPACE)
1783: SMALL_DECIMAL # [0-9]+ -> (SMALL_DECIMAL, SMALL_DECIMAL_US, DECIMAL, EXP_E, SMALL_END_SPACE)
1784: SMALL_DECIMAL_US # '_' -> (SMALL_DECIMAL, DECIMAL)
1785: DECIMAL # [0-9]+ -> (DECIMAL, DECIMAL_US, EXP_E, END_SPACE)
1786: DECIMAL_US # '_' -> (DECIMAL)
1787: EXP_E # [eE] -> (EXP_SIGN, EXP)
1788: EXP_SIGN # [+-] -> (EXP)
1789: EXP # [0-9]+ -> (EXP_US, END_SPACE)
1790: EXP_US # '_' -> (EXP)
1791: END_SPACE # '\s'+
1792: SMALL_END_SPACE # '\s'+
1793:
1794: # 2) "NOM / DENOM" syntax
1795: DENOM_START # '/' -> (DENOM_SIGN, SMALL_DENOM)
1796: DENOM_SIGN # [+-] -> (SMALL_DENOM)
1797: SMALL_DENOM # [0-9]+ -> (SMALL_DENOM, SMALL_DENOM_US, DENOM, DENOM_SPACE)
1798: SMALL_DENOM_US # '_' -> (SMALL_DENOM)
1799: DENOM # [0-9]+ -> (DENOM, DENOM_US, DENOM_SPACE)
1800: DENOM_US # '_' -> (DENOM)
1801: DENOM_SPACE # '\s'+
1802:
1803:
+1804: 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;
}
+1805: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1805, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1806: 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, 1806, __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, 1806, __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, 1806, __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, 1806, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[0]); /* … */ }
+1807: 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, 1807, __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, 1807, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[1]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[1]);
+1808: 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, 1808, __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, 1808, __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, 1808, __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, 1808, __pyx_L1_error)
1809:
1810:
+1811: 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;
}
+1812: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1812, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1813: 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, 1813, __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, 1813, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1814: 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, 1814, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1815: 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, 1815, __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, 1815, __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, 1815, __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, 1815, __pyx_L1_error)
1816:
1817:
1818: cdef extern from *:
1819: """
1820: static CYTHON_INLINE int __QUICKTIONS_unpack_ustring(
1821: PyObject* string, Py_ssize_t *length, void** data, int *kind) {
1822: if (PyUnicode_READY(string) < 0) return -1;
1823: *kind = PyUnicode_KIND(string);
1824: *length = PyUnicode_GET_LENGTH(string);
1825: *data = PyUnicode_DATA(string);
1826: return 0;
1827: }
1828: #define __QUICKTIONS_char_at(data, kind, index) \
1829: (((kind == 1) ? (Py_UCS4) ((char*) data)[index] : (Py_UCS4) PyUnicode_READ(kind, data, index)))
1830: """
1831: int _unpack_ustring "__QUICKTIONS_unpack_ustring" (
1832: object string, Py_ssize_t *length, void **data, int *kind) except -1
1833: Py_UCS4 _char_at "__QUICKTIONS_char_at" (void *data, int kind, Py_ssize_t index)
1834: Py_UCS4 PyUnicode_READ(int kind, void *data, Py_ssize_t index)
1835:
1836:
+1837: 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;
}
1838: cdef unsigned int unum
1839: cdef int num
+1840: 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'));
+1841: if unum > 9:
__pyx_t_1 = (__pyx_v_unum > 9);
if (__pyx_t_1) {
/* … */
}
+1842: if not allow_unicode:
__pyx_t_1 = (!(__pyx_v_allow_unicode != 0));
if (__pyx_t_1) {
/* … */
}
+1843: return -1
__pyx_r = -1;
goto __pyx_L0;
+1844: num = Py_UNICODE_TODECIMAL(c)
__pyx_v_num = Py_UNICODE_TODECIMAL(__pyx_v_c);
+1845: if num == -1:
__pyx_t_1 = (__pyx_v_num == -1L);
if (__pyx_t_1) {
/* … */
}
+1846: return -1
__pyx_r = -1;
goto __pyx_L0;
+1847: unum = <unsigned int> num
__pyx_v_unum = ((unsigned int)__pyx_v_num);
+1848: c = <Py_UCS4> (num + c'0')
__pyx_v_c = ((Py_UCS4)(__pyx_v_num + '0'));
+1849: if c_digits:
__pyx_t_1 = (__pyx_v_c_digits != 0);
if (__pyx_t_1) {
/* … */
}
+1850: c_digits[0][0] = <char> c
((__pyx_v_c_digits[0])[0]) = ((char)__pyx_v_c);
+1851: c_digits[0] += 1
__pyx_t_2 = 0;
(__pyx_v_c_digits[__pyx_t_2]) = ((__pyx_v_c_digits[__pyx_t_2]) + 1);
+1852: return <int> unum
__pyx_r = ((int)__pyx_v_unum); goto __pyx_L0;
1853:
1854:
+1855: 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;
}
+1856: c_digits_end[0][0] = 0
((__pyx_v_c_digits_end[0])[0]) = 0;
+1857: 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, 1857, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_py_number = __pyx_t_1; __pyx_t_1 = 0;
+1858: c_digits_end[0] = c_digits_start # reset
(__pyx_v_c_digits_end[0]) = __pyx_v_c_digits_start;
+1859: return py_number
__Pyx_XDECREF(__pyx_r); __Pyx_INCREF(__pyx_v_py_number); __pyx_r = __pyx_v_py_number; goto __pyx_L0;
1860:
1861:
+1862: @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;
1863: cdef tuple _parse_fraction(AnyString s, Py_ssize_t s_len, orig_str):
1864: """
1865: Parse a string into a number tuple: (numerator, denominator, is_normalised)
1866: """
+1867: cdef Py_ssize_t pos, decimal_len = 0
__pyx_v_decimal_len = 0; /* … */ __pyx_v_decimal_len = 0;
1868: cdef Py_UCS4 c
+1869: cdef ParserState state = BEGIN_SPACE
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE;
1870:
+1871: 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;
1872: cdef int digit
1873: cdef unsigned int udigit
+1874: 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;
1875: cdef ullong igcd
+1876: cdef object num = None, decimal, denom
__Pyx_INCREF(Py_None); __pyx_v_num = Py_None; /* … */ __Pyx_INCREF(Py_None); __pyx_v_num = Py_None;
1877: # 2^n > 10^(n * 5/17)
+1878: 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);
1879:
1880: # Incremental Unicode iteration isn't in Cython yet.
+1881: cdef int allow_unicode = AnyString is unicode
__pyx_v_allow_unicode = 1; /* … */ __pyx_v_allow_unicode = 0;
+1882: cdef int s_kind = 1
__pyx_v_s_kind = 1; /* … */ __pyx_v_s_kind = 1;
+1883: cdef void* s_data = NULL
__pyx_v_s_data = NULL; /* … */ __pyx_v_s_data = NULL;
+1884: cdef char* cdata = NULL
__pyx_v_cdata = NULL; /* … */ __pyx_v_cdata = NULL;
1885:
1886: if AnyString is unicode:
+1887: _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, 1887, __pyx_L1_error)
+1888: if s_kind == 1:
__pyx_t_2 = (__pyx_v_s_kind == 1);
if (__pyx_t_2) {
/* … */
}
+1889: 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, 1889, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_r = ((PyObject*)__pyx_t_3); __pyx_t_3 = 0; goto __pyx_L0;
+1890: cdata = <char*> s_data
__pyx_v_cdata = ((char *)__pyx_v_s_data);
+1891: cdata += 0 # mark used
__pyx_v_cdata = (__pyx_v_cdata + 0);
1892: else:
+1893: cdata = s
__pyx_v_cdata = __pyx_v_s;
1894:
1895: # We collect the digits in inum / idenum as long as the value fits their integer size
1896: # and additionally in a char* buffer in case it grows too large.
+1897: 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, 1897, __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, 1897, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_digits = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1898: 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, 1898, __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, 1898, __pyx_L1_error) __pyx_v_c_digits_start = __pyx_t_2;
+1899: 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;
1900:
+1901: pos = 0
__pyx_v_pos = 0; /* … */ __pyx_v_pos = 0;
+1902: 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;
+1903: 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;
+1904: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+1905: 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, 1905, __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, 1905, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1906: 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) {
/* … */
}
+1907: if c == u'/':
switch (__pyx_v_c) {
case 47:
/* … */
break;
case 46:
/* … */
switch (__pyx_v_c) {
case 47:
/* … */
break;
case 46:
+1908: 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:
+1909: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1909, __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, 1909, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1910: elif state in (NUM, NUM_SPACE):
case __pyx_e_10quicktions_NUM_SPACE:
/* … */
break;
default:
/* … */
case __pyx_e_10quicktions_NUM_SPACE:
/* … */
break;
default:
+1911: 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, 1911, __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, 1911, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1912: else:
+1913: _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, 1913, __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, 1913, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1914: state = DENOM_START
__pyx_v_state = __pyx_e_10quicktions_DENOM_START;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_START;
+1915: break
goto __pyx_L5_break;
/* … */
goto __pyx_L4_break;
+1916: elif c == u'.':
break;
case 69:
/* … */
break;
case 69:
+1917: 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:
+1918: state = START_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
/* … */
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
+1919: elif state == SMALL_NUM:
break;
case __pyx_e_10quicktions_NUM:
/* … */
break;
case __pyx_e_10quicktions_NUM:
+1920: state = SMALL_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
+1921: elif state == NUM:
break;
default:
/* … */
break;
default:
+1922: state = DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
1923: else:
+1924: _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, 1924, __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, 1924, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1925: break
goto __pyx_L5_break;
/* … */
goto __pyx_L4_break;
+1926: elif c in u'eE':
case 0x65:
/* … */
break;
case 43:
/* … */
case 0x65:
/* … */
break;
case 43:
+1927: 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:
+1928: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1928, __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, 1928, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1929: elif state == NUM:
break;
default:
/* … */
break;
default:
+1930: 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, 1930, __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, 1930, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1931: else:
+1932: _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, 1932, __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, 1932, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1933: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1934: break
goto __pyx_L5_break;
/* … */
goto __pyx_L4_break;
+1935: elif c in u'-+':
case 45:
/* … */
break;
case 95:
/* … */
case 45:
/* … */
break;
case 95:
+1936: 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;
}
+1937: is_neg = c == u'-'
__pyx_v_is_neg = (__pyx_v_c == 45);
/* … */
__pyx_v_is_neg = (__pyx_v_c == 45);
+1938: state = BEGIN_SIGN
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
/* … */
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
1939: else:
+1940: _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, 1940, __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, 1940, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L6:;
+1941: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
+1942: elif c == u'_':
break;
default:
/* … */
break;
default:
+1943: 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:
+1944: state = SMALL_NUM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
+1945: elif state == NUM:
break;
default:
/* … */
break;
default:
+1946: state = NUM_US
__pyx_v_state = __pyx_e_10quicktions_NUM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM_US;
1947: else:
+1948: _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, 1948, __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, 1948, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1949: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
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: 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;
+1953: 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]);
+1954: 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) { /* … */ }
+1955: break
goto __pyx_L10_break;
/* … */
goto __pyx_L9_break;
+1956: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L10_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L9_break:;
1957:
+1958: 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:
+1959: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
+1960: elif state == SMALL_NUM:
break;
case __pyx_e_10quicktions_NUM:
/* … */
break;
case __pyx_e_10quicktions_NUM:
+1961: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1961, __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, 1961, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1962: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
+1963: elif state == NUM:
break;
default:
/* … */
break;
default:
+1964: 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, 1964, __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, 1964, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1965: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
1966: else:
+1967: _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, 1967, __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, 1967, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1968: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
1969:
+1970: _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, 1970, __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, 1970, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+1971: continue
goto __pyx_L4_continue;
break;
}
/* … */
goto __pyx_L3_continue;
break;
}
1972:
1973: # normal digit found
+1974: 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:
+1975: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1976: state = SMALL_NUM
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
1977:
1978: # fast-path for consecutive digits
+1979: 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;
+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: 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, 1981, __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, 1981, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+1982: 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) {
/* … */
}
+1983: break
goto __pyx_L13_break;
/* … */
goto __pyx_L12_break;
+1984: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+1985: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L13_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L12_break:;
1986:
+1987: 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) {
/* … */
}
+1988: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM;
+1989: elif state == NUM_US:
break;
default: break;
}
/* … */
break;
default: break;
}
+1990: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM;
1991:
1992: # We might have switched to NUM above, so continue right here in that case.
+1993: 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:
1994: pass # handled above
+1995: elif state == NUM:
break;
default:
/* … */
break;
default:
1996: # fast-path for consecutive digits
+1997: 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;
+1998: 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]);
+1999: 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, 1999, __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, 1999, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2000: 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) {
/* … */
}
+2001: break
goto __pyx_L19_break;
/* … */
goto __pyx_L18_break;
+2002: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L19_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L18_break:;
2003: else:
+2004: _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, 2004, __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, 2004, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L3_continue:; } __pyx_L4_break:;
2005:
+2006: 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:
2007: # NUM '/' | SMALL_NUM '/'
+2008: 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;
+2009: 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]);
+2010: 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) { /* … */ }
+2011: break
goto __pyx_L22_break;
/* … */
goto __pyx_L21_break;
+2012: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L22_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L21_break:;
2013:
2014: # Start fresh digits collection.
+2015: c_digits = c_digits_start
__pyx_v_c_digits = __pyx_v_c_digits_start;
/* … */
__pyx_v_c_digits = __pyx_v_c_digits_start;
+2016: 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;
+2017: 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]);
+2018: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2019: 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, 2019, __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, 2019, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2020: 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) {
/* … */
}
+2021: 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:
+2022: 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;
}
+2023: 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));
+2024: state = DENOM_SIGN
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
2025: else:
+2026: _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, 2026, __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, 2026, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L26:;
+2027: continue
goto __pyx_L24_continue;
/* … */
goto __pyx_L23_continue;
+2028: elif c == u'_':
break;
default:
/* … */
break;
default:
+2029: 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:
+2030: state = SMALL_DENOM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
+2031: elif state == DENOM:
break;
default:
/* … */
break;
default:
+2032: state = DENOM_US
__pyx_v_state = __pyx_e_10quicktions_DENOM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_US;
2033: else:
+2034: _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, 2034, __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, 2034, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2035: continue
goto __pyx_L24_continue;
/* … */
goto __pyx_L23_continue;
2036: else:
+2037: 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) { /* … */ }
+2038: 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;
+2039: 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]);
+2040: 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) { /* … */ }
+2041: break
goto __pyx_L30_break;
/* … */
goto __pyx_L29_break;
+2042: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L30_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L29_break:;
2043:
+2044: 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:
2045: pass
+2046: elif state == SMALL_DENOM:
break;
case __pyx_e_10quicktions_DENOM:
/* … */
break;
case __pyx_e_10quicktions_DENOM:
+2047: denom = idenom
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); 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_PY_LONG_LONG(__pyx_v_idenom); 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: elif state == DENOM:
break;
default:
/* … */
break;
default:
+2049: 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, 2049, __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, 2049, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2050: else:
+2051: _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, 2051, __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, 2051, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2052: state = DENOM_SPACE
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
+2053: continue
goto __pyx_L24_continue;
/* … */
goto __pyx_L23_continue;
2054:
+2055: _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, 2055, __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, 2055, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2056: continue
goto __pyx_L24_continue;
break;
}
/* … */
goto __pyx_L23_continue;
break;
}
2057:
2058: # normal digit found
+2059: 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:
+2060: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
/* … */
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+2061: state = SMALL_DENOM
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
2062:
2063: # fast-path for consecutive digits
+2064: 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;
+2065: 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]);
+2066: 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, 2066, __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, 2066, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2067: 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) {
/* … */
}
+2068: break
goto __pyx_L33_break;
/* … */
goto __pyx_L32_break;
+2069: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
/* … */
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+2070: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L33_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L32_break:;
2071:
+2072: 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) {
/* … */
}
+2073: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM;
+2074: elif state == DENOM_US:
break;
default: break;
}
/* … */
break;
default: break;
}
+2075: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM;
2076:
2077: # We might have switched to DENOM above, so continue right here in that case.
+2078: 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:
2079: pass # handled above
+2080: elif state == DENOM:
break;
default:
/* … */
break;
default:
2081: # fast-path for consecutive digits
+2082: 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;
+2083: 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]);
+2084: 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, 2084, __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, 2084, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2085: 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) {
/* … */
}
+2086: break
goto __pyx_L39_break;
/* … */
goto __pyx_L38_break;
+2087: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L39_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L38_break:;
2088: else:
+2089: _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, 2089, __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, 2089, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L23_continue:; }
2090:
+2091: 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;
}
2092: # SMALL_NUM '.' | '.'
+2093: 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;
+2094: 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]);
+2095: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2096: 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, 2096, __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, 2096, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2097: 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) {
/* … */
}
+2098: if c == u'_':
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
/* … */
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
+2099: 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;
}
+2100: state = SMALL_DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
2101: else:
+2102: _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, 2102, __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, 2102, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L43:;
+2103: continue
goto __pyx_L41_continue;
/* … */
goto __pyx_L40_continue;
+2104: elif c in u'eE':
case 0x65:
/* … */
break;
default:
/* … */
case 0x65:
/* … */
break;
default:
+2105: 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:
+2106: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2106, __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, 2106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2107: else:
+2108: _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, 2108, __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, 2108, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2109: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
+2110: break
goto __pyx_L42_break;
/* … */
goto __pyx_L41_break;
2111: else:
+2112: 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) { /* … */ }
+2113: 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;
+2114: 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]);
+2115: 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) { /* … */ }
+2116: break
goto __pyx_L47_break;
/* … */
goto __pyx_L46_break;
+2117: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L47_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L46_break:;
2118:
+2119: 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:
+2120: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2120, __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, 2120, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+2121: state = SMALL_END_SPACE
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
2122: else:
+2123: _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, 2123, __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, 2123, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2124: continue
goto __pyx_L41_continue;
/* … */
goto __pyx_L40_continue;
2125:
+2126: _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, 2126, __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, 2126, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2127: continue
goto __pyx_L41_continue;
break;
}
/* … */
goto __pyx_L40_continue;
break;
}
2128:
2129: # normal digit found
+2130: 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:
+2131: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+2132: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2133: state = SMALL_DECIMAL
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
2134:
2135: # fast-path for consecutive digits
+2136: 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;
+2137: 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]);
+2138: 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, 2138, __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, 2138, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2139: 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) {
/* … */
}
+2140: break
goto __pyx_L50_break;
/* … */
goto __pyx_L49_break;
+2141: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+2142: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2143: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L50_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L49_break:;
2144:
+2145: 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) {
/* … */
}
+2146: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
+2147: break
goto __pyx_L42_break;
/* … */
goto __pyx_L41_break;
2148: else:
+2149: _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, 2149, __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, 2149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L40_continue:; } __pyx_L41_break:;
2150:
+2151: 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;
}
2152: # NUM '.' | SMALL_DECIMAL->DECIMAL
+2153: 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;
+2154: 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]);
+2155: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2156: 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, 2156, __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, 2156, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2157: 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) {
/* … */
}
+2158: if c == u'_':
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
/* … */
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
+2159: 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;
}
+2160: state = DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
2161: else:
+2162: _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, 2162, __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, 2162, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L60:;
+2163: continue
goto __pyx_L58_continue;
/* … */
goto __pyx_L57_continue;
+2164: elif c in u'eE':
case 0x65:
/* … */
break;
default:
/* … */
case 0x65:
/* … */
break;
default:
+2165: 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:
+2166: 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, 2166, __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, 2166, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2167: else:
+2168: _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, 2168, __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, 2168, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2169: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
+2170: break
goto __pyx_L59_break;
/* … */
goto __pyx_L58_break;
2171: else:
+2172: 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) { /* … */ }
+2173: 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:
+2174: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2175: else:
+2176: _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, 2176, __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, 2176, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2177: break
goto __pyx_L59_break;
/* … */
goto __pyx_L58_break;
2178:
+2179: _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, 2179, __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, 2179, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2180: continue
goto __pyx_L58_continue;
break;
}
/* … */
goto __pyx_L57_continue;
break;
}
2181:
2182: # normal digit found
+2183: 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:
+2184: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2185: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
2186:
2187: # fast-path for consecutive digits
+2188: 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;
+2189: 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]);
+2190: 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, 2190, __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, 2190, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2191: 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) {
/* … */
}
+2192: break
goto __pyx_L64_break;
/* … */
goto __pyx_L63_break;
+2193: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2194: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L64_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L63_break:;
2195: else:
+2196: _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, 2196, __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, 2196, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L57_continue:; } __pyx_L58_break:;
2197:
+2198: 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) {
/* … */
}
2199: # (SMALL_) NUM ['.' DECIMAL] 'E'
+2200: 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;
+2201: 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]);
+2202: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2203: 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, 2203, __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, 2203, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2204: 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) {
/* … */
}
+2205: 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:
+2206: 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;
}
+2207: exp_is_neg = c == u'-'
__pyx_v_exp_is_neg = (__pyx_v_c == 45);
/* … */
__pyx_v_exp_is_neg = (__pyx_v_c == 45);
+2208: state = EXP_SIGN
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
2209: else:
+2210: _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, 2210, __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, 2210, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L69:;
+2211: continue
goto __pyx_L67_continue;
/* … */
goto __pyx_L66_continue;
+2212: elif c == u'_':
break;
default:
/* … */
break;
default:
+2213: 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;
}
+2214: state = EXP_US
__pyx_v_state = __pyx_e_10quicktions_EXP_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_US;
2215: else:
+2216: _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, 2216, __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, 2216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L70:;
+2217: continue
goto __pyx_L67_continue;
/* … */
goto __pyx_L66_continue;
2218: else:
+2219: 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) { /* … */ }
+2220: 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;
}
+2221: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2222: else:
+2223: _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, 2223, __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, 2223, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L72:;
+2224: break
goto __pyx_L68_break;
/* … */
goto __pyx_L67_break;
2225:
+2226: _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, 2226, __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, 2226, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2227: continue
goto __pyx_L67_continue;
break;
}
/* … */
goto __pyx_L66_continue;
break;
}
2228:
2229: # normal digit found
+2230: 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:
+2231: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
/* … */
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2232: state = EXP
__pyx_v_state = __pyx_e_10quicktions_EXP;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP;
2233:
2234: # fast-path for consecutive digits
+2235: 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;
+2236: 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]);
+2237: 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, 2237, __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, 2237, __pyx_L1_error) __pyx_v_digit = __pyx_t_5;
+2238: 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) {
/* … */
}
+2239: break
goto __pyx_L75_break;
/* … */
goto __pyx_L74_break;
+2240: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
/* … */
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2241: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L75_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L74_break:;
2242:
+2243: 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) {
/* … */
}
+2244: _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, 2244, __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, 2244, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2245: else:
+2246: _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, 2246, __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, 2246, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L66_continue:; } __pyx_L67_break:;
2247:
+2248: 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;
}
+2249: 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;
+2250: 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]);
+2251: 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) { /* … */ }
+2252: break
goto __pyx_L81_break;
/* … */
goto __pyx_L80_break;
+2253: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L81_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L80_break:;
2254:
+2255: 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) {
/* … */
}
+2256: _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, 2256, __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, 2256, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2257:
+2258: cdef bint is_normalised = False
__pyx_v_is_normalised = 0; /* … */ __pyx_v_is_normalised = 0;
+2259: 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:
2260: # Special case for 'small' numbers: normalise directly in C space.
+2261: 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;
}
2262: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2263: 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;
}
+2264: 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, 2264, __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, 2264, __pyx_L1_error) __pyx_v_idenom = __pyx_t_7;
+2265: igcd = _c_gcd(inum, idenom)
__pyx_t_8 = __pyx_v_10quicktions__c_gcd(__pyx_v_inum, __pyx_v_idenom); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2265, __pyx_L1_error) __pyx_v_igcd = __pyx_t_8; /* … */ __pyx_t_8 = __pyx_v_10quicktions__c_gcd(__pyx_v_inum, __pyx_v_idenom); if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 2265, __pyx_L1_error) __pyx_v_igcd = __pyx_t_8;
+2266: 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;
}
+2267: inum //= igcd
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
/* … */
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
+2268: 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, 2268, __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, 2268, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2269: else:
+2270: denom = pow10(decimal_len)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2270, __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, 2270, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1);
__pyx_t_1 = 0;
}
__pyx_L89:;
2271: else:
+2272: denom = pow10(decimal_len)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2272, __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, 2272, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1);
__pyx_t_1 = 0;
}
__pyx_L86:;
2273: else:
+2274: 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:;
+2275: if is_neg:
if (__pyx_v_is_neg) {
/* … */
}
/* … */
if (__pyx_v_is_neg) {
/* … */
}
+2276: inum = -inum
__pyx_v_inum = (-__pyx_v_inum);
/* … */
__pyx_v_inum = (-__pyx_v_inum);
+2277: 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, 2277, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2277, __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, 2277, __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, 2277, __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, 2277, __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, 2277, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2277, __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, 2277, __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, 2277, __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, 2277, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = ((PyObject*)__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L0;
2278:
+2279: elif state == SMALL_DENOM:
break;
case __pyx_e_10quicktions_NUM:
/* … */
break;
case __pyx_e_10quicktions_NUM:
+2280: denom = idenom
__pyx_t_9 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2280, __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, 2280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0;
+2281: 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:
+2282: is_normalised = True # will be repaired below for iexp < 0
__pyx_v_is_normalised = 1;
/* … */
__pyx_v_is_normalised = 1;
+2283: 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);
+2284: 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, 2284, __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, 2284, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_9); __pyx_t_9 = 0;
+2285: elif state == DENOM:
break;
case __pyx_e_10quicktions_NUM_SPACE:
/* … */
break;
case __pyx_e_10quicktions_NUM_SPACE:
+2286: 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, 2286, __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, 2286, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_9); __pyx_t_9 = 0;
+2287: 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:
+2288: is_normalised = True
__pyx_v_is_normalised = 1;
/* … */
__pyx_v_is_normalised = 1;
+2289: 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);
+2290: elif state == DENOM_SPACE:
break;
default:
/* … */
break;
default:
2291: pass
2292: else:
+2293: _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, 2293, __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, 2293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; break; }
2294:
+2295: 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) {
/* … */
}
+2296: _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, 2296, __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, 2296, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+2297: if exp_is_neg:
if (__pyx_v_exp_is_neg) {
/* … */
}
/* … */
if (__pyx_v_exp_is_neg) {
/* … */
}
+2298: iexp = -iexp
__pyx_v_iexp = (-__pyx_v_iexp);
/* … */
__pyx_v_iexp = (-__pyx_v_iexp);
+2299: iexp -= decimal_len
__pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len); /* … */ __pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len);
2300:
+2301: 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;
}
+2302: num *= pow10(iexp)
__pyx_t_9 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2302, __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, 2302, __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, 2302, __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, 2302, __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;
+2303: 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:;
2304: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2305: 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, 2305, __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, 2305, __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, 2305, __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, 2305, __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, 2305, __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, 2305, __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, 2305, __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, 2305, __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;
+2306: denom = pow10(-iexp)
__pyx_t_3 = __pyx_f_10quicktions_pow10((-__pyx_v_iexp)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2306, __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, 2306, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2307:
+2308: if is_neg:
if (__pyx_v_is_neg) {
/* … */
}
/* … */
if (__pyx_v_is_neg) {
/* … */
}
+2309: num = -num
__pyx_t_3 = PyNumber_Negative(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2309, __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, 2309, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2310:
+2311: return num, denom, is_normalised
__Pyx_XDECREF(__pyx_r); if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2311, __pyx_L1_error) } __pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_is_normalised); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2311, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2311, __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, 2311, __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, 2311, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 2311, __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, 2311, __pyx_L1_error) } __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_is_normalised); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2311, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2311, __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, 2311, __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, 2311, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_1) != (0)) __PYX_ERR(0, 2311, __pyx_L1_error); __pyx_t_1 = 0; __pyx_r = ((PyObject*)__pyx_t_9); __pyx_t_9 = 0; goto __pyx_L0;