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