Generated by Cython 3.3.0
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']
{
PyObject* __pyx_temp[1] = {__pyx_mstate_global->__pyx_n_u_Fraction_2};
__pyx_t_2 = __Pyx_PyList_FromArray(__pyx_temp, 1); 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.24'
if (PyDict_SetItem(__pyx_mstate_global->__pyx_d, __pyx_mstate_global->__pyx_n_u_version, __pyx_mstate_global->__pyx_kp_u_1_24) < (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, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0; }
+0066: return tuple(l)
__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); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = ((PyObject*)__pyx_t_1); } __Pyx_XDECREF(__pyx_temp); } __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]
if (unlikely(__pyx_v_10quicktions_POW_10 == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 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, 1, 1, 1, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 78, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
0079: else:
+0080: return 10 ** (<object> i)
/*else*/ {
__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;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_3;
}
__Pyx_XDECREF(__pyx_temp);
}
__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_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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_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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __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_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); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_6; } __Pyx_XDECREF(__pyx_temp); } __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_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); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_6; } __Pyx_XDECREF(__pyx_temp); } __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_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);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_6;
}
__Pyx_XDECREF(__pyx_temp);
}
__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_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); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_6; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_6 = 0; goto __pyx_L0;
0237:
+0238: return _gcd_fallback(int(a), int(b))
__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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_7; } __Pyx_XDECREF(__pyx_temp); } __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_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;
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_1;
}
__Pyx_XDECREF(__pyx_temp);
}
__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_VECTORCALL 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 \047name\047 is one of: \047euclid\047, \047binary\047, \047hybrid\047\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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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_PyObject_CompareBoolNe_object_str(__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_PyObject_CompareBoolNe_object_str(__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_PyObject_CompareBoolNe_object_str(__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_PyObject_CompareBoolEq_object_str(__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_PyObject_CompareBoolEq_object_str(__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 = __Pyx_PyNumber_Subtract_object_object(__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_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); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __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_1 = __Pyx_PyObject_CompareBoolGt_int_object(__pyx_v_b, __pyx_v_10quicktions_PY_MAX_ULONGLONG, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 530, __pyx_L1_error)
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
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_a);
__pyx_r = __pyx_v_a;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
+0534: while a > PY_MAX_ULONGLONG:
while (1) {
__pyx_t_1 = __Pyx_PyObject_CompareBoolGt_int_object(__pyx_v_a, __pyx_v_10quicktions_PY_MAX_ULONGLONG, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 534, __pyx_L1_error)
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
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_a);
__pyx_r = __pyx_v_a;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
+0538: return _py_gcd(a, b)
__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); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __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_2);
__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 = __Pyx_PyObject_CompareBoolGe_object_int(__pyx_v_exponent, __pyx_mstate_global->__pyx_int_0, Py_GE); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 571, __pyx_L1_error) if (__pyx_t_1) { /* … */ goto __pyx_L3; }
+0572: d *= 10**exponent
__pyx_t_2 = PyNumber_Power(__pyx_mstate_global->__pyx_int_10, __pyx_v_exponent, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 572, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyNumber_InPlaceMultiply_object_object(__pyx_v_d, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 572, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_2 = PyNumber_Power(__pyx_mstate_global->__pyx_int_10, __pyx_t_3, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 574, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_3 = __Pyx_PyNumber_InPlaceMultiply_object_object(__pyx_v_n, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 574, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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_2 = __Pyx_PyNumber_Add_object_object(__pyx_v_n, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __pyx_t_3 = PyNumber_Divmod(__pyx_t_2, __pyx_v_d); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __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, 578, __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_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyList_GET_ITEM_REF(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_2 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 578, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __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_2 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); 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_2; __pyx_t_2 = 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_1 = __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_1 = __pyx_t_7; __pyx_L7_bool_binop_done:; if (__pyx_t_1) { /* … */ }
+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 = __Pyx_PyObject_CompareLt_object_int(__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_1 = __pyx_t_7;
} else {
__pyx_t_3 = __Pyx_PyObject_CompareLt_object_int(__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_1 = __pyx_t_7;
}
__pyx_v_sign = __pyx_t_1;
+0583: return sign, abs(q)
__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_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 583, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_GIVEREF(__pyx_t_3); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3) != (0)) __PYX_ERR(0, 583, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_4); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_4) != (0)) __PYX_ERR(0, 583, __pyx_L1_error); __pyx_t_3 = 0; __pyx_t_4 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 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_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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __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 = __Pyx_PyObject_CompareLe_str_str(__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 = __Pyx_PyNumber_Add_int_object(__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); if (__Pyx_PyInt_FromNumber(&__pyx_t_6, NULL, 0) < (0)) __PYX_ERR(0, 615, __pyx_L1_error) __pyx_v_exponent = ((PyObject*)__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_GET_ITEM_REF(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_GET_ITEM_REF(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, ((PyObject*)__pyx_t_6)); __pyx_t_6 = 0;
0623:
+0624: return sign, significand, exponent
__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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __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 = __Pyx_PyNumber_Or_object_object(__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 = __Pyx_PyNumber_Or_object_object(__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,
#if CYTHON_VECTORCALL_TPNEW
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
); /*proto*/
static int __pyx_pw_10quicktions_8Fraction_1__cinit__(PyObject *__pyx_v_self,
#if CYTHON_VECTORCALL_TPNEW
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
PyObject *__pyx_v_numerator = 0;
PyObject *__pyx_v_denominator = 0;
#if !CYTHON_VECTORCALL_TPNEW
CYTHON_UNUSED Py_ssize_t __pyx_nargs;
#endif
CYTHON_UNUSED PyObject *const *__pyx_kwvalues;
int __pyx_r;
__Pyx_RefNannyDeclarations
__Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0);
#if !CYTHON_VECTORCALL_TPNEW
#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
#endif
__pyx_kwvalues = __Pyx_KwValues_FASTCALL_TPNEW(__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_FASTCALL_TPNEW(__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_FASTCALL_TPNEW(__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_FASTCALL_TPNEW(__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_FASTCALL_TPNEW(__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_FASTCALL_TPNEW(__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_GET_ITEM_REF(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_GET_ITEM_REF(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 \047NoneType\047 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_GET_ITEM_REF(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_GET_ITEM_REF(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_GET_ITEM_REF(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_GET_ITEM_REF(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 = __Pyx_PyNumber_Multiply_object_object(((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 = __Pyx_PyNumber_Multiply_object_object(((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 = __Pyx_PyNumber_Multiply_object_object(__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 = __Pyx_PyNumber_Multiply_object_object(__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_8 = 13;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_8 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_11[1]);
#endif
__pyx_t_12 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_11[1]);
#endif
__pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_11, 3, __pyx_t_8, __pyx_t_12);
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_1 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_denominator, __pyx_mstate_global->__pyx_int_0, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 786, __pyx_L1_error) 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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_8); __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_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;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
0807:
+0808: elif type(number) is float:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_number)) == ((PyObject *)(&PyFloat_Type)));
if (__pyx_t_1) {
/* … */
}
+0809: n, d = (<float> number).as_integer_ratio()
__pyx_t_6 = __Pyx_PyFloat_AsFloat(__pyx_v_number); if (unlikely((__pyx_t_6 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 809, __pyx_L1_error) __pyx_t_2 = PyFloat_FromDouble(((float)__pyx_t_6)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 809, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __pyx_t_2; __Pyx_INCREF(__pyx_t_3); __pyx_t_7 = 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_7, (1-__pyx_t_7) | (1*__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_4)) __PYX_ERR(0, 809, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } if (!(likely(PyTuple_CheckExact(__pyx_t_4))||((__pyx_t_4) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_t_4))) __PYX_ERR(0, 809, __pyx_L1_error) if (likely(__pyx_t_4 != Py_None)) { PyObject* sequence = __pyx_t_4; Py_ssize_t size = __Pyx_PyTuple_GET_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 809, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS __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_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 809, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 809, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); #endif __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; } else { __Pyx_RaiseNoneNotIterableError(); __PYX_ERR(0, 809, __pyx_L1_error) } __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_3; __pyx_t_3 = 0;
+0810: return _fraction_from_coprime_ints(n, d, cls)
__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, 810, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
0811:
+0812: elif isinstance(number, int):
__pyx_t_1 = PyLong_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0813: return _fraction_from_coprime_ints(number, 1, cls)
__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, 813, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
0814:
+0815: elif isinstance(number, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_number);
if (__pyx_t_1) {
/* … */
}
+0816: n, d = number.as_integer_ratio()
__pyx_t_3 = __pyx_v_number;
__Pyx_INCREF(__pyx_t_3);
__pyx_t_7 = 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_7, (1-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 816, __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, 816, __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_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 816, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 816, __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, 816, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 816, __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_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 816, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_9 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_8);
index = 0; __pyx_t_3 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_3)) goto __pyx_L4_unpacking_failed;
__Pyx_GOTREF(__pyx_t_3);
index = 1; __pyx_t_2 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_2)) goto __pyx_L4_unpacking_failed;
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < (0)) __PYX_ERR(0, 816, __pyx_L1_error)
__pyx_t_9 = NULL;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
goto __pyx_L5_unpacking_done;
__pyx_L4_unpacking_failed:;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 816, __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;
+0817: return cls(n, d)
__pyx_t_2 = NULL;
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_v_n, __pyx_v_d};
__pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)__pyx_v_cls, __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;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 817, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
0818:
+0819: 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, 819, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+0820: return cls(number.numerator, number.denominator)
__pyx_t_2 = NULL;
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 820, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_v_number, __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 820, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_t_3, __pyx_t_8};
__pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)__pyx_v_cls, __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_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 820, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
0821:
+0822: elif not isinstance(number, type) and hasattr(number, 'as_integer_ratio'):
__pyx_t_10 = PyType_Check(__pyx_v_number); __pyx_t_11 = (!__pyx_t_10); if (__pyx_t_11) { } else { __pyx_t_1 = __pyx_t_11; goto __pyx_L6_bool_binop_done; } __pyx_t_11 = __Pyx_HasAttr(__pyx_v_number, __pyx_mstate_global->__pyx_n_u_as_integer_ratio); if (unlikely(__pyx_t_11 == ((int)-1))) __PYX_ERR(0, 822, __pyx_L1_error) __pyx_t_1 = __pyx_t_11; __pyx_L6_bool_binop_done:; if (likely(__pyx_t_1)) { /* … */ }
+0823: n, d = number.as_integer_ratio()
__pyx_t_8 = __pyx_v_number;
__Pyx_INCREF(__pyx_t_8);
__pyx_t_7 = 0;
{
PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL};
__pyx_t_4 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_7, (1-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 823, __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, 823, __pyx_L1_error)
}
#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS
if (likely(PyTuple_CheckExact(sequence))) {
__pyx_t_8 = PyTuple_GET_ITEM(sequence, 0);
__Pyx_INCREF(__pyx_t_8);
__pyx_t_3 = PyTuple_GET_ITEM(sequence, 1);
__Pyx_INCREF(__pyx_t_3);
} else {
__pyx_t_8 = __Pyx_PyList_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 823, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_8);
__pyx_t_3 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_3);
}
#else
__pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 823, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__pyx_t_3 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 823, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
#endif
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_2 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 823, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_9 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_2);
index = 0; __pyx_t_8 = __pyx_t_9(__pyx_t_2); if (unlikely(!__pyx_t_8)) goto __pyx_L8_unpacking_failed;
__Pyx_GOTREF(__pyx_t_8);
index = 1; __pyx_t_3 = __pyx_t_9(__pyx_t_2); if (unlikely(!__pyx_t_3)) goto __pyx_L8_unpacking_failed;
__Pyx_GOTREF(__pyx_t_3);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_2), 2) < (0)) __PYX_ERR(0, 823, __pyx_L1_error)
__pyx_t_9 = NULL;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
goto __pyx_L9_unpacking_done;
__pyx_L8_unpacking_failed:;
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_t_9 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 823, __pyx_L1_error)
__pyx_L9_unpacking_done:;
}
__pyx_v_n = __pyx_t_8;
__pyx_t_8 = 0;
__pyx_v_d = __pyx_t_3;
__pyx_t_3 = 0;
+0824: return cls(n, d)
__pyx_t_3 = NULL;
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_v_n, __pyx_v_d};
__pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)__pyx_v_cls, __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;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 824, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
0825:
0826: else:
+0827: raise TypeError("argument should be a Rational instance or "
/*else*/ {
__pyx_t_3 = NULL;
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_mstate_global->__pyx_kp_u_argument_should_be_a_Rational_in};
__pyx_t_4 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_TypeError)), __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;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 827, __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, 827, __pyx_L1_error)
}
0828: "have the as_integer_ratio() method")
0829:
+0830: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_5from_float(PyObject *__pyx_v_cls, #if CYTHON_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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, 830, __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, 830, __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, 830, __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, 830, __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, 830, __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, 830, __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_num = NULL; PyObject *__pyx_v_denom = 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_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_14); __Pyx_XDECREF(__pyx_t_15); __Pyx_AddTraceback("quicktions.Fraction.from_float", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_num); __Pyx_XDECREF(__pyx_v_denom); __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, 830, __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, 830, __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, 830, __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, 830, __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, 830, __pyx_L1_error) __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
0831: def from_float(cls, f):
0832: """Converts a finite float to a rational number, exactly.
0833:
0834: Beware that Fraction.from_float(0.3) != Fraction(3, 10).
0835:
0836: """
+0837: 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);
}
+0838: num, denom = 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, 838, __pyx_L3_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, 838, __pyx_L3_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_7 = PyTuple_GET_ITEM(sequence, 1);
__Pyx_INCREF(__pyx_t_7);
} else {
__pyx_t_5 = __Pyx_PyList_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 838, __pyx_L3_error)
__Pyx_XGOTREF(__pyx_t_5);
__pyx_t_7 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 838, __pyx_L3_error)
__Pyx_XGOTREF(__pyx_t_7);
}
#else
__pyx_t_5 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 838, __pyx_L3_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_7 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 838, __pyx_L3_error)
__Pyx_GOTREF(__pyx_t_7);
#endif
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_8 = PyObject_GetIter(__pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 838, __pyx_L3_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_9 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_8);
index = 0; __pyx_t_5 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_5)) goto __pyx_L9_unpacking_failed;
__Pyx_GOTREF(__pyx_t_5);
index = 1; __pyx_t_7 = __pyx_t_9(__pyx_t_8); if (unlikely(!__pyx_t_7)) goto __pyx_L9_unpacking_failed;
__Pyx_GOTREF(__pyx_t_7);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_9(__pyx_t_8), 2) < (0)) __PYX_ERR(0, 838, __pyx_L3_error)
__pyx_t_9 = NULL;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
goto __pyx_L10_unpacking_done;
__pyx_L9_unpacking_failed:;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_9 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 838, __pyx_L3_error)
__pyx_L10_unpacking_done:;
}
__pyx_v_num = __pyx_t_5;
__pyx_t_5 = 0;
__pyx_v_denom = __pyx_t_7;
__pyx_t_7 = 0;
+0839: except (ValueError, OverflowError, AttributeError):
__pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(((PyTypeObject*)PyExc_ValueError)))) || __Pyx_PyErr_ExceptionMatches(((PyObject *)(((PyTypeObject*)PyExc_OverflowError)))) || __Pyx_PyErr_ExceptionMatches(((PyObject *)(((PyTypeObject*)PyExc_AttributeError)))); if (__pyx_t_12) { __Pyx_ErrRestore(0,0,0); goto __pyx_L4_exception_handled; } goto __pyx_L5_except_error;
0840: pass # not something we can convert, raise concrete exceptions below
0841: else:
0842: # float.as_integer_ratio() returns a normalised fraction, subtypes may not.
+0843: return _fraction_from_coprime_ints(num, denom, cls) if type(f) is float else cls(num, denom)
/*else:*/ {
__pyx_t_10 = (((PyObject *)Py_TYPE(__pyx_v_f)) == ((PyObject *)(&PyFloat_Type)));
if (__pyx_t_10) {
__pyx_t_11.__pyx_n = 1;
__pyx_t_11.cls = ((PyObject *)__pyx_v_cls);
__pyx_t_7 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_num, __pyx_v_denom, &__pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 843, __pyx_L5_except_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_4 = __pyx_t_7;
__pyx_t_7 = 0;
} else {
__pyx_t_5 = NULL;
__pyx_t_6 = 1;
{
PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_v_num, __pyx_v_denom};
__pyx_t_7 = __Pyx_PyObject_FastCall((PyObject*)__pyx_v_cls, __pyx_callargs+__pyx_t_6, (3-__pyx_t_6) | (__pyx_t_6*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 843, __pyx_L5_except_error)
__Pyx_GOTREF(__pyx_t_7);
}
__pyx_t_4 = __pyx_t_7;
__pyx_t_7 = 0;
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L6_except_return;
}
__pyx_L3_error:;
__Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0;
__Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0;
0844:
+0845: if isinstance(f, Integral):
__pyx_t_4 = __pyx_v_10quicktions_Integral; __Pyx_INCREF(__pyx_t_4); __pyx_t_10 = PyObject_IsInstance(__pyx_v_f, __pyx_t_4); if (unlikely(__pyx_t_10 == ((int)-1))) __PYX_ERR(0, 845, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_10) { /* … */ }
+0846: return cls(int(f))
__pyx_t_7 = NULL;
__pyx_t_5 = __Pyx_PyNumber_Int(__pyx_v_f); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 846, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_6 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_5};
__pyx_t_4 = __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_7); __pyx_t_7 = 0;
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 846, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
+0847: elif not isinstance(f, float):
__pyx_t_10 = PyFloat_Check(__pyx_v_f);
__pyx_t_13 = (!__pyx_t_10);
if (unlikely(__pyx_t_13)) {
/* … */
}
+0848: raise TypeError(f"{cls.__name__}.from_float() only takes floats, not {f!r} ({type(f).__name__})")
__pyx_t_5 = NULL;
__pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 848, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_t_7, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 848, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_7 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 848, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_f)), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 848, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__pyx_t_15 = __Pyx_PyObject_FormatSimple(__pyx_t_14, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 848, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
__pyx_t_16[0] = __pyx_t_8;
__pyx_t_16[1] = __pyx_mstate_global->__pyx_kp_u_from_float_only_takes_floats_no;
__pyx_t_16[2] = __pyx_t_7;
__pyx_t_16[3] = __pyx_mstate_global->__pyx_kp_u__3;
__pyx_t_16[4] = __pyx_t_15;
__pyx_t_16[5] = __pyx_mstate_global->__pyx_kp_u__4;
__pyx_t_17 = 40;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_17 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_16[0]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_16[2]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_16[4]);
#endif
__pyx_t_12 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_16[0]) | __Pyx_PyUnicode_KIND_04(__pyx_t_16[2]) | __Pyx_PyUnicode_KIND_04(__pyx_t_16[4]);
#endif
__pyx_t_14 = __Pyx_PyUnicode_Join(__pyx_t_16, 6, __pyx_t_17, __pyx_t_12);
if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 848, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__pyx_t_6 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_t_14};
__pyx_t_4 = __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_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 848, __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, 848, __pyx_L1_error)
+0849: if math.isinf(f):
__pyx_t_14 = __pyx_v_10quicktions_math; __Pyx_INCREF(__pyx_t_14); __pyx_t_6 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_v_f}; __pyx_t_4 = __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_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 849, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); } __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 849, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (unlikely(__pyx_t_13)) { /* … */ }
+0850: raise OverflowError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_14 = NULL;
__pyx_t_5 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 850, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 850, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__pyx_t_7 = __Pyx_PyObject_FormatSimple(__pyx_t_15, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 850, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__pyx_t_18[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert;
__pyx_t_18[1] = __pyx_t_5;
__pyx_t_18[2] = __pyx_mstate_global->__pyx_kp_u_to;
__pyx_t_18[3] = __pyx_t_7;
__pyx_t_18[4] = __pyx_mstate_global->__pyx_kp_u_;
__pyx_t_17 = 20;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_17 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[1]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[3]);
#endif
__pyx_t_12 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_18[1]) | __Pyx_PyUnicode_KIND_04(__pyx_t_18[3]);
#endif
__pyx_t_15 = __Pyx_PyUnicode_Join(__pyx_t_18, 5, __pyx_t_17, __pyx_t_12);
if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 850, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0;
__pyx_t_6 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_t_15};
__pyx_t_4 = __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_14); __pyx_t_14 = 0;
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 850, __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, 850, __pyx_L1_error)
+0851: raise ValueError(f"Cannot convert {f!r} to {cls.__name__}.")
__pyx_t_15 = NULL; __pyx_t_14 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_f), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_7 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_7, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_18[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert; __pyx_t_18[1] = __pyx_t_14; __pyx_t_18[2] = __pyx_mstate_global->__pyx_kp_u_to; __pyx_t_18[3] = __pyx_t_5; __pyx_t_18[4] = __pyx_mstate_global->__pyx_kp_u_; __pyx_t_17 = 20; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_17 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[1]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[3]); #endif __pyx_t_12 = 0; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_18[1]) | __Pyx_PyUnicode_KIND_04(__pyx_t_18[3]); #endif __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_18, 5, __pyx_t_17, __pyx_t_12); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 851, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_6 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_7}; __pyx_t_4 = __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_15); __pyx_t_15 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 851, __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, 851, __pyx_L1_error)
0852:
+0853: @classmethod
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_7from_decimal(PyObject *__pyx_v_cls, #if CYTHON_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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, 853, __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, 853, __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, 853, __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, 853, __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, 853, __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, 853, __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_5); __Pyx_XDECREF(__pyx_t_6); __Pyx_XDECREF(__pyx_t_8); __Pyx_XDECREF(__pyx_t_9); __Pyx_XDECREF(__pyx_t_14); __Pyx_XDECREF(__pyx_t_15); __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, 853, __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, 853, __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, 853, __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, 853, __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, 853, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
0854: def from_decimal(cls, dec):
0855: """Converts a finite Decimal instance to a rational number, exactly."""
0856: cdef Py_ssize_t exp
+0857: if type(dec) is Decimal:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_dec)) == __pyx_v_10quicktions_Decimal);
if (__pyx_t_1) {
/* … */
}
+0858: 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_L7_except_return:;
__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_L0;
__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);
}
+0859: num, denom = dec.as_integer_ratio()
__pyx_t_6 = __pyx_v_dec;
__Pyx_INCREF(__pyx_t_6);
__pyx_t_7 = 0;
{
PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL};
__pyx_t_5 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_7, (1-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 859, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_5);
}
if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) {
PyObject* sequence = __pyx_t_5;
Py_ssize_t size = __Pyx_PySequence_SIZE(sequence);
if (unlikely(size != 2)) {
if (size > 2) __Pyx_RaiseTooManyValuesError(2);
else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size);
__PYX_ERR(0, 859, __pyx_L4_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_8 = PyTuple_GET_ITEM(sequence, 1);
__Pyx_INCREF(__pyx_t_8);
} else {
__pyx_t_6 = __Pyx_PyList_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L4_error)
__Pyx_XGOTREF(__pyx_t_6);
__pyx_t_8 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 859, __pyx_L4_error)
__Pyx_XGOTREF(__pyx_t_8);
}
#else
__pyx_t_6 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 859, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 859, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_8);
#endif
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_9 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 859, __pyx_L4_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_9);
index = 0; __pyx_t_6 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_6)) goto __pyx_L10_unpacking_failed;
__Pyx_GOTREF(__pyx_t_6);
index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_9); if (unlikely(!__pyx_t_8)) goto __pyx_L10_unpacking_failed;
__Pyx_GOTREF(__pyx_t_8);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_9), 2) < (0)) __PYX_ERR(0, 859, __pyx_L4_error)
__pyx_t_10 = NULL;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
goto __pyx_L11_unpacking_done;
__pyx_L10_unpacking_failed:;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__pyx_t_10 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 859, __pyx_L4_error)
__pyx_L11_unpacking_done:;
}
__pyx_v_num = __pyx_t_6;
__pyx_t_6 = 0;
__pyx_v_denom = __pyx_t_8;
__pyx_t_8 = 0;
+0860: except (OverflowError, ValueError):
__pyx_t_12 = __Pyx_PyErr_ExceptionMatches2(((PyObject *)(((PyTypeObject*)PyExc_OverflowError))), ((PyObject *)(((PyTypeObject*)PyExc_ValueError))));
if (__pyx_t_12) {
__Pyx_ErrRestore(0,0,0);
goto __pyx_L5_exception_handled;
}
goto __pyx_L6_except_error;
0861: pass
0862: else:
+0863: return _fraction_from_coprime_ints(num, denom, cls)
/*else:*/ {
__pyx_t_11.__pyx_n = 1;
__pyx_t_11.cls = ((PyObject *)__pyx_v_cls);
__pyx_t_5 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_num, __pyx_v_denom, &__pyx_t_11); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 863, __pyx_L6_except_error)
__Pyx_GOTREF(__pyx_t_5);
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_5;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_5 = 0;
goto __pyx_L7_except_return;
}
__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_8); __pyx_t_8 = 0;
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
+0864: if isinstance(dec, Integral):
__pyx_t_5 = __pyx_v_10quicktions_Integral; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = PyObject_IsInstance(__pyx_v_dec, __pyx_t_5); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 864, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ goto __pyx_L14; }
+0865: dec = Decimal(int(dec))
__pyx_t_8 = NULL;
__Pyx_INCREF(__pyx_v_10quicktions_Decimal);
__pyx_t_6 = __pyx_v_10quicktions_Decimal;
__pyx_t_9 = __Pyx_PyNumber_Int(__pyx_v_dec); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 865, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__pyx_t_7 = 1;
#if CYTHON_UNPACK_METHODS
if (unlikely(PyMethod_Check(__pyx_t_6))) {
__pyx_t_8 = PyMethod_GET_SELF(__pyx_t_6);
assert(__pyx_t_8);
PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_6);
__Pyx_INCREF(__pyx_t_8);
__Pyx_INCREF(__pyx__function);
__Pyx_DECREF_SET(__pyx_t_6, __pyx__function);
__pyx_t_7 = 0;
}
#endif
{
PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_t_9};
__pyx_t_5 = __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_8); __pyx_t_8 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 865, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
}
__Pyx_DECREF_SET(__pyx_v_dec, __pyx_t_5);
__pyx_t_5 = 0;
+0866: elif not isinstance(dec, Decimal):
__pyx_t_5 = __pyx_v_10quicktions_Decimal; __Pyx_INCREF(__pyx_t_5); __pyx_t_1 = PyObject_IsInstance(__pyx_v_dec, __pyx_t_5); if (unlikely(__pyx_t_1 == ((int)-1))) __PYX_ERR(0, 866, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_13 = (!__pyx_t_1); if (unlikely(__pyx_t_13)) { /* … */ } __pyx_L14:;
+0867: raise TypeError(
__pyx_t_6 = NULL;
+0868: f"{cls.__name__}.from_decimal() only takes Decimals, not {dec!r} ({type(dec).__name__})")
__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, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_8 = __Pyx_PyObject_FormatSimple(__pyx_t_9, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __pyx_t_9 = __Pyx_PyObject_FormatSimpleAndDecref(PyObject_Repr(__pyx_v_dec), __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_14 = __Pyx_PyObject_GetAttrStr(((PyObject *)Py_TYPE(__pyx_v_dec)), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __pyx_t_15 = __Pyx_PyObject_FormatSimple(__pyx_t_14, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; __pyx_t_16[0] = __pyx_t_8; __pyx_t_16[1] = __pyx_mstate_global->__pyx_kp_u_from_decimal_only_takes_Decimal; __pyx_t_16[2] = __pyx_t_9; __pyx_t_16[3] = __pyx_mstate_global->__pyx_kp_u__3; __pyx_t_16[4] = __pyx_t_15; __pyx_t_16[5] = __pyx_mstate_global->__pyx_kp_u__4; __pyx_t_17 = 44; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_17 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_16[0]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_16[2]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_16[4]); #endif __pyx_t_12 = 0; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_16[0]) | __Pyx_PyUnicode_KIND_04(__pyx_t_16[2]) | __Pyx_PyUnicode_KIND_04(__pyx_t_16[4]); #endif __pyx_t_14 = __Pyx_PyUnicode_Join(__pyx_t_16, 6, __pyx_t_17, __pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 868, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_14); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; __pyx_t_7 = 1; { PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_14}; __pyx_t_5 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_TypeError)), __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 867, __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, 867, __pyx_L1_error)
+0869: if dec.is_infinite():
__pyx_t_14 = __pyx_v_dec; __Pyx_INCREF(__pyx_t_14); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_14, NULL}; __pyx_t_5 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_is_infinite, __pyx_callargs+__pyx_t_7, (1-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 869, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 869, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_t_13)) { /* … */ }
+0870: raise OverflowError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_14 = NULL;
__pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_v_dec, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 870, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_15 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_cls), __pyx_mstate_global->__pyx_n_u_name); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 870, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__pyx_t_9 = __Pyx_PyObject_FormatSimple(__pyx_t_15, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 870, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
__pyx_t_18[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert;
__pyx_t_18[1] = __pyx_t_6;
__pyx_t_18[2] = __pyx_mstate_global->__pyx_kp_u_to;
__pyx_t_18[3] = __pyx_t_9;
__pyx_t_18[4] = __pyx_mstate_global->__pyx_kp_u_;
__pyx_t_17 = 20;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_17 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[1]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[3]);
#endif
__pyx_t_12 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_18[1]) | __Pyx_PyUnicode_KIND_04(__pyx_t_18[3]);
#endif
__pyx_t_15 = __Pyx_PyUnicode_Join(__pyx_t_18, 5, __pyx_t_17, __pyx_t_12);
if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 870, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_t_15};
__pyx_t_5 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_OverflowError)), __pyx_callargs+__pyx_t_7, (2-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0;
__Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 870, __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, 870, __pyx_L1_error)
+0871: if dec.is_nan():
__pyx_t_15 = __pyx_v_dec; __Pyx_INCREF(__pyx_t_15); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_15, NULL}; __pyx_t_5 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_is_nan, __pyx_callargs+__pyx_t_7, (1-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 871, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } __pyx_t_13 = __Pyx_PyObject_IsTrue(__pyx_t_5); if (unlikely((__pyx_t_13 < 0))) __PYX_ERR(0, 871, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (unlikely(__pyx_t_13)) { /* … */ }
+0872: raise ValueError(f"Cannot convert {dec} to {cls.__name__}.")
__pyx_t_15 = NULL;
__pyx_t_14 = __Pyx_PyObject_FormatSimple(__pyx_v_dec, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 872, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_14);
__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, 872, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__pyx_t_6 = __Pyx_PyObject_FormatSimple(__pyx_t_9, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 872, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_6);
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
__pyx_t_18[0] = __pyx_mstate_global->__pyx_kp_u_Cannot_convert;
__pyx_t_18[1] = __pyx_t_14;
__pyx_t_18[2] = __pyx_mstate_global->__pyx_kp_u_to;
__pyx_t_18[3] = __pyx_t_6;
__pyx_t_18[4] = __pyx_mstate_global->__pyx_kp_u_;
__pyx_t_17 = 20;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_17 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[1]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_18[3]);
#endif
__pyx_t_12 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_12 |= __Pyx_PyUnicode_KIND_04(__pyx_t_18[1]) | __Pyx_PyUnicode_KIND_04(__pyx_t_18[3]);
#endif
__pyx_t_9 = __Pyx_PyUnicode_Join(__pyx_t_18, 5, __pyx_t_17, __pyx_t_12);
if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 872, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_9);
__Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0;
__Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_t_9};
__pyx_t_5 = __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_15); __pyx_t_15 = 0;
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 872, __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, 872, __pyx_L1_error)
0873:
+0874: num, denom = dec.as_integer_ratio()
__pyx_t_9 = __pyx_v_dec; __Pyx_INCREF(__pyx_t_9); __pyx_t_7 = 0; { PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL}; __pyx_t_5 = __Pyx_PyObject_FastCallMethod((PyObject*)__pyx_mstate_global->__pyx_n_u_as_integer_ratio, __pyx_callargs+__pyx_t_7, (1-__pyx_t_7) | (1*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); } if ((likely(PyTuple_CheckExact(__pyx_t_5))) || (PyList_CheckExact(__pyx_t_5))) { PyObject* sequence = __pyx_t_5; Py_ssize_t size = __Pyx_PySequence_SIZE(sequence); if (unlikely(size != 2)) { if (size > 2) __Pyx_RaiseTooManyValuesError(2); else if (size >= 0) __Pyx_RaiseNeedMoreValuesError(size); __PYX_ERR(0, 874, __pyx_L1_error) } #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS if (likely(PyTuple_CheckExact(sequence))) { __pyx_t_9 = PyTuple_GET_ITEM(sequence, 0); __Pyx_INCREF(__pyx_t_9); __pyx_t_15 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_15); } else { __pyx_t_9 = __Pyx_PyList_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_9); __pyx_t_15 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_15); } #else __pyx_t_9 = __Pyx_PySequence_ITEM(sequence, 0); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_15 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_15); #endif __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; } else { Py_ssize_t index = -1; __pyx_t_6 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 874, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_6); index = 0; __pyx_t_9 = __pyx_t_10(__pyx_t_6); if (unlikely(!__pyx_t_9)) goto __pyx_L17_unpacking_failed; __Pyx_GOTREF(__pyx_t_9); index = 1; __pyx_t_15 = __pyx_t_10(__pyx_t_6); if (unlikely(!__pyx_t_15)) goto __pyx_L17_unpacking_failed; __Pyx_GOTREF(__pyx_t_15); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_6), 2) < (0)) __PYX_ERR(0, 874, __pyx_L1_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; goto __pyx_L18_unpacking_done; __pyx_L17_unpacking_failed:; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_10 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 874, __pyx_L1_error) __pyx_L18_unpacking_done:; } __Pyx_XDECREF_SET(__pyx_v_num, __pyx_t_9); __pyx_t_9 = 0; __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_15); __pyx_t_15 = 0;
+0875: return _fraction_from_coprime_ints(num, denom, cls) if type(dec) is Decimal else cls(num, denom)
__pyx_t_13 = (((PyObject *)Py_TYPE(__pyx_v_dec)) == __pyx_v_10quicktions_Decimal);
if (__pyx_t_13) {
__pyx_t_11.__pyx_n = 1;
__pyx_t_11.cls = ((PyObject *)__pyx_v_cls);
__pyx_t_15 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_num, __pyx_v_denom, &__pyx_t_11); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 875, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
__pyx_t_5 = __pyx_t_15;
__pyx_t_15 = 0;
} else {
__pyx_t_9 = NULL;
__pyx_t_7 = 1;
{
PyObject *__pyx_callargs[3] = {__pyx_t_9, __pyx_v_num, __pyx_v_denom};
__pyx_t_15 = __Pyx_PyObject_FastCall((PyObject*)__pyx_v_cls, __pyx_callargs+__pyx_t_7, (3-__pyx_t_7) | (__pyx_t_7*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0;
if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 875, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_15);
}
__pyx_t_5 = __pyx_t_15;
__pyx_t_15 = 0;
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_5;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_5 = 0;
goto __pyx_L0;
0876:
+0877: def is_integer(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_9is_integer(PyObject *__pyx_v_self, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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, 877, __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, 877, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
0878: """Return True if the Fraction is an integer."""
+0879: return self._denominator == 1
__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, 879, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
0880:
+0881: def as_integer_ratio(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_11as_integer_ratio(PyObject *__pyx_v_self, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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, 881, __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, 881, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
0882: """Return a pair of integers, whose ratio is equal to the original Fraction.
0883:
0884: The ratio is in lowest terms and has a positive denominator.
0885: """
+0886: return (self._numerator, self._denominator)
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 886, __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, 886, __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, 886, __pyx_L1_error); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
0887:
+0888: def limit_denominator(self, max_denominator=1000000):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_13limit_denominator(PyObject *__pyx_v_self, #if CYTHON_VECTORCALL 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(\0473.141592653589793\047).limit_denominator(10)\n Fraction(22, 7)\n >>> Fraction(\0473.141592653589793\047).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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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, 888, __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, 888, __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, 888, __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, 888, __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, 888, __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_2); __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, 888, __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, 888, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; /* … */ { PyObject* __pyx_temp[1] = {__pyx_mstate_global->__pyx_int_1000000}; __pyx_mstate_global->__pyx_tuple[0] = __Pyx_PyTuple_FromArray(__pyx_temp, 1); if (unlikely(!__pyx_mstate_global->__pyx_tuple[0])) __PYX_ERR(0, 888, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[0]); } __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[0]);
0889: """Closest Fraction to self with denominator at most max_denominator.
0890:
0891: >>> Fraction('3.141592653589793').limit_denominator(10)
0892: Fraction(22, 7)
0893: >>> Fraction('3.141592653589793').limit_denominator(100)
0894: Fraction(311, 99)
0895: >>> Fraction(4321, 8765).limit_denominator(10000)
0896: Fraction(4321, 8765)
0897:
0898: """
0899: # Algorithm notes: For any real number x, define a *best upper
0900: # approximation* to x to be a rational number p/q such that:
0901: #
0902: # (1) p/q >= x, and
0903: # (2) if p/q > r/s >= x then s > q, for any rational r/s.
0904: #
0905: # Define *best lower approximation* similarly. Then it can be
0906: # proved that a rational number is a best upper or lower
0907: # approximation to x if, and only if, it is a convergent or
0908: # semiconvergent of the (unique shortest) continued fraction
0909: # associated to x.
0910: #
0911: # To find a best rational approximation with denominator <= M,
0912: # we find the best upper and lower approximations with
0913: # denominator <= M and take whichever of these is closer to x.
0914: # In the event of a tie, the bound with smaller denominator is
0915: # chosen. If both denominators are equal (which can happen
0916: # only when max_denominator == 1 and self is midway between
0917: # two integers) the lower bound---i.e., the floor of self, is
0918: # taken.
0919:
+0920: if max_denominator < 1:
__pyx_t_1 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_max_denominator, __pyx_mstate_global->__pyx_int_1, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 920, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+0921: 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_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;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 921, __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, 921, __pyx_L1_error)
+0922: if self._denominator <= max_denominator:
__pyx_t_1 = __Pyx_PyObject_CompareBoolLe_object_object(__pyx_v_self->_denominator, __pyx_v_max_denominator, Py_LE); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 922, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0923: return Fraction(self)
__pyx_t_3 = NULL;
__pyx_t_4 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_3, ((PyObject *)__pyx_v_self)};
__pyx_t_2 = __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_2)) __PYX_ERR(0, 923, __pyx_L1_error)
__Pyx_GOTREF((PyObject *)__pyx_t_2);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = ((PyObject *)__pyx_t_2);
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
0924:
+0925: p0, q0, p1, q1 = 0, 1, 1, 0
__pyx_t_2 = __pyx_mstate_global->__pyx_int_0; __Pyx_INCREF(__pyx_t_2); __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_2; __pyx_t_2 = 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;
+0926: 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;
+0927: while True:
while (1) {
+0928: a = n//d
__pyx_t_5 = PyNumber_FloorDivide(__pyx_v_n, __pyx_v_d); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 928, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_XDECREF_SET(__pyx_v_a, __pyx_t_5); __pyx_t_5 = 0;
+0929: q2 = q0+a*q1
__pyx_t_5 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_a, __pyx_v_q1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 929, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = __Pyx_PyNumber_Add_int_object(__pyx_v_q0, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 929, __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;
+0930: if q2 > max_denominator:
__pyx_t_1 = __Pyx_PyObject_CompareBoolGt_object_object(__pyx_v_q2, __pyx_v_max_denominator, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 930, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0931: break
goto __pyx_L6_break;
+0932: 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 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_a, __pyx_v_p1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 932, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PyNumber_Add_int_object(__pyx_v_p0, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 932, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__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_2);
__pyx_t_2 = 0;
__Pyx_DECREF_SET(__pyx_v_q1, __pyx_t_3);
__pyx_t_3 = 0;
+0933: n, d = d, n-a*d
__pyx_t_3 = __pyx_v_d;
__Pyx_INCREF(__pyx_t_3);
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_a, __pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 933, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_5 = __Pyx_PyNumber_Subtract_object_object(__pyx_v_n, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 933, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 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:;
0934:
+0935: k = (max_denominator-q0)//q1
__pyx_t_5 = __Pyx_PyNumber_Subtract_object_object(__pyx_v_max_denominator, __pyx_v_q0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 935, __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, 935, __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;
0936:
0937: # Determine which of the candidates (p0+k*p1)/(q0+k*q1) and p1/q1 is
0938: # closer to self. The distance between them is 1/(q1*(q0+k*q1)), while
0939: # the distance from p1/q1 to self is d/(q1*self._denominator). So we
0940: # need to compare 2*(q0+k*q1) with self._denominator/d.
+0941: 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, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_5 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_k, __pyx_v_q1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_v_q0, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_5 = __Pyx_PyNumber_Multiply_object_object(__pyx_t_3, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_1 = __Pyx_PyObject_CompareBoolLe_object_object(__pyx_t_5, __pyx_v_self->_denominator, Py_LE); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 941, __pyx_L1_error) __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (__pyx_t_1) { /* … */ }
+0942: return _fraction_from_coprime_ints(p1, q1)
__pyx_t_5 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_v_p1, __pyx_v_q1, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 942, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_5 = 0; goto __pyx_L0;
0943: else:
+0944: return _fraction_from_coprime_ints(p0+k*p1, q0+k*q1)
/*else*/ {
__pyx_t_5 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_k, __pyx_v_p1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_v_p0, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 944, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_k, __pyx_v_q1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_3 = __Pyx_PyNumber_Add_object_object(__pyx_v_q0, __pyx_t_5); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 944, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0;
__pyx_t_5 = __pyx_f_10quicktions__fraction_from_coprime_ints(__pyx_t_2, __pyx_t_3, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 944, __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;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_5;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_5 = 0;
goto __pyx_L0;
}
0945:
+0946: @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;
}
0947: def numerator(self):
+0948: return self._numerator
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_self->_numerator);
__pyx_r = __pyx_v_self->_numerator;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
0949:
+0950: @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;
}
0951: def denominator(self):
+0952: return self._denominator
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_self->_denominator);
__pyx_r = __pyx_v_self->_denominator;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
0953:
+0954: 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_7); __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; }
0955: """repr(self)"""
+0956: return '%s(%s, %s)' % (self.__class__.__name__,
__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, 956, __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, 956, __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, 956, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* … */ __pyx_t_5 = 4; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4[0]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4[2]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4[4]); #endif __pyx_t_6 = 0; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_6 |= __Pyx_PyUnicode_KIND_04(__pyx_t_4[0]) | __Pyx_PyUnicode_KIND_04(__pyx_t_4[2]) | __Pyx_PyUnicode_KIND_04(__pyx_t_4[4]); #endif __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_4, 6, __pyx_t_5, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 956, __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_DECREF(__pyx_t_3); __pyx_t_3 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_7; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_7 = 0; goto __pyx_L0;
+0957: 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, 957, __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, 957, __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__5; __pyx_t_4[2] = __pyx_t_2; __pyx_t_4[3] = __pyx_mstate_global->__pyx_kp_u__6; __pyx_t_4[4] = __pyx_t_3; __pyx_t_4[5] = __pyx_mstate_global->__pyx_kp_u__4;
0958:
+0959: 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_7); __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; }
0960: """str(self)"""
+0961: 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, 961, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+0962: return str(self._numerator)
__pyx_t_2 = __Pyx_PyObject_Unicode(__pyx_v_self->_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 962, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
0963: else:
+0964: return f'{self._numerator}/{self._denominator}'
/*else*/ {
__pyx_t_2 = __Pyx_PyObject_FormatSimple(__pyx_v_self->_numerator, __pyx_mstate_global->__pyx_empty_unicode); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 964, __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, 964, __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__7;
__pyx_t_4[2] = __pyx_t_3;
__pyx_t_5 = 1;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4[0]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4[2]);
#endif
__pyx_t_6 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_6 |= __Pyx_PyUnicode_KIND_04(__pyx_t_4[0]) | __Pyx_PyUnicode_KIND_04(__pyx_t_4[2]);
#endif
__pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_4, 3, __pyx_t_5, __pyx_t_6);
if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 964, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_7);
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_7;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_7 = 0;
goto __pyx_L0;
}
0965:
+0966: @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;
}
0967: cdef _format_general(self, dict match):
0968: """Helper method for __format__.
0969:
0970: Handles fill, alignment, signs, and thousands separators in the
0971: case of no presentation type.
0972: """
0973: # Validate and parse the format specifier.
+0974: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 974, __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, 974, __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, 974, __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__8);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__8;
__pyx_L3_bool_binop_done:;
__pyx_v_fill = __pyx_t_1;
__pyx_t_1 = 0;
+0975: cdef Py_UCS4 align = ord(match["align"] or ">")
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 975, __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, 975, __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, 975, __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__9);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__9;
__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, 975, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_align = __pyx_t_4;
+0976: pos_sign = "" if match["sign"] == "-" else match["sign"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 976, __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, 976, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = (__Pyx_PyObject_Equals_obj_ch45(__pyx_t_2, __pyx_mstate_global->__pyx_kp_u__10, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 976, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_3) {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__11);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__11;
} else {
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 976, __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, 976, __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;
+0977: cdef bint alternate_form = match["alt"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 977, __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, 977, __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, 977, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_alternate_form = __pyx_t_3;
+0978: cdef Py_ssize_t minimumwidth = int(match["minimumwidth"] or "0")
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 978, __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, 978, __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, 978, __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, 978, __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, 978, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_minimumwidth = __pyx_t_5;
+0979: thousands_sep = match["thousands_sep"] or ''
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 979, __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, 979, __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, 979, __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__11);
__pyx_t_2 = __pyx_mstate_global->__pyx_kp_u__11;
__pyx_L9_bool_binop_done:;
__pyx_v_thousands_sep = __pyx_t_2;
__pyx_t_2 = 0;
0980:
0981: cdef Py_ssize_t first_pos # Py2/3.5-only
0982:
0983: # Determine the body and sign representation.
+0984: 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;
+0985: if d > 1 or alternate_form:
__pyx_t_6 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_d, __pyx_mstate_global->__pyx_int_1, Py_GT); if (unlikely((__pyx_t_6 < 0))) __PYX_ERR(0, 985, __pyx_L1_error) 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; }
+0986: 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, 986, __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, 986, __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, 986, __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, 986, __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, 986, __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__7; __pyx_t_8[2] = __pyx_t_1; __pyx_t_5 = 1; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_5 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8[0]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_8[2]); #endif __pyx_t_9 = 0; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_9 |= __Pyx_PyUnicode_KIND_04(__pyx_t_8[0]) | __Pyx_PyUnicode_KIND_04(__pyx_t_8[2]); #endif __pyx_t_2 = __Pyx_PyUnicode_Join(__pyx_t_8, 3, __pyx_t_5, __pyx_t_9); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 986, __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;
0987: else:
+0988: body = f"{abs(n):{thousands_sep}}"
/*else*/ {
__pyx_t_2 = __Pyx_PyNumber_Absolute(__pyx_v_n); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 988, __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, 988, __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, 988, __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:;
+0989: sign = '-' if n < 0 else pos_sign
__pyx_t_3 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_n, __pyx_mstate_global->__pyx_int_0, Py_LT); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 989, __pyx_L1_error) if (__pyx_t_3) { __Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__10); __pyx_t_7 = __pyx_mstate_global->__pyx_kp_u__10; } else { __Pyx_INCREF(__pyx_v_pos_sign); __pyx_t_7 = __pyx_v_pos_sign; } __pyx_v_sign = __pyx_t_7; __pyx_t_7 = 0;
0990:
0991: # Pad with fill character if necessary and return.
+0992: 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, 992, __pyx_L1_error) __pyx_t_10 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_body); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 992, __pyx_L1_error) __pyx_t_7 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_5) - __pyx_t_10)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 992, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = __Pyx_PyNumber_Multiply_object_int(__pyx_v_fill, __pyx_t_7); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 992, __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;
+0993: if align == u">":
switch (__pyx_v_align) {
case 62:
/* … */
break;
case 60:
+0994: return padding + sign + body
__pyx_t_1 = __Pyx_PyNumber_Add_object_object(__pyx_v_padding, __pyx_v_sign); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 994, __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, 994, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_7; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_7 = 0; goto __pyx_L0;
+0995: elif align == u"<":
break;
case 94:
+0996: return sign + body + padding
__pyx_t_7 = PyNumber_Add(__pyx_v_sign, __pyx_v_body); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 996, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = __Pyx_PyNumber_Add_object_object(__pyx_t_7, __pyx_v_padding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 996, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
+0997: elif align == u"^":
break;
default:
+0998: half = len(padding) // 2
__pyx_t_10 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_10 == ((Py_ssize_t)-1))) __PYX_ERR(0, 998, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_10, 2, 1);
+0999: return padding[:half] + sign + body + padding[half:]
__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, 999, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = __Pyx_PyNumber_Add_object_object(__pyx_t_1, __pyx_v_sign); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 999, __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, 999, __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, 999, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_t_1, __pyx_t_7); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 999, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1000: else: # align == u"="
+1001: return sign + padding + body
__pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_v_sign, __pyx_v_padding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1001, __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, 1001, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_7; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_7 = 0; goto __pyx_L0; break; }
1002:
+1003: @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_8);
__Pyx_XDECREF(__pyx_t_13);
__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;
}
1004: cdef _format_float_style(self, dict match):
1005: """Helper method for __format__; handles float presentation types."""
+1006: fill = match["fill"] or " "
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1006, __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, 1006, __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, 1006, __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__8);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__8;
__pyx_L3_bool_binop_done:;
__pyx_v_fill = __pyx_t_1;
__pyx_t_1 = 0;
+1007: align = match["align"] or ">"
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1007, __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, 1007, __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, 1007, __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__9);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__9;
__pyx_L5_bool_binop_done:;
__pyx_v_align = __pyx_t_1;
__pyx_t_1 = 0;
+1008: pos_sign = "" if match["sign"] == "-" else match["sign"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1008, __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, 1008, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_3 = (__Pyx_PyObject_Equals_obj_ch45(__pyx_t_2, __pyx_mstate_global->__pyx_kp_u__10, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1008, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
if (__pyx_t_3) {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__11);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__11;
} else {
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1008, __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, 1008, __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;
+1009: cdef bint no_neg_zero = match["no_neg_zero"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1009, __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, 1009, __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, 1009, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_no_neg_zero = __pyx_t_3;
+1010: cdef bint alternate_form = match["alt"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1010, __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, 1010, __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, 1010, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_alternate_form = __pyx_t_3;
+1011: cdef bint zeropad = match["zeropad"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1011, __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, 1011, __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, 1011, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_zeropad = __pyx_t_3;
+1012: cdef Py_ssize_t minimumwidth = int(match["minimumwidth"] or "0")
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1012, __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, 1012, __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, 1012, __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, 1012, __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, 1012, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
__pyx_v_minimumwidth = __pyx_t_4;
+1013: thousands_sep = match["thousands_sep"]
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1013, __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, 1013, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_v_thousands_sep = __pyx_t_2;
__pyx_t_2 = 0;
+1014: cdef Py_ssize_t precision = int(match["precision"] or "6")
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1014, __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, 1014, __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, 1014, __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, 1014, __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, 1014, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_precision = __pyx_t_4;
+1015: cdef str frac_sep = match["frac_separators"] or ""
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1015, __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, 1015, __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, 1015, __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, 1015, __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__11);
__pyx_t_1 = __pyx_mstate_global->__pyx_kp_u__11;
__pyx_L11_bool_binop_done:;
__pyx_v_frac_sep = ((PyObject*)__pyx_t_1);
__pyx_t_1 = 0;
+1016: cdef Py_UCS4 presentation_type = ord(match["presentation_type"])
if (unlikely(__pyx_v_match == Py_None)) {
PyErr_SetString(PyExc_TypeError, "\047NoneType\047 object is not subscriptable");
__PYX_ERR(0, 1016, __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, 1016, __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, 1016, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
__pyx_v_presentation_type = __pyx_t_6;
+1017: 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;
}
if (__pyx_t_7) {
} else {
__pyx_t_3 = __pyx_t_7;
goto __pyx_L13_bool_binop_done;
}
__pyx_t_7 = (!__pyx_v_alternate_form);
__pyx_t_3 = __pyx_t_7;
__pyx_L13_bool_binop_done:;
__pyx_v_trim_zeros = __pyx_t_3;
+1018: cdef bint trim_point = not alternate_form
__pyx_v_trim_point = (!__pyx_v_alternate_form);
+1019: 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;
1020:
+1021: if align == '=' and fill == '0':
__pyx_t_7 = (__Pyx_PyObject_Equals_obj_ch61(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__12, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1021, __pyx_L1_error) if (__pyx_t_7) { } else { __pyx_t_3 = __pyx_t_7; goto __pyx_L16_bool_binop_done; } __pyx_t_7 = (__Pyx_PyObject_Equals_obj_ch48(__pyx_v_fill, __pyx_mstate_global->__pyx_kp_u_0_2, Py_EQ)); if (unlikely((__pyx_t_7 < 0))) __PYX_ERR(0, 1021, __pyx_L1_error) __pyx_t_3 = __pyx_t_7; __pyx_L16_bool_binop_done:; if (__pyx_t_3) { /* … */ }
+1022: zeropad = True
__pyx_v_zeropad = 1;
1023:
1024: cdef bint negative, scientific
1025: cdef Py_ssize_t exponent, figures
1026:
1027: # Round to get the digits we need, figure out where to place the point,
1028: # and decide whether to use scientific notation. 'point_pos' is the
1029: # relative to the _end_ of the digit string: that is, it's the number
1030: # of digits that should follow the point.
+1031: if presentation_type in u"fF%":
switch (__pyx_v_presentation_type) {
case 37:
case 70:
case 0x66:
/* … */
break;
default:
+1032: exponent = -precision
__pyx_v_exponent = (-__pyx_v_precision);
+1033: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37);
if (__pyx_t_3) {
/* … */
}
+1034: exponent -= 2
__pyx_v_exponent = (__pyx_v_exponent - 2);
+1035: negative, significand = _round_to_exponent(
__pyx_t_9.__pyx_n = 1;
__pyx_t_9.no_neg_zero = __pyx_v_no_neg_zero;
__pyx_t_8 = __pyx_f_10quicktions__round_to_exponent(__pyx_t_1, __pyx_t_2, __pyx_t_5, &__pyx_t_9); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1035, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__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_8))) || (PyList_CheckExact(__pyx_t_8))) {
PyObject* sequence = __pyx_t_8;
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, 1035, __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_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1035, __pyx_L1_error)
__Pyx_XGOTREF(__pyx_t_5);
__pyx_t_2 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference);
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1035, __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, 1035, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1035, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
#endif
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
} else {
Py_ssize_t index = -1;
__pyx_t_1 = PyObject_GetIter(__pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1035, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
__pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_1);
index = 0; __pyx_t_5 = __pyx_t_10(__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_10(__pyx_t_1); if (unlikely(!__pyx_t_2)) goto __pyx_L19_unpacking_failed;
__Pyx_GOTREF(__pyx_t_2);
if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_1), 2) < (0)) __PYX_ERR(0, 1035, __pyx_L1_error)
__pyx_t_10 = 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_10 = NULL;
if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index);
__PYX_ERR(0, 1035, __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, 1035, __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;
+1036: 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, 1036, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
+1037: scientific = False
__pyx_v_scientific = 0;
+1038: point_pos = precision
__pyx_t_8 = PyLong_FromSsize_t(__pyx_v_precision); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1038, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); if (__Pyx_PyInt_FromNumber(&__pyx_t_8, NULL, 0) < (0)) __PYX_ERR(0, 1038, __pyx_L1_error) __pyx_v_point_pos = ((PyObject*)__pyx_t_8); __pyx_t_8 = 0;
1039: else: # presentation_type in "eEgG"
1040: figures = (
+1041: max(precision, 1)
switch (__pyx_v_presentation_type) {
case 71:
/* … */
__pyx_t_6 = 1;
__pyx_t_11 = __pyx_v_precision;
__pyx_t_3 = (__pyx_t_6 > __pyx_t_11);
if (__pyx_t_3) {
__pyx_t_12 = __pyx_t_6;
} else {
__pyx_t_12 = __pyx_t_11;
}
__pyx_t_4 = __pyx_t_12;
break;
default:
+1042: if presentation_type in u"gG"
case 0x67:
+1043: else precision + 1
__pyx_t_4 = (__pyx_v_precision + 1);
break;
}
__pyx_v_figures = __pyx_t_4;
1044: )
+1045: negative, significand, exponent = _round_to_figures(
__pyx_t_5 = __pyx_f_10quicktions__round_to_figures(__pyx_t_8, __pyx_t_2, __pyx_v_figures); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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, 1045, __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_8 = PyTuple_GET_ITEM(sequence, 1); __Pyx_INCREF(__pyx_t_8); __pyx_t_1 = PyTuple_GET_ITEM(sequence, 2); __Pyx_INCREF(__pyx_t_1); } else { __pyx_t_2 = __Pyx_PyList_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1045, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_8 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1045, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_8); __pyx_t_1 = __Pyx_PyList_GET_ITEM_REF(sequence, 2, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1045, __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, 1045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_8 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1045, __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_13 = PyObject_GetIter(__pyx_t_5); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 1045, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_13); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_10 = (CYTHON_COMPILING_IN_LIMITED_API) ? PyIter_Next : __Pyx_PyObject_GetIterNextFunc(__pyx_t_13); index = 0; __pyx_t_2 = __pyx_t_10(__pyx_t_13); if (unlikely(!__pyx_t_2)) goto __pyx_L21_unpacking_failed; __Pyx_GOTREF(__pyx_t_2); index = 1; __pyx_t_8 = __pyx_t_10(__pyx_t_13); if (unlikely(!__pyx_t_8)) goto __pyx_L21_unpacking_failed; __Pyx_GOTREF(__pyx_t_8); index = 2; __pyx_t_1 = __pyx_t_10(__pyx_t_13); if (unlikely(!__pyx_t_1)) goto __pyx_L21_unpacking_failed; __Pyx_GOTREF(__pyx_t_1); if (__Pyx_IternextUnpackEndCheck(__pyx_t_10(__pyx_t_13), 3) < (0)) __PYX_ERR(0, 1045, __pyx_L1_error) __pyx_t_10 = NULL; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; goto __pyx_L22_unpacking_done; __pyx_L21_unpacking_failed:; __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; __pyx_t_10 = NULL; if (__Pyx_IterFinish() == 0) __Pyx_RaiseNeedMoreValuesError(index); __PYX_ERR(0, 1045, __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, 1045, __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, 1045, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_negative = __pyx_t_3; __pyx_v_significand = __pyx_t_8; __pyx_t_8 = 0; __pyx_v_exponent = __pyx_t_4;
+1046: self._numerator, self._denominator, figures)
__pyx_t_8 = __pyx_v_self->_numerator;
__Pyx_INCREF(__pyx_t_8);
__pyx_t_2 = __pyx_v_self->_denominator;
__Pyx_INCREF(__pyx_t_2);
1047: scientific = (
+1048: presentation_type in u"eE"
switch (__pyx_v_presentation_type) {
case 69:
case 0x65:
__pyx_t_7 = 1;
break;
default:
__pyx_t_7 = 0;
break;
}
if (!__pyx_t_7) {
} else {
__pyx_t_3 = __pyx_t_7;
goto __pyx_L23_bool_binop_done;
}
+1049: 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;
}
+1050: 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;
1051: )
+1052: 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, 1052, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyInt_FromNumber(&__pyx_t_1, NULL, 0) < (0)) __PYX_ERR(0, 1052, __pyx_L1_error)
__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, 1052, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyInt_FromNumber(&__pyx_t_1, NULL, 0) < (0)) __PYX_ERR(0, 1052, __pyx_L1_error)
__pyx_t_5 = __pyx_t_1;
__pyx_t_1 = 0;
}
__pyx_v_point_pos = ((PyObject*)__pyx_t_5);
__pyx_t_5 = 0;
break;
}
1053:
1054: # Get the suffix - the part following the digits, if any.
+1055: if presentation_type == u"%":
__pyx_t_3 = (__pyx_v_presentation_type == 37);
if (__pyx_t_3) {
/* … */
goto __pyx_L26;
}
+1056: suffix = "%"
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__13);
__pyx_v_suffix = __pyx_mstate_global->__pyx_kp_u__13;
+1057: elif scientific:
if (__pyx_v_scientific) {
/* … */
goto __pyx_L26;
}
1058: #suffix = f"{exponent_indicator}{exponent + point_pos:+03d}"
+1059: 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, 1059, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = __Pyx_PyNumber_Add_int_int(__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_5 = PyTuple_New(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1059, __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, 1059, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 1059, __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, 1059, __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;
1060: else:
+1061: suffix = ""
/*else*/ {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__11);
__pyx_v_suffix = __pyx_mstate_global->__pyx_kp_u__11;
}
__pyx_L26:;
1062:
1063: # String of output digits, padded sufficiently with zeros on the left
1064: # so that we'll have at least one digit before the decimal point.
+1065: 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, 1065, __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, 1065, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_14[0] = __pyx_mstate_global->__pyx_kp_u_0_2; __pyx_t_14[1] = __pyx_t_5; __pyx_t_14[2] = __pyx_mstate_global->__pyx_n_u_d; __pyx_t_4 = 2; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_4 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14[1]); #endif __pyx_t_15 = 0; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_15 |= __Pyx_PyUnicode_KIND_04(__pyx_t_14[1]); #endif __pyx_t_1 = __Pyx_PyUnicode_Join(__pyx_t_14, 3, __pyx_t_4, __pyx_t_15); 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_t_5 = __Pyx_PyObject_Format(__pyx_v_significand, __pyx_t_1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1065, __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;
1066:
1067: # Before padding, the output has the form f"{sign}{leading}{trailing}",
1068: # where `leading` includes thousands separators if necessary and
1069: # `trailing` includes the decimal separator where appropriate.
+1070: sign = "-" if negative else pos_sign
if (__pyx_v_negative) {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__10);
__pyx_t_5 = __pyx_mstate_global->__pyx_kp_u__10;
} else {
__Pyx_INCREF(__pyx_v_pos_sign);
__pyx_t_5 = __pyx_v_pos_sign;
}
__pyx_v_sign = __pyx_t_5;
__pyx_t_5 = 0;
+1071: 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, 1071, __pyx_L1_error) __pyx_t_5 = PyLong_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1071, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = __Pyx_PyNumber_Subtract_int_int(__pyx_t_5, __pyx_v_point_pos); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1071, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __pyx_t_3 = (__pyx_t_1 == ((PyObject*)Py_None)); if (__pyx_t_3) { __pyx_t_4 = PY_SSIZE_T_MAX; } else { __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_1); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1071, __pyx_L1_error) __pyx_t_4 = __pyx_t_12; } __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, 1071, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_leading = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1072: 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, 1072, __pyx_L1_error) __pyx_t_1 = PyLong_FromSsize_t(__pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1072, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_5 = __Pyx_PyNumber_Subtract_int_int(__pyx_t_1, __pyx_v_point_pos); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1072, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_3 = (__pyx_t_5 == ((PyObject*)Py_None)); if (__pyx_t_3) { __pyx_t_4 = 0; } else { __pyx_t_12 = __Pyx_PyIndex_AsSsize_t(__pyx_t_5); if (unlikely((__pyx_t_12 == (Py_ssize_t)-1) && PyErr_Occurred())) __PYX_ERR(0, 1072, __pyx_L1_error) __pyx_t_4 = __pyx_t_12; } __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, 1072, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_v_frac_part = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0;
+1073: if trim_zeros:
if (__pyx_v_trim_zeros) {
/* … */
}
+1074: 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, 1074, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (!(likely(PyUnicode_CheckExact(__pyx_t_5)) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_5))) __PYX_ERR(0, 1074, __pyx_L1_error) __Pyx_DECREF_SET(__pyx_v_frac_part, ((PyObject*)__pyx_t_5)); __pyx_t_5 = 0;
+1075: 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, 1075, __pyx_L1_error)
__pyx_t_7 = (__pyx_temp != 0);
}
__pyx_t_16 = (!__pyx_t_7);
__pyx_t_3 = __pyx_t_16;
__pyx_L28_bool_binop_done:;
if (__pyx_t_3) {
__Pyx_INCREF(__pyx_mstate_global->__pyx_kp_u__11);
__pyx_t_5 = __pyx_mstate_global->__pyx_kp_u__11;
} 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;
+1076: 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, 1076, __pyx_L1_error)
__pyx_t_3 = (__pyx_temp != 0);
}
if (__pyx_t_3) {
/* … */
}
+1077: frac_part = frac_sep.join([
if (unlikely(__pyx_v_frac_sep == Py_None)) {
PyErr_Format(PyExc_AttributeError, "\047NoneType\047 object has no attribute \047%.30s\047", "join");
__PYX_ERR(0, 1077, __pyx_L1_error)
}
{ /* enter inner scope */
__pyx_t_5 = PyList_New(0); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1077, __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, 1077, __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;
+1078: 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, 1078, __pyx_L1_error) __pyx_t_12 = __pyx_t_4; for (__pyx_t_11 = 0; __pyx_t_11 < __pyx_t_12; __pyx_t_11+=3) { __pyx_7genexpr__pyx_v_pos = __pyx_t_11; __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, 1078, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); if (unlikely(__Pyx_ListComp_AppendAndDecref(__pyx_t_5, __pyx_t_1))) __PYX_ERR(0, 1077, __pyx_L1_error) __pyx_t_1 = 0; } } /* exit inner scope */
1079: ])
+1080: 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, 1080, __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, 1080, __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;
1081:
1082: # Do zero padding if required.
+1083: if zeropad:
if (__pyx_v_zeropad) {
/* … */
}
+1084: 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, 1084, __pyx_L1_error) __pyx_t_12 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_trailing); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1084, __pyx_L1_error) __pyx_t_5 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_4) - __pyx_t_12)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1084, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); if (__Pyx_PyInt_FromNumber(&__pyx_t_5, NULL, 0) < (0)) __PYX_ERR(0, 1084, __pyx_L1_error) __pyx_v_min_leading = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0;
1085: # When adding thousands separators, they'll be added to the
1086: # zero-padded portion too, so we need to compensate.
+1087: 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, 1087, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; if (!(likely(PyUnicode_CheckExact(__pyx_t_1)) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_1))) __PYX_ERR(0, 1087, __pyx_L1_error) __Pyx_DECREF_SET(__pyx_v_leading, ((PyObject*)__pyx_t_1)); __pyx_t_1 = 0;
+1088: 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, 1088, __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, 1088, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = __Pyx_PyLong_FloorDivideObjC(__pyx_t_1, __pyx_mstate_global->__pyx_int_4, 4, 0, 0); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1088, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyLong_AddObjC(__pyx_t_8, __pyx_mstate_global->__pyx_int_1, 1, 0, 0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1088, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 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; }
1089: )
1090:
1091: # Insert thousands separators if required.
+1092: if thousands_sep:
__pyx_t_3 = __Pyx_PyObject_IsTrue(__pyx_v_thousands_sep); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1092, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+1093: first_pos = 1 + (len(leading) - 1) % 3
__pyx_t_12 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_leading); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1093, __pyx_L1_error) __pyx_v_first_pos = (1 + __Pyx_mod_Py_ssize_t((__pyx_t_12 - 1), 3, 1));
+1094: 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, 1094, __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, 1094, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); /* … */ __pyx_t_2 = PyUnicode_Join(__pyx_mstate_global->__pyx_kp_u__11, __pyx_t_5); 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_t_5 = __Pyx_PyUnicode_Concat__Pyx_ReferenceSharing_OwnStrongReferenceInPlace(__pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1094, __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;
+1095: thousands_sep + leading[pos : pos + 3]
__pyx_t_8 = __Pyx_PyUnicode_Substring(__pyx_v_leading, __pyx_8genexpr1__pyx_v_pos, (__pyx_8genexpr1__pyx_v_pos + 3)); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1095, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = PyNumber_Add(__pyx_v_thousands_sep, __pyx_t_8); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1095, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_GIVEREF(__pyx_t_2); if (unlikely(__Pyx_ListComp_AppendAndDecref(__pyx_t_5, __pyx_t_2))) __PYX_ERR(0, 1094, __pyx_L1_error) __pyx_t_2 = 0; } } /* exit inner scope */
+1096: for pos in range(first_pos, len(leading), 3)
__pyx_t_12 = __Pyx_PyUnicode_GET_LENGTH(__pyx_v_leading); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1096, __pyx_L1_error) __pyx_t_4 = __pyx_t_12; for (__pyx_t_11 = __pyx_v_first_pos; __pyx_t_11 < __pyx_t_4; __pyx_t_11+=3) { __pyx_8genexpr1__pyx_v_pos = __pyx_t_11;
1097: ])
1098:
1099: # We now have a sign and a body. Pad with fill character if necessary
1100: # and return.
+1101: body = leading + trailing
__pyx_t_5 = __Pyx_PyUnicode_Concat(__pyx_v_leading, __pyx_v_trailing); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_v_body = ((PyObject*)__pyx_t_5); __pyx_t_5 = 0;
+1102: padding = fill * (minimumwidth - len(sign) - len(body))
__pyx_t_12 = PyObject_Length(__pyx_v_sign); if (unlikely(__pyx_t_12 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1102, __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, 1102, __pyx_L1_error) __pyx_t_5 = PyLong_FromSsize_t(((__pyx_v_minimumwidth - __pyx_t_12) - __pyx_t_4)); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1102, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_PyNumber_Multiply_object_int(__pyx_v_fill, __pyx_t_5); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1102, __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;
+1103: if align == ">":
__pyx_t_3 = (__Pyx_PyObject_Equals_obj_ch62(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__9, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1103, __pyx_L1_error)
if (__pyx_t_3) {
/* … */
}
+1104: return padding + sign + body
__pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_v_padding, __pyx_v_sign); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1104, __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, 1104, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_5 = 0; goto __pyx_L0;
+1105: elif align == "<":
__pyx_t_3 = (__Pyx_PyObject_Equals_obj_ch60(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__14, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1105, __pyx_L1_error)
if (__pyx_t_3) {
/* … */
}
+1106: return sign + body + padding
__pyx_t_5 = PyNumber_Add(__pyx_v_sign, __pyx_v_body); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_t_5, __pyx_v_padding); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1106, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1107: elif align == "^":
__pyx_t_3 = (__Pyx_PyObject_Equals_obj_ch94(__pyx_v_align, __pyx_mstate_global->__pyx_kp_u__15, Py_EQ)); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1107, __pyx_L1_error)
if (__pyx_t_3) {
/* … */
}
+1108: half = len(padding) // 2
__pyx_t_4 = PyObject_Length(__pyx_v_padding); if (unlikely(__pyx_t_4 == ((Py_ssize_t)-1))) __PYX_ERR(0, 1108, __pyx_L1_error) __pyx_v_half = __Pyx_div_Py_ssize_t(__pyx_t_4, 2, 1);
+1109: return padding[:half] + sign + body + padding[half:]
__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, 1109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = __Pyx_PyNumber_Add_object_object(__pyx_t_2, __pyx_v_sign); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1109, __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, 1109, __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, 1109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_1 = __Pyx_PyNumber_Add_object_object(__pyx_t_2, __pyx_t_5); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1109, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
1110: else: # align == "="
+1111: return sign + padding + body
/*else*/ {
__pyx_t_1 = __Pyx_PyNumber_Add_object_object(__pyx_v_sign, __pyx_v_padding); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1111, __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, 1111, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_5;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_5 = 0;
goto __pyx_L0;
}
1112:
+1113: 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, 1113, __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, 1113, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1114: """Format this fraction according to the given format specification."""
1115:
+1116: 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, 1116, __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, 1116, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_5) { /* … */ }
+1117: return self._format_general(match.groupdict())
__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, 1117, __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, 1117, __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, 1117, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_3;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_3 = 0;
goto __pyx_L0;
1118:
+1119: 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, 1119, __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, 1119, __pyx_L1_error) __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (__pyx_t_5) { /* … */ }
1120: # Refuse the temptation to guess if both alignment _and_
1121: # zero padding are specified.
+1122: 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, 1122, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
}
__pyx_v_match_groups = __pyx_t_3;
__pyx_t_3 = 0;
+1123: 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, 1123, __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, 1123, __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) { /* … */ }
+1124: return self._format_float_style(match_groups)
__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, 1124, __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, 1124, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
1125:
+1126: raise ValueError(
__pyx_t_3 = NULL;
+1127: 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, 1127, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); /* … */ __pyx_t_10 = 45; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_10 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9[1]) + __Pyx_PyUnicode_GET_LENGTH(__pyx_t_9[3]); #endif __pyx_t_11 = 0; #if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH __pyx_t_11 |= __Pyx_PyUnicode_KIND_04(__pyx_t_9[1]) | __Pyx_PyUnicode_KIND_04(__pyx_t_9[3]); #endif __pyx_t_7 = __Pyx_PyUnicode_Join(__pyx_t_9, 4, __pyx_t_10, __pyx_t_11); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1127, __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, 1126, __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, 1126, __pyx_L1_error)
+1128: 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, 1128, __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, 1128, __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;
1129: )
1130:
+1131: 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; }
1132: """a + b"""
+1133: return forward(a, b, _add, _math_op_add)
__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, 1133, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1134:
+1135: 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; }
1136: """a + b"""
+1137: return reverse(a, b, _add, _math_op_add)
__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, 1137, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1138:
+1139: 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; }
1140: """a - b"""
+1141: return forward(a, b, _sub, _math_op_sub)
__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, 1141, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1142:
+1143: 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; }
1144: """a - b"""
+1145: return reverse(a, b, _sub, _math_op_sub)
__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, 1145, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1146:
+1147: 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; }
1148: """a * b"""
+1149: return forward(a, b, _mul, _math_op_mul)
__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, 1149, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1150:
+1151: 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; }
1152: """a * b"""
+1153: return reverse(a, b, _mul, _math_op_mul)
__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, 1153, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1154:
+1155: def __div__(a, b):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_33__div__(PyObject *__pyx_v_a, #if CYTHON_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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, 1155, __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, 1155, __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, 1155, __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, 1155, __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, 1155, __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, 1155, __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, 1155, __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, 1155, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1156: """a / b"""
+1157: return forward(a, b, _div, _math_op_div)
__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, 1157, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1158:
+1159: def __rdiv__(b, a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_35__rdiv__(PyObject *__pyx_v_b, #if CYTHON_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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, 1159, __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, 1159, __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, 1159, __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, 1159, __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, 1159, __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, 1159, __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, 1159, __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, 1159, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1160: """a / b"""
+1161: return reverse(a, b, _div, _math_op_div)
__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, 1161, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1162:
+1163: 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; }
1164: """a / b"""
+1165: return forward(a, b, _div, _math_op_truediv)
__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, 1165, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1166:
+1167: 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; }
1168: """a / b"""
+1169: return reverse(a, b, _div, _math_op_truediv)
__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, 1169, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1170:
+1171: 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; }
1172: """a // b"""
+1173: return forward(a, b, _floordiv, _math_op_floordiv, handle_complex=False)
__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, 1173, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1174:
+1175: 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; }
1176: """a // b"""
+1177: return reverse(a, b, _floordiv, _math_op_floordiv, handle_complex=False)
__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, 1177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1178:
+1179: 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; }
1180: """a % b"""
+1181: return forward(a, b, _mod, _math_op_mod, handle_complex=False)
__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, 1181, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1182:
+1183: 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; }
1184: """a % b"""
+1185: return reverse(a, b, _mod, _math_op_mod, handle_complex=False)
__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, 1185, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1186:
+1187: 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; }
1188: """divmod(self, other): The pair (self // other, self % other).
1189:
1190: Sometimes this can be computed faster than the pair of
1191: operations.
1192: """
+1193: return forward(a, b, _divmod, _math_op_divmod, handle_complex=False)
__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, 1193, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1194:
+1195: 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; }
1196: """divmod(self, other): The pair (self // other, self % other).
1197:
1198: Sometimes this can be computed faster than the pair of
1199: operations.
1200: """
+1201: return reverse(a, b, _divmod, _math_op_divmod, handle_complex=False)
__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, 1201, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1202:
+1203: 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; }
1204: """a ** b
1205:
1206: If b is not an integer, the result will be a float or complex
1207: since roots are generally irrational. If b is an integer, the
1208: result will be rational.
1209: """
+1210: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None);
if (__pyx_t_1) {
/* … */
}
+1211: return NotImplemented
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1212:
+1213: if isinstance(b, int):
__pyx_t_1 = PyLong_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1214: return _pow(a.numerator, a.denominator, b, 1)
__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, 1214, __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, 1214, __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, 1214, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
+1215: 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) { /* … */ }
+1216: return _pow(a.numerator, a.denominator, b.numerator, b.denominator)
__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, 1216, __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, 1216, __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, 1216, __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, 1216, __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, 1216, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_7; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_7 = 0; goto __pyx_L0;
+1217: 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) { /* … */ }
+1218: return (a.numerator / a.denominator) ** b
__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, 1218, __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, 1218, __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, 1218, __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, 1218, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_6; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_6 = 0; goto __pyx_L0;
1219: else:
+1220: return NotImplemented
/*else*/ {
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
}
1221:
+1222: 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; }
1223: """a ** b
1224:
1225: If b is not an integer, the result will be a float or complex
1226: since roots are generally irrational. If b is an integer, the
1227: result will be rational.
1228: """
+1229: if x is not None:
__pyx_t_1 = (__pyx_v_x != Py_None);
if (__pyx_t_1) {
/* … */
}
+1230: return NotImplemented
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1231:
+1232: 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, 1232, __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, 1232, __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;
+1233: 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, 1233, __pyx_L1_error) if (__pyx_t_4) { } else { __pyx_t_1 = __pyx_t_4; goto __pyx_L5_bool_binop_done; } __pyx_t_4 = __Pyx_PyObject_CompareBoolGe_object_int(__pyx_v_bn, __pyx_mstate_global->__pyx_int_0, Py_GE); if (unlikely((__pyx_t_4 < 0))) __PYX_ERR(0, 1233, __pyx_L1_error) __pyx_t_1 = __pyx_t_4; __pyx_L5_bool_binop_done:; if (__pyx_t_1) { /* … */ }
1234: # If a is an int, keep it that way if possible.
+1235: return a ** bn
__pyx_t_3 = PyNumber_Power(__pyx_v_a, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1235, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1236:
+1237: if isinstance(a, int):
__pyx_t_1 = PyLong_Check(__pyx_v_a);
if (__pyx_t_1) {
/* … */
}
+1238: return _pow(a, 1, bn, bd)
__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, 1238, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
+1239: 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) { /* … */ }
+1240: return _pow(a.numerator, a.denominator, bn, bd)
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1240, __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, 1240, __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, 1240, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_5 = 0; goto __pyx_L0;
1241:
+1242: 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, 1242, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1243: return a ** bn
__pyx_t_5 = PyNumber_Power(__pyx_v_a, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1243, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_5; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_5 = 0; goto __pyx_L0;
1244:
+1245: return a ** (bn / bd)
__pyx_t_5 = __Pyx_PyNumber_Divide(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1245, __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, 1245, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1246:
+1247: 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; }
1248: """+a: Coerces a subclass instance to Fraction"""
+1249: 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) {
/* … */
}
+1250: return a
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF((PyObject *)__pyx_v_a);
__pyx_r = ((PyObject *)__pyx_v_a);
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
+1251: return _fraction_from_coprime_ints(a._numerator, a._denominator)
__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, 1251, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
1252:
+1253: 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; }
1254: """-a"""
+1255: return _fraction_from_coprime_ints(-a._numerator, a._denominator)
__pyx_t_1 = PyNumber_Negative(__pyx_v_a->_numerator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1255, __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, 1255, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1256:
+1257: 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; }
1258: """abs(a)"""
+1259: return _fraction_from_coprime_ints(abs(a._numerator), a._denominator)
__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, 1259, __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, 1259, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1260:
+1261: 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_2); __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; }
1262: """int(a)"""
+1263: if a._numerator < 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_a->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1263, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1264: return _operator_index(-(-a._numerator // a._denominator))
__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, 1264, __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, 1264, __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, 1264, __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_2 = __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_2)) __PYX_ERR(0, 1264, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
1265: else:
+1266: return _operator_index(a._numerator // a._denominator)
/*else*/ {
__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, 1266, __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_2 = __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_2)) __PYX_ERR(0, 1266, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
}
1267:
+1268: def __trunc__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_65__trunc__(PyObject *__pyx_v_a, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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_2); __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, 1268, __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, 1268, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1269: """math.trunc(a)"""
+1270: if a._numerator < 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_a->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1270, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1271: return -(-a._numerator // a._denominator)
__pyx_t_2 = PyNumber_Negative(__pyx_v_a->_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = PyNumber_FloorDivide(__pyx_t_2, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyNumber_Negative(__pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1271, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1272: else:
+1273: return a._numerator // a._denominator
/*else*/ {
__pyx_t_2 = PyNumber_FloorDivide(__pyx_v_a->_numerator, __pyx_v_a->_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1273, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
}
1274:
+1275: def __floor__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_67__floor__(PyObject *__pyx_v_a, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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, 1275, __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, 1275, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1276: """math.floor(a)"""
+1277: return a.numerator // a.denominator
__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, 1277, __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, 1277, __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, 1277, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1278:
+1279: def __ceil__(a):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_69__ceil__(PyObject *__pyx_v_a, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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, 1279, __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, 1279, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1280: """math.ceil(a)"""
1281: # The negations cleverly convince floordiv to return the ceiling.
+1282: return -(-a.numerator // a.denominator)
__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, 1282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyNumber_Negative(__pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1282, __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, 1282, __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, 1282, __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, 1282, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
1283:
+1284: def __round__(self, ndigits=None):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_71__round__(PyObject *__pyx_v_self, #if CYTHON_VECTORCALL 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_VECTORCALL 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_VECTORCALL 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_VECTORCALL #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, 1284, __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, 1284, __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, 1284, __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, 1284, __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, 1284, __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, 1284, __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, 1284, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; /* … */ { PyObject* __pyx_temp[1] = {Py_None}; __pyx_mstate_global->__pyx_tuple[1] = __Pyx_PyTuple_FromArray(__pyx_temp, 1); if (unlikely(!__pyx_mstate_global->__pyx_tuple[1])) __PYX_ERR(0, 1284, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_tuple[1]); } __Pyx_GIVEREF(__pyx_mstate_global->__pyx_tuple[1]);
1285: """round(self, ndigits)
1286:
1287: Rounds half toward even.
1288: """
+1289: if ndigits is None:
__pyx_t_1 = (__pyx_v_ndigits == Py_None);
if (__pyx_t_1) {
/* … */
}
+1290: 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, 1290, __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, 1290, __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, 1290, __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, 1290, __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_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1290, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1290, __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, 1290, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1290, __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, 1290, __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, 1290, __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, 1290, __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;
+1291: 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, 1291, __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, 1291, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyObject_CompareBoolLt_object_object(__pyx_t_4, __pyx_t_2, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1291, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1292: return floor
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_floor);
__pyx_r = __pyx_v_floor;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
+1293: elif remainder * 2 > self.denominator:
__pyx_t_2 = __Pyx_PyLong_MultiplyObjC(__pyx_v_remainder, __pyx_mstate_global->__pyx_int_2, 2, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_mstate_global->__pyx_n_u_denominator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1293, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_1 = __Pyx_PyObject_CompareBoolGt_object_object(__pyx_t_2, __pyx_t_4, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1293, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1294: return floor + 1
__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, 1294, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
1295: # Deal with the half case:
+1296: 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, 1296, __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, 1296, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_1) { /* … */ }
+1297: return floor
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_floor);
__pyx_r = __pyx_v_floor;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1298: else:
+1299: return floor + 1
/*else*/ {
__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, 1299, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
}
+1300: 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, 1300, __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, 1300, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_shift = __pyx_t_4; __pyx_t_4 = 0;
1301: # See _operator_fallbacks.forward to check that the results of
1302: # these operations will always be Fraction and therefore have
1303: # round().
+1304: if ndigits > 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_ndigits, __pyx_mstate_global->__pyx_int_0, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1304, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1305: return Fraction(round(self * shift), shift)
__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, 1305, __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, 1305, __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, 1305, __pyx_L1_error)
__Pyx_GOTREF((PyObject *)__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = ((PyObject *)__pyx_t_4);
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
1306: else:
+1307: return Fraction(round(self / shift) * shift)
/*else*/ {
__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, 1307, __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, 1307, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
__pyx_t_5 = __Pyx_PyNumber_Multiply_object_object(__pyx_t_2, __pyx_v_shift); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1307, __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, 1307, __pyx_L1_error)
__Pyx_GOTREF((PyObject *)__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = ((PyObject *)__pyx_t_4);
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
}
1308:
+1309: 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\047s important that this conversion use the integer\047s \"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; }
1310: """float(self) = self.numerator / self.denominator
1311:
1312: It's important that this conversion use the integer's "true"
1313: division rather than casting one side to float before dividing
1314: so that ratios of huge integers convert without overflowing.
1315: """
+1316: return _as_float(self.numerator, self.denominator)
__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, 1316, __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, 1316, __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, 1316, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1317:
1318: # Concrete implementations of Complex abstract methods.
+1319: def __complex__(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_75__complex__(PyObject *__pyx_v_self, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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, 1319, __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, 1319, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1320: """complex(self) == complex(float(self), 0)"""
+1321: return complex(float(self))
__pyx_t_2 = NULL; __pyx_t_3 = __Pyx_PyNumber_Float(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1321, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); if (__Pyx_PyFloat_FromNumber(&__pyx_t_3, NULL, 0) < (0)) __PYX_ERR(0, 1321, __pyx_L1_error) __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, 1321, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
1322:
1323: # == +self
+1324: 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, 1324, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_10 = 1; { PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_t_2, __pyx_mstate_global->__pyx_kp_u_Real_numbers_are_their_real_comp}; #if CYTHON_VECTORCALL __pyx_t_8 = __pyx_mstate_global->__pyx_tuple[2]; if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1324, __pyx_L1_error) __Pyx_INCREF(__pyx_t_8); #else { PyObject *__pyx_temp[1] = {__pyx_mstate_global->__pyx_n_u_doc}; __pyx_t_8 = __Pyx_MakeKwargDict(__pyx_temp, __pyx_callargs+2, 1); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1324, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); } #endif __pyx_t_9 = __Pyx_Object_VectorcallKwds((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, 1324, __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, 1324, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1325:
1326: # == 0
+1327: @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;
}
1328: def imag(self):
1329: "Real numbers have no imaginary component."
+1330: return 0
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_mstate_global->__pyx_int_0);
__pyx_r = __pyx_mstate_global->__pyx_int_0;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1331:
+1332: def conjugate(self):
/* Python wrapper */ static PyObject *__pyx_pw_10quicktions_8Fraction_77conjugate(PyObject *__pyx_v_self, #if CYTHON_VECTORCALL 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_VECTORCALL PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds #else PyObject *__pyx_args, PyObject *__pyx_kwds #endif ) { #if !CYTHON_VECTORCALL 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_VECTORCALL #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, 1332, __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, 1332, __pyx_L1_error) __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1333: """Conjugate is a no-op for Reals."""
+1334: return +self
__pyx_t_1 = PyNumber_Positive(((PyObject *)__pyx_v_self)); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1334, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
1335:
+1336: 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; }
1337: """hash(self)"""
+1338: if self._hash != -1:
__pyx_t_1 = (__pyx_v_self->_hash != -1L);
if (__pyx_t_1) {
/* … */
}
+1339: return self._hash
{
__pyx_r = __pyx_v_self->_hash;
}
goto __pyx_L0;
1340:
1341: cdef Py_hash_t result
1342:
1343: # In order to make sure that the hash of a Fraction agrees
1344: # with the hash of a numerically equal integer, float or
1345: # Decimal instance, we follow the rules for numeric hashes
1346: # outlined in the documentation. (See library docs, 'Built-in
1347: # Types').
1348:
+1349: 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:;
}
+1350: 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, 1350, __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, 1350, __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;
+1351: except ValueError:
__pyx_t_9 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(((PyTypeObject*)PyExc_ValueError)))); if (__pyx_t_9) { __Pyx_ErrRestore(0,0,0);
1352: # ValueError means there is no modular inverse.
+1353: result = _PyHASH_INF
__pyx_v_result = __pyx_v_10quicktions__PyHASH_INF;
goto __pyx_L5_exception_handled;
}
goto __pyx_L6_except_error;
1354: else:
1355: # The general algorithm now specifies that the absolute value of
1356: # the hash is
1357: # (|N| * dinv) % P
1358: # where N is self._numerator and P is _PyHASH_MODULUS. That's
1359: # optimized here in two ways: first, for a non-negative int i,
1360: # hash(i) == i % P, but the int hash implementation doesn't need
1361: # to divide, and is faster than doing % P explicitly. So we do
1362: # hash(|N| * dinv)
1363: # instead. Second, N is unbounded, so its product with dinv may
1364: # be arbitrarily expensive to compute. The final answer is the
1365: # same if we use the bounded |N| % P instead, which can again
1366: # be done with an int hash() call. If 0 <= i < P, hash(i) == i,
1367: # so this nested hash() call wastes a bit of time making a
1368: # redundant copy when |N| < P, but can save an arbitrarily large
1369: # amount of computation for large |N|.
+1370: 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, 1370, __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, 1370, __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, 1370, __pyx_L6_except_error)
__Pyx_GOTREF(__pyx_t_6);
__pyx_t_7 = __Pyx_PyNumber_Multiply_int_object(__pyx_t_6, __pyx_v_dinv); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 1370, __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, 1370, __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;
1371:
+1372: if self._numerator < 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_self->_numerator, __pyx_mstate_global->__pyx_int_0, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1372, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1373: result = -result
__pyx_v_result = (-__pyx_v_result);
+1374: if result == -1:
__pyx_t_1 = (__pyx_v_result == -1L);
if (__pyx_t_1) {
/* … */
}
+1375: result = -2
__pyx_v_result = -2L;
+1376: self._hash = result
__pyx_v_self->_hash = __pyx_v_result;
+1377: return result
{
__pyx_r = __pyx_v_result;
}
goto __pyx_L0;
1378:
+1379: 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;
}
+1380: 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;
}
+1381: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ);
if (__pyx_t_1) {
/* … */
}
+1382: return (<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, 1382, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1383: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE);
if (__pyx_t_1) {
/* … */
}
+1384: 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, 1384, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_result = __pyx_t_2; __pyx_t_2 = 0;
+1385: return NotImplemented if result is NotImplemented else not result
__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, 1385, __pyx_L1_error)
__pyx_t_4 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1385, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
__pyx_t_2 = __pyx_t_4;
__pyx_t_4 = 0;
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
1386: else:
+1387: 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, 1387, __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;
+1388: if op == Py_EQ:
__pyx_t_1 = (__pyx_v_op == Py_EQ);
if (__pyx_t_1) {
/* … */
}
+1389: return (<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, 1389, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
+1390: elif op == Py_NE:
__pyx_t_1 = (__pyx_v_op == Py_NE);
if (__pyx_t_1) {
/* … */
}
+1391: 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, 1391, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_v_result = __pyx_t_4; __pyx_t_4 = 0;
+1392: return NotImplemented if result is NotImplemented else not result
__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, 1392, __pyx_L1_error)
__pyx_t_2 = __Pyx_PyBool_FromLong((!__pyx_t_3)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1392, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__pyx_t_4 = __pyx_t_2;
__pyx_t_2 = 0;
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
+1393: elif op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1394: op = Py_GE
__pyx_v_op = Py_GE;
+1395: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1396: op = Py_LE
__pyx_v_op = Py_LE;
+1397: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1398: op = Py_GT
__pyx_v_op = Py_GT;
+1399: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE);
if (__pyx_t_1) {
/* … */
goto __pyx_L5;
}
+1400: op = Py_LT
__pyx_v_op = Py_LT;
1401: else:
+1402: return NotImplemented
/*else*/ {
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
}
__pyx_L5:;
}
__pyx_L3:;
+1403: return (<Fraction>a)._richcmp(b, op)
__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, 1403, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
1404:
+1405: @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;
}
1406: cdef _eq(a, b):
+1407: if type(b) is int:
__pyx_t_1 = (((PyObject *)Py_TYPE(__pyx_v_b)) == ((PyObject *)(&PyLong_Type)));
if (__pyx_t_1) {
/* … */
}
+1408: return a._numerator == b and a._denominator == 1
__pyx_t_3 = __Pyx_PyObject_CompareEq_object_object(__pyx_v_a->_numerator, __pyx_v_b, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1408, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1408, __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, 1408, __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:; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1409: 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) {
/* … */
}
+1410: return (a._numerator == (<Fraction>b)._numerator and
__pyx_t_3 = __Pyx_PyObject_CompareEq_object_object(__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, 1410, __pyx_L1_error) __pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_t_3); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1410, __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; }
+1411: a._denominator == (<Fraction>b)._denominator)
__pyx_t_3 = __Pyx_PyObject_CompareEq_object_object(__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, 1411, __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:; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1412: 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, 1412, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_1) { /* … */ }
+1413: return (a._numerator == b.numerator and
__pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1413, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyObject_CompareEq_object_object(__pyx_v_a->_numerator, __pyx_t_3, Py_EQ); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1413, __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, 1413, __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; }
+1414: 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, 1414, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_3 = __Pyx_PyObject_CompareEq_object_object(__pyx_v_a->_denominator, __pyx_t_4, Py_EQ); __Pyx_XGOTREF(__pyx_t_3); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1414, __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:; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1415: 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, 1415, __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, 1415, __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, 1415, __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) { /* … */ }
+1416: 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, 1416, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_b, __pyx_t_2); __pyx_t_2 = 0;
+1417: if isinstance(b, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_1) {
/* … */
}
+1418: 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, 1418, __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, 1418, __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, 1418, __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, 1418, __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) {
/* … */
}
1419: # comparisons with an infinity or nan should behave in
1420: # the same way for any finite a, so treat a as zero.
+1421: return 0.0 == b
__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, 1421, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1422: else:
+1423: return a == a.from_float(b)
/*else*/ {
__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, 1423, __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, 1423, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_3;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_3 = 0;
goto __pyx_L0;
}
+1424: return NotImplemented
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1425:
+1426: @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;
}
1427: cdef _richcmp(self, other, int op):
1428: """Helper for comparison operators, for internal use only.
1429:
1430: Implement comparison between a Rational instance `self`, and
1431: either another Rational instance or a float `other`. If
1432: `other` is not a Rational instance or a float, return
1433: NotImplemented. `op` should be one of the six standard
1434: comparison operators.
1435:
1436: """
1437: # convert other to a Rational instance where reasonable.
+1438: if isinstance(other, int):
__pyx_t_1 = PyLong_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1439: 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;
+1440: b = self._denominator * other
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_self->_denominator, __pyx_v_other); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1440, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
+1441: 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;
}
+1442: a = self._numerator * (<Fraction>other)._denominator
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_self->_numerator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_other)->_denominator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1442, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_a = __pyx_t_2; __pyx_t_2 = 0;
+1443: b = self._denominator * (<Fraction>other)._numerator
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_self->_denominator, ((struct __pyx_obj_10quicktions_Fraction *)__pyx_v_other)->_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1443, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_v_b = __pyx_t_2; __pyx_t_2 = 0;
+1444: elif isinstance(other, float):
__pyx_t_1 = PyFloat_Check(__pyx_v_other);
if (__pyx_t_1) {
/* … */
goto __pyx_L3;
}
+1445: 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, 1445, __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, 1445, __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, 1445, __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, 1445, __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;
}
+1446: 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;
1447: else:
+1448: return self._richcmp(self.from_float(other), op)
/*else*/ {
__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, 1448, __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, 1448, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
}
__pyx_L4:;
+1449: 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; }
+1450: 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, 1450, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_self->_numerator, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1450, __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;
+1451: 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, 1451, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_self->_denominator, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1451, __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;
1452: else:
1453: # comparisons with complex should raise a TypeError, for consistency
1454: # with int<->complex, float<->complex, and complex<->complex comparisons.
+1455: return NotImplemented
/*else*/ {
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
}
__pyx_L3:;
1456:
+1457: if op == Py_LT:
__pyx_t_1 = (__pyx_v_op == Py_LT);
if (__pyx_t_1) {
/* … */
}
+1458: return a < b
__pyx_t_2 = __Pyx_PyObject_CompareLt_object_object(__pyx_v_a, __pyx_v_b, Py_LT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1458, __pyx_L1_error) { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1459: elif op == Py_GT:
__pyx_t_1 = (__pyx_v_op == Py_GT);
if (__pyx_t_1) {
/* … */
}
+1460: return a > b
__pyx_t_2 = __Pyx_PyObject_CompareGt_object_object(__pyx_v_a, __pyx_v_b, Py_GT); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1460, __pyx_L1_error) { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1461: elif op == Py_LE:
__pyx_t_1 = (__pyx_v_op == Py_LE);
if (__pyx_t_1) {
/* … */
}
+1462: return a <= b
__pyx_t_2 = __Pyx_PyObject_CompareLe_object_object(__pyx_v_a, __pyx_v_b, Py_LE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1462, __pyx_L1_error) { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1463: elif op == Py_GE:
__pyx_t_1 = (__pyx_v_op == Py_GE);
if (__pyx_t_1) {
/* … */
}
+1464: return a >= b
__pyx_t_2 = __Pyx_PyObject_CompareGe_object_object(__pyx_v_a, __pyx_v_b, Py_GE); __Pyx_XGOTREF(__pyx_t_2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1464, __pyx_L1_error) { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1465: else:
+1466: return NotImplemented
/*else*/ {
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
}
1467:
+1468: 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;
}
1469: """a != 0"""
1470: # Use bool() because (a._numerator != 0) can return an
1471: # object which is not a bool.
1472: # See https://bugs.python.org/issue39274
+1473: return bool(self._numerator)
__pyx_t_1 = __Pyx_PyObject_IsTrue(__pyx_v_self->_numerator); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1473, __pyx_L1_error) { __pyx_r = (!(!__pyx_t_1)); } goto __pyx_L0;
1474:
1475: # support for pickling, copy, and deepcopy
1476:
+1477: def __reduce__(self):
/* Python wrapper */
static PyObject *__pyx_pw_10quicktions_8Fraction_85__reduce__(PyObject *__pyx_v_self,
#if CYTHON_VECTORCALL
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_VECTORCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
#if !CYTHON_VECTORCALL
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_VECTORCALL
#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, 1477, __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, 1477, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+1478: return (type(self), (self._numerator, self._denominator))
__pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1478, __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, 1478, __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, 1478, __pyx_L1_error); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1478, __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, 1478, __pyx_L1_error); __Pyx_GIVEREF(__pyx_t_1); if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_1) != (0)) __PYX_ERR(0, 1478, __pyx_L1_error); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1479:
+1480: def __copy__(self):
/* Python wrapper */
static PyObject *__pyx_pw_10quicktions_8Fraction_87__copy__(PyObject *__pyx_v_self,
#if CYTHON_VECTORCALL
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_VECTORCALL
PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds
#else
PyObject *__pyx_args, PyObject *__pyx_kwds
#endif
) {
#if !CYTHON_VECTORCALL
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_VECTORCALL
#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, 1480, __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, 1480, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+1481: 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) {
/* … */
}
+1482: return self # I'm immutable; therefore I am my own clone
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF((PyObject *)__pyx_v_self);
__pyx_r = ((PyObject *)__pyx_v_self);
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
+1483: return type(self)(self._numerator, self._denominator)
__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, 1483, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1484:
+1485: def __deepcopy__(self, memo):
/* Python wrapper */
static PyObject *__pyx_pw_10quicktions_8Fraction_89__deepcopy__(PyObject *__pyx_v_self,
#if CYTHON_VECTORCALL
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_VECTORCALL
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_VECTORCALL
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_VECTORCALL
#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, 1485, __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, 1485, __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, 1485, __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, 1485, __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, 1485, __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, 1485, __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, 1485, __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, 1485, __pyx_L1_error)
__Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
+1486: 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) {
/* … */
}
+1487: return self # My components are also immutable
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF((PyObject *)__pyx_v_self);
__pyx_r = ((PyObject *)__pyx_v_self);
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
+1488: return type(self)(self._numerator, self._denominator)
__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, 1488, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1489:
1490:
1491: # Register with Python's numerical tower.
+1492: 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, 1492, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); } __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0;
1493:
1494:
+1495: 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;
};
1496: """Convert a pair of ints to a rational number, for internal use.
1497:
1498: The ratio of integers should be in lowest terms and the denominator
1499: should be positive.
1500: """
1501: cdef Fraction obj
+1502: 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;
}
+1503: obj = Fraction.__new__(Fraction, NOINIT, NOINIT)
__pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1503, __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, 1503, __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, 1503, __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, 1503, __pyx_L1_error) __Pyx_GOTREF(__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;
1504: else:
+1505: 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, 1505, __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, 1505, __pyx_L1_error)
__pyx_v_obj = ((struct __pyx_obj_10quicktions_Fraction *)__pyx_t_4);
__pyx_t_4 = 0;
}
__pyx_L3:;
+1506: 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;
+1507: 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;
+1508: return obj
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF((PyObject *)__pyx_v_obj);
__pyx_r = ((PyObject *)__pyx_v_obj);
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1509:
1510:
+1511: 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;
}
+1512: 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, 1512, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
1513: # power = bn
+1514: if bn >= 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolGe_object_int(__pyx_v_bn, __pyx_mstate_global->__pyx_int_0, Py_GE); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1514, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1515: return _fraction_from_coprime_ints(
__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, 1515, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
+1516: an ** bn,
__pyx_t_2 = PyNumber_Power(__pyx_v_an, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1516, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2);
+1517: ad ** bn)
__pyx_t_3 = PyNumber_Power(__pyx_v_ad, __pyx_v_bn, Py_None); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1517, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3);
+1518: elif an > 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_an, __pyx_mstate_global->__pyx_int_0, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1518, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1519: return _fraction_from_coprime_ints(
__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, 1519, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
+1520: ad ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1520, __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, 1520, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1521: an ** -bn)
__pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1521, __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, 1521, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
+1522: 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, 1522, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1523: 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, 1523, __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, 1523, __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, 1523, __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_7 = 13;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_7 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6[1]);
#endif
__pyx_t_8 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_8 |= __Pyx_PyUnicode_KIND_04(__pyx_t_6[1]);
#endif
__pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_6, 3, __pyx_t_7, __pyx_t_8);
if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1523, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
__pyx_t_9 = 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_9, (2-__pyx_t_9) | (__pyx_t_9*__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, 1523, __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, 1523, __pyx_L1_error)
1524: else:
+1525: return _fraction_from_coprime_ints(
/*else*/ {
/* … */
__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, 1525, __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;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
}
+1526: (-ad) ** -bn,
__pyx_t_4 = PyNumber_Negative(__pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1526, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); __pyx_t_5 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1526, __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, 1526, __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;
+1527: (-an) ** -bn)
__pyx_t_5 = PyNumber_Negative(__pyx_v_an); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 1527, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_5); __pyx_t_4 = PyNumber_Negative(__pyx_v_bn); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1527, __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, 1527, __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;
1528: else:
1529: # A fractional power will generally produce an
1530: # irrational number.
+1531: return (an / ad) ** (bn / bd)
/*else*/ {
__pyx_t_4 = __Pyx_PyNumber_Divide(__pyx_v_an, __pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1531, __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, 1531, __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, 1531, __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;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
}
1532:
1533:
+1534: 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;
}
+1535: return numerator / denominator
__pyx_t_1 = __Pyx_PyNumber_Divide(__pyx_v_numerator, __pyx_v_denominator); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1535, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
1536:
1537:
1538: # Rational arithmetic algorithms: Knuth, TAOCP, Volume 2, 4.5.1.
1539: #
1540: # Assume input fractions a and b are normalized.
1541: #
1542: # 1) Consider addition/subtraction.
1543: #
1544: # Let g = gcd(da, db). Then
1545: #
1546: # na nb na*db ± nb*da
1547: # a ± b == -- ± -- == ------------- ==
1548: # da db da*db
1549: #
1550: # na*(db//g) ± nb*(da//g) t
1551: # == ----------------------- == -
1552: # (da*db)//g d
1553: #
1554: # Now, if g > 1, we're working with smaller integers.
1555: #
1556: # Note, that t, (da//g) and (db//g) are pairwise coprime.
1557: #
1558: # Indeed, (da//g) and (db//g) share no common factors (they were
1559: # removed) and da is coprime with na (since input fractions are
1560: # normalized), hence (da//g) and na are coprime. By symmetry,
1561: # (db//g) and nb are coprime too. Then,
1562: #
1563: # gcd(t, da//g) == gcd(na*(db//g), da//g) == 1
1564: # gcd(t, db//g) == gcd(nb*(da//g), db//g) == 1
1565: #
1566: # Above allows us optimize reduction of the result to lowest
1567: # terms. Indeed,
1568: #
1569: # g2 = gcd(t, d) == gcd(t, (da//g)*(db//g)*g) == gcd(t, g)
1570: #
1571: # t//g2 t//g2
1572: # a ± b == ----------------------- == ----------------
1573: # (da//g)*(db//g)*(g//g2) (da//g)*(db//g2)
1574: #
1575: # is a normalized fraction. This is useful because the unnormalized
1576: # denominator d could be much larger than g.
1577: #
1578: # We should special-case g == 1 (and g2 == 1), since 60.8% of
1579: # randomly-chosen integers are coprime:
1580: # https://en.wikipedia.org/wiki/Coprime_integers#Probability_of_coprimality
1581: # Note, that g2 == 1 always for fractions, obtained from floats: here
1582: # g is a power of 2 and the unnormalized numerator t is an odd integer.
1583: #
1584: # 2) Consider multiplication
1585: #
1586: # Let g1 = gcd(na, db) and g2 = gcd(nb, da), then
1587: #
1588: # na*nb na*nb (na//g1)*(nb//g2)
1589: # a*b == ----- == ----- == -----------------
1590: # da*db db*da (db//g1)*(da//g2)
1591: #
1592: # Note, that after divisions we're multiplying smaller integers.
1593: #
1594: # Also, the resulting fraction is normalized, because each of
1595: # two factors in the numerator is coprime to each of the two factors
1596: # in the denominator.
1597: #
1598: # Indeed, pick (na//g1). It's coprime with (da//g2), because input
1599: # fractions are normalized. It's also coprime with (db//g1), because
1600: # common factors are removed by g1 == gcd(na, db).
1601: #
1602: # As for addition/subtraction, we should special-case g1 == 1
1603: # and g2 == 1 for same reason. That happens also for multiplying
1604: # rationals, obtained from floats.
1605:
+1606: 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;
}
1607: """a + b"""
1608: # return Fraction(na * db + nb * da, da * db)
+1609: 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, 1609, __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, 1609, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1610: 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, 1610, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1611: return _fraction_from_coprime_ints(na * db + da * nb, da * db)
__pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_na, __pyx_v_db); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_da, __pyx_v_nb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1611, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1611, __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 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_da, __pyx_v_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1611, __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, 1611, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
+1612: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1612, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1613: 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, 1613, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_na, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1613, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_nb, __pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1613, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyNumber_Add_object_object(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1613, __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;
+1614: 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, 1614, __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, 1614, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1615: 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, 1615, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1616: return _fraction_from_coprime_ints(t, s * db)
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_s, __pyx_v_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1616, __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, 1616, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
+1617: return _fraction_from_coprime_ints(t // g2, s * (db // g2))
__pyx_t_3 = PyNumber_FloorDivide(__pyx_v_t, __pyx_v_g2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1617, __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, 1617, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_s, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1617, __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, 1617, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1618:
+1619: 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;
}
1620: """a - b"""
1621: # return Fraction(na * db - nb * da, da * db)
+1622: 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, 1622, __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, 1622, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g = __pyx_t_1; __pyx_t_1 = 0;
+1623: 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, 1623, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1624: return _fraction_from_coprime_ints(na * db - da * nb, da * db)
__pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_na, __pyx_v_db); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1624, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_da, __pyx_v_nb); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1624, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_2 = __Pyx_PyNumber_Subtract_object_object(__pyx_t_1, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1624, __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 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_da, __pyx_v_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1624, __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, 1624, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_1; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
+1625: s = da // g
__pyx_t_1 = PyNumber_FloorDivide(__pyx_v_da, __pyx_v_g); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1625, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_s = __pyx_t_1; __pyx_t_1 = 0;
+1626: 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, 1626, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_na, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1626, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_nb, __pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1626, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyNumber_Subtract_object_object(__pyx_t_3, __pyx_t_1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1626, __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;
+1627: 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, 1627, __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, 1627, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1628: 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, 1628, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1629: return _fraction_from_coprime_ints(t, s * db)
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_s, __pyx_v_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1629, __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, 1629, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
+1630: return _fraction_from_coprime_ints(t // g2, s * (db // g2))
__pyx_t_3 = PyNumber_FloorDivide(__pyx_v_t, __pyx_v_g2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1630, __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, 1630, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_s, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1630, __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, 1630, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1631:
+1632: 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;
}
1633: """a * b"""
1634: # return Fraction(na * nb, da * db)
+1635: 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, 1635, __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, 1635, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g1 = __pyx_t_1; __pyx_t_1 = 0;
+1636: if g1 > 1:
__pyx_t_5 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_g1, __pyx_mstate_global->__pyx_int_1, Py_GT); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1636, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1637: na //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1637, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_1); __pyx_t_1 = 0;
+1638: db //= g1
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1638, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_1); __pyx_t_1 = 0;
+1639: 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, 1639, __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, 1639, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); } __pyx_v_g2 = __pyx_t_1; __pyx_t_1 = 0;
+1640: if g2 > 1:
__pyx_t_5 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, Py_GT); if (unlikely((__pyx_t_5 < 0))) __PYX_ERR(0, 1640, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+1641: nb //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1641, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_1); __pyx_t_1 = 0;
+1642: da //= g2
__pyx_t_1 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1642, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_1); __pyx_t_1 = 0;
+1643: return _fraction_from_coprime_ints(na * nb, db * da)
__pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_na, __pyx_v_nb); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1643, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_db, __pyx_v_da); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1643, __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, 1643, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1644:
+1645: 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_8);
__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;
}
1646: """a / b"""
1647: # return Fraction(na * db, da * nb)
1648: # Same as _mul(), with inversed b.
+1649: 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, 1649, __pyx_L1_error) if (unlikely(__pyx_t_1)) { /* … */ }
+1650: 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, 1650, __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 = 13;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_6 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5[1]);
#endif
__pyx_t_7 = 0;
#if __Pyx_PyUnicode_Join_CAN_USE_KIND_AND_LENGTH
__pyx_t_7 |= __Pyx_PyUnicode_KIND_04(__pyx_t_5[1]);
#endif
__pyx_t_8 = __Pyx_PyUnicode_Join(__pyx_t_5, 3, __pyx_t_6, __pyx_t_7);
if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1650, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_8);
__Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0;
__pyx_t_9 = 1;
{
PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_t_8};
__pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)(((PyTypeObject*)PyExc_ZeroDivisionError)), __pyx_callargs+__pyx_t_9, (2-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET));
__Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0;
__Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1650, __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, 1650, __pyx_L1_error)
+1651: g1 = _gcd(na, nb)
__pyx_t_8 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1651, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_3))) { __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_3); assert(__pyx_t_8); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_3); __Pyx_INCREF(__pyx_t_8); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_3, __pyx__function); __pyx_t_9 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_v_na, __pyx_v_nb}; __pyx_t_2 = __Pyx_PyObject_FastCall((PyObject*)__pyx_t_3, __pyx_callargs+__pyx_t_9, (3-__pyx_t_9) | (__pyx_t_9*__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)); __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1651, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g1 = __pyx_t_2; __pyx_t_2 = 0;
+1652: if g1 > 1:
__pyx_t_1 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_g1, __pyx_mstate_global->__pyx_int_1, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1652, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1653: na //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_na, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1653, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_na, __pyx_t_2); __pyx_t_2 = 0;
+1654: nb //= g1
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_nb, __pyx_v_g1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1654, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_nb, __pyx_t_2); __pyx_t_2 = 0;
+1655: g2 = _gcd(db, da)
__pyx_t_3 = NULL; __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_mstate_global->__pyx_n_u_gcd); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_9 = 1; #if CYTHON_UNPACK_METHODS if (unlikely(PyMethod_Check(__pyx_t_8))) { __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_8); assert(__pyx_t_3); PyObject* __pyx__function = PyMethod_GET_FUNCTION(__pyx_t_8); __Pyx_INCREF(__pyx_t_3); __Pyx_INCREF(__pyx__function); __Pyx_DECREF_SET(__pyx_t_8, __pyx__function); __pyx_t_9 = 0; } #endif { PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_v_db, __pyx_v_da}; __pyx_t_2 = __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_3); __pyx_t_3 = 0; __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1655, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); } __pyx_v_g2 = __pyx_t_2; __pyx_t_2 = 0;
+1656: if g2 > 1:
__pyx_t_1 = __Pyx_PyObject_CompareBoolGt_object_int(__pyx_v_g2, __pyx_mstate_global->__pyx_int_1, Py_GT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1656, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1657: da //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_da, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1657, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_da, __pyx_t_2); __pyx_t_2 = 0;
+1658: db //= g2
__pyx_t_2 = PyNumber_InPlaceFloorDivide(__pyx_v_db, __pyx_v_g2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1658, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_db, __pyx_t_2); __pyx_t_2 = 0;
+1659: n, d = na * db, nb * da
__pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_na, __pyx_v_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_8 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_nb, __pyx_v_da); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1659, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_v_n = __pyx_t_2; __pyx_t_2 = 0; __pyx_v_d = __pyx_t_8; __pyx_t_8 = 0;
+1660: if d < 0:
__pyx_t_1 = __Pyx_PyObject_CompareBoolLt_object_int(__pyx_v_d, __pyx_mstate_global->__pyx_int_0, Py_LT); if (unlikely((__pyx_t_1 < 0))) __PYX_ERR(0, 1660, __pyx_L1_error) if (__pyx_t_1) { /* … */ }
+1661: n, d = -n, -d
__pyx_t_8 = PyNumber_Negative(__pyx_v_n); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 1661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_2 = PyNumber_Negative(__pyx_v_d); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1661, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF_SET(__pyx_v_n, __pyx_t_8); __pyx_t_8 = 0; __Pyx_DECREF_SET(__pyx_v_d, __pyx_t_2); __pyx_t_2 = 0;
+1662: return _fraction_from_coprime_ints(n, d)
__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, 1662, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1663:
+1664: 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;
}
1665: """a // b -> int"""
+1666: return (an * bd) // (bn * ad)
__pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1666, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_bn, __pyx_v_ad); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1666, __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, 1666, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_3; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
1667:
+1668: 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;
}
+1669: div, n_mod = divmod(an * bd, ad * bn)
__pyx_t_1 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1669, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_ad, __pyx_v_bn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1669, __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, 1669, __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, 1669, __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_GET_ITEM_REF(sequence, 0, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1669, __pyx_L1_error) __Pyx_XGOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PyList_GET_ITEM_REF(sequence, 1, __Pyx_ReferenceSharing_SharedReference); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1669, __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, 1669, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = __Pyx_PySequence_ITEM(sequence, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1669, __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, 1669, __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, 1669, __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, 1669, __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;
+1670: return div, Fraction(n_mod, ad * bd)
__pyx_t_1 = NULL; __pyx_t_2 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1670, __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, 1670, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_3); } __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1670, __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, 1670, __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, 1670, __pyx_L1_error); __pyx_t_3 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
1671:
+1672: 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;
}
+1673: return Fraction((an * bd) % (bn * ad), ad * bd)
__pyx_t_2 = NULL; __pyx_t_3 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_an, __pyx_v_bd); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1673, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_4 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_bn, __pyx_v_ad); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1673, __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, 1673, __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 = __Pyx_PyNumber_Multiply_object_object(__pyx_v_ad, __pyx_v_bd); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1673, __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, 1673, __pyx_L1_error) __Pyx_GOTREF((PyObject *)__pyx_t_1); } { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = ((PyObject *)__pyx_t_1); } __Pyx_XDECREF(__pyx_temp); } __pyx_t_1 = 0; goto __pyx_L0;
1674:
1675:
1676: """
1677: In general, we want to implement the arithmetic operations so
1678: that mixed-mode operations either call an implementation whose
1679: author knew about the types of both arguments, or convert both
1680: to the nearest built in type and do the operation there. In
1681: Fraction, that means that we define __add__ and __radd__ as:
1682:
1683: def __add__(self, other):
1684: # Both types have numerators/denominator attributes,
1685: # so do the operation directly
1686: if isinstance(other, (int, Fraction)):
1687: return Fraction(self.numerator * other.denominator +
1688: other.numerator * self.denominator,
1689: self.denominator * other.denominator)
1690: # float and complex don't have those operations, but we
1691: # know about those types, so special case them.
1692: elif isinstance(other, float):
1693: return float(self) + other
1694: elif isinstance(other, complex):
1695: return complex(self) + other
1696: # Let the other type take over.
1697: return NotImplemented
1698:
1699: def __radd__(self, other):
1700: # radd handles more types than add because there's
1701: # nothing left to fall back to.
1702: if isinstance(other, Rational):
1703: return Fraction(self.numerator * other.denominator +
1704: other.numerator * self.denominator,
1705: self.denominator * other.denominator)
1706: elif isinstance(other, Real):
1707: return float(other) + float(self)
1708: elif isinstance(other, Complex):
1709: return complex(other) + complex(self)
1710: return NotImplemented
1711:
1712:
1713: There are 5 different cases for a mixed-type addition on
1714: Fraction. I'll refer to all of the above code that doesn't
1715: refer to Fraction, float, or complex as "boilerplate". 'r'
1716: will be an instance of Fraction, which is a subtype of
1717: Rational (r : Fraction <: Rational), and b : B <:
1718: Complex. The first three involve 'r + b':
1719:
1720: 1. If B <: Fraction, int, float, or complex, we handle
1721: that specially, and all is well.
1722: 2. If Fraction falls back to the boilerplate code, and it
1723: were to return a value from __add__, we'd miss the
1724: possibility that B defines a more intelligent __radd__,
1725: so the boilerplate should return NotImplemented from
1726: __add__. In particular, we don't handle Rational
1727: here, even though we could get an exact answer, in case
1728: the other type wants to do something special.
1729: 3. If B <: Fraction, Python tries B.__radd__ before
1730: Fraction.__add__. This is ok, because it was
1731: implemented with knowledge of Fraction, so it can
1732: handle those instances before delegating to Real or
1733: Complex.
1734:
1735: The next two situations describe 'b + r'. We assume that b
1736: didn't know about Fraction in its implementation, and that it
1737: uses similar boilerplate code:
1738:
1739: 4. If B <: Rational, then __radd_ converts both to the
1740: builtin rational type (hey look, that's us) and
1741: proceeds.
1742: 5. Otherwise, __radd__ tries to find the nearest common
1743: base ABC, and fall back to its builtin type. Since this
1744: class doesn't subclass a concrete type, there's no
1745: implementation to fall back to, so we need to try as
1746: hard as possible to return an actual value, or the user
1747: will get a TypeError.
1748: """
1749:
1750: cdef:
+1751: _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, 1751, __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;
+1752: _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, 1752, __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;
+1753: _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, 1753, __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;
+1754: _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, 1754, __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, 1754, __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;
+1755: _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, 1755, __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;
+1756: _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, 1756, __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;
+1757: _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, 1757, __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;
+1758: _math_op_divmod = divmod
__pyx_t_2 = __Pyx_GetBuiltinName(__pyx_mstate_global->__pyx_n_u_divmod); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1758, __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;
1759:
1760:
+1761: ctypedef object (*math_func)(an, ad, bn, bd)
typedef PyObject *(*__pyx_t_10quicktions_math_func)(PyObject *, PyObject *, PyObject *, PyObject *);
1762:
1763:
+1764: 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;
};
+1765: 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;
+1766: 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) {
/* … */
}
+1767: return monomorphic_operator(an, ad, (<Fraction>b)._numerator, (<Fraction>b)._denominator)
__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, 1767, __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;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
+1768: elif isinstance(b, int):
__pyx_t_3 = PyLong_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1769: return monomorphic_operator(an, ad, b, 1)
__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, 1769, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_4); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
+1770: elif isinstance(b, Fraction):
__pyx_t_3 = __Pyx_TypeCheck(__pyx_v_b, __pyx_mstate_global->__pyx_ptype_10quicktions_Fraction);
if (__pyx_t_3) {
/* … */
}
+1771: return monomorphic_operator(an, ad, b.numerator, b.denominator)
__pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_b, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 1771, __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, 1771, __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, 1771, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1772: elif isinstance(b, float):
__pyx_t_3 = PyFloat_Check(__pyx_v_b);
if (__pyx_t_3) {
/* … */
}
+1773: return pyoperator(_as_float(an, ad), b)
__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, 1773, __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, 1773, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
+1774: 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, 1774, __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) { /* … */ }
+1775: return pyoperator(float(a), b)
__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, 1775, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyFloat_FromNumber(&__pyx_t_1, NULL, 0) < (0)) __PYX_ERR(0, 1775, __pyx_L1_error)
__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, 1775, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_2);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_2;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_2 = 0;
goto __pyx_L0;
1776: else:
+1777: return NotImplemented
/*else*/ {
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
}
1778:
1779:
+1780: 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;
};
+1781: 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;
+1782: if isinstance(a, int):
__pyx_t_3 = PyLong_Check(__pyx_v_a);
if (__pyx_t_3) {
/* … */
}
+1783: return monomorphic_operator(a, 1, bn, bd)
__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, 1783, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_2); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_2; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_2 = 0; goto __pyx_L0;
+1784: 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, 1784, __pyx_L1_error) __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (__pyx_t_3) { /* … */ }
+1785: return monomorphic_operator(a.numerator, a.denominator, bn, bd)
__pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_v_a, __pyx_mstate_global->__pyx_n_u_numerator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1785, __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, 1785, __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, 1785, __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; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = __pyx_t_4; } __Pyx_XDECREF(__pyx_temp); } __pyx_t_4 = 0; goto __pyx_L0;
+1786: 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, 1786, __pyx_L1_error) __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; if (__pyx_t_3) { /* … */ }
+1787: return pyoperator(float(a), _as_float(bn, bd))
__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, 1787, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_5);
if (__Pyx_PyFloat_FromNumber(&__pyx_t_5, NULL, 0) < (0)) __PYX_ERR(0, 1787, __pyx_L1_error)
__pyx_t_6 = __pyx_f_10quicktions__as_float(__pyx_v_bn, __pyx_v_bd); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 1787, __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, 1787, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
+1788: 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, 1788, __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, 1788, __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) { /* … */ }
+1789: return pyoperator(complex(a), float(b))
__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, 1789, __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, 1789, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
if (__Pyx_PyFloat_FromNumber(&__pyx_t_1, NULL, 0) < (0)) __PYX_ERR(0, 1789, __pyx_L1_error)
__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, 1789, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_4);
}
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = __pyx_t_4;
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_4 = 0;
goto __pyx_L0;
1790: else:
+1791: return NotImplemented
/*else*/ {
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_builtin_NotImplemented);
__pyx_r = __pyx_builtin_NotImplemented;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
}
1792:
1793:
+1794: ctypedef char* charptr
typedef char *__pyx_t_10quicktions_charptr;
1795:
1796: ctypedef fused AnyString:
1797: unicode
1798: charptr
1799:
1800:
+1801: 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
};
1802: BEGIN_SPACE # '\s'* -> (BEGIN_SIGN, SMALL_NUM, START_DECIMAL_DOT)
1803: BEGIN_SIGN # [+-] -> (SMALL_NUM, SMALL_DECIMAL_DOT)
1804: SMALL_NUM # [0-9]+ -> (SMALL_NUM, SMALL_NUM_US, NUM, NUM_SPACE, SMALL_DECIMAL_DOT, EXP_E, DENOM_START)
1805: SMALL_NUM_US # '_' -> (SMALL_NUM, NUM)
1806: NUM # [0-9]+ -> (NUM, NUM_US, NUM_SPACE, DECIMAL_DOT, EXP_E, DENOM_START)
1807: NUM_US # '_' -> (NUM)
1808: NUM_SPACE # '\s'+ -> (DENOM_START)
1809:
1810: # 1) floating point syntax
1811: START_DECIMAL_DOT # '.' -> (SMALL_DECIMAL)
1812: SMALL_DECIMAL_DOT # '.' -> (SMALL_DECIMAL, EXP_E, SMALL_END_SPACE)
1813: DECIMAL_DOT # '.' -> (DECIMAL, EXP_E, END_SPACE)
1814: SMALL_DECIMAL # [0-9]+ -> (SMALL_DECIMAL, SMALL_DECIMAL_US, DECIMAL, EXP_E, SMALL_END_SPACE)
1815: SMALL_DECIMAL_US # '_' -> (SMALL_DECIMAL, DECIMAL)
1816: DECIMAL # [0-9]+ -> (DECIMAL, DECIMAL_US, EXP_E, END_SPACE)
1817: DECIMAL_US # '_' -> (DECIMAL)
1818: EXP_E # [eE] -> (EXP_SIGN, EXP)
1819: EXP_SIGN # [+-] -> (EXP)
1820: EXP # [0-9]+ -> (EXP_US, END_SPACE)
1821: EXP_US # '_' -> (EXP)
1822: END_SPACE # '\s'+
1823: SMALL_END_SPACE # '\s'+
1824:
1825: # 2) "NOM / DENOM" syntax
1826: DENOM_START # '/' -> (DENOM_SIGN, SMALL_DENOM)
1827: DENOM_SIGN # [+-] -> (SMALL_DENOM)
1828: SMALL_DENOM # [0-9]+ -> (SMALL_DENOM, SMALL_DENOM_US, DENOM, DENOM_SPACE)
1829: SMALL_DENOM_US # '_' -> (SMALL_DENOM)
1830: DENOM # [0-9]+ -> (DENOM, DENOM_US, DENOM_SPACE)
1831: DENOM_US # '_' -> (DENOM)
1832: DENOM_SPACE # '\s'+
1833:
1834:
+1835: 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;
}
+1836: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1836, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1837: 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, 1837, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_3 = __Pyx_PyObject_CompareBoolEq_object_str(__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_b_2, Py_EQ); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1837, __pyx_L1_error) if (!__pyx_t_3) { } else { __pyx_t_2 = __pyx_t_3; goto __pyx_L4_bool_binop_done; } __pyx_t_3 = __Pyx_PyObject_CompareBoolEq_object_str(__pyx_t_1, __pyx_mstate_global->__pyx_kp_u_b_3, Py_EQ); if (unlikely((__pyx_t_3 < 0))) __PYX_ERR(0, 1837, __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, 1837, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[0]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[0]); /* … */ }
+1838: 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, 1838, __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, 1838, __pyx_L1_error) __Pyx_GOTREF(__pyx_mstate_global->__pyx_slice[1]); __Pyx_GIVEREF(__pyx_mstate_global->__pyx_slice[1]);
+1839: 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, 1839, __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, 1839, __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, 1839, __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, 1839, __pyx_L1_error)
1840:
1841:
+1842: 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;
}
+1843: s = repr(s)
__pyx_t_1 = PyObject_Repr(__pyx_v_s); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1843, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1844: if s[0] == 'b':
__pyx_t_1 = __Pyx_GetItemInt(__pyx_v_s, 0, long, 1, __Pyx_PyLong_From_long, 0, 1, 1, __Pyx_ReferenceSharing_FunctionArgument); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1844, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = (__Pyx_PyObject_Equals_obj_ch98(__pyx_t_1, __pyx_mstate_global->__pyx_n_u_b, Py_EQ)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 1844, __pyx_L1_error) __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_2) { /* … */ }
+1845: 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, 1845, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_s, __pyx_t_1); __pyx_t_1 = 0;
+1846: 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, 1846, __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, 1846, __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, 1846, __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, 1846, __pyx_L1_error)
1847:
1848:
1849: cdef extern from *:
1850: """
1851: static CYTHON_INLINE int __QUICKTIONS_to_decimal(Py_UCS4 digit) {
1852: #if CYTHON_COMPILING_IN_LIMITED_API
1853: #include "todecimal.h"
1854: #else
1855: return Py_UNICODE_TODECIMAL(digit);
1856: #endif
1857: }
1858:
1859: static CYTHON_INLINE int __QUICKTIONS_unpack_ustring(
1860: PyObject* string, Py_ssize_t *length, void** data, int *kind) {
1861: #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030c0000
1862: if (PyUnicode_READY(string) < 0) return -1;
1863: #endif
1864: *kind = __Pyx_PyUnicode_KIND(string);
1865: *length = __Pyx_PyUnicode_GET_LENGTH(string);
1866:
1867: #if CYTHON_COMPILING_IN_LIMITED_API
1868: *data = (void*) string;
1869: #else
1870: *data = __Pyx_PyUnicode_DATA(string);
1871: #endif
1872:
1873: return 0;
1874: }
1875:
1876: #if CYTHON_COMPILING_IN_LIMITED_API
1877: #define __QUICKTIONS_char_at(data, kind, index) (Py_UCS4) (((void)kind), PyUnicode_ReadChar(data, index))
1878: #else
1879: #define __QUICKTIONS_char_at(data, kind, index) \
1880: (((kind == 1) ? (Py_UCS4) ((char*) data)[index] : (Py_UCS4) PyUnicode_READ(kind, data, index)))
1881: #endif
1882: """
1883: int _unpack_ustring "__QUICKTIONS_unpack_ustring" (
1884: object string, Py_ssize_t *length, void **data, int *kind) except -1
1885: Py_UCS4 _char_at "__QUICKTIONS_char_at" (void *data, int kind, Py_ssize_t index)
1886: int _to_decimal "__QUICKTIONS_to_decimal" (Py_UCS4 c)
1887:
1888:
+1889: 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;
}
1890: cdef unsigned int unum
1891: cdef int num
+1892: 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'));
+1893: if unum > 9:
__pyx_t_1 = (__pyx_v_unum > 9);
if (__pyx_t_1) {
/* … */
}
+1894: if not allow_unicode:
__pyx_t_1 = (!(__pyx_v_allow_unicode != 0));
if (__pyx_t_1) {
/* … */
}
+1895: return -1
{
__pyx_r = -1;
}
goto __pyx_L0;
+1896: if c < 1632:
__pyx_t_1 = (__pyx_v_c < 0x660);
if (__pyx_t_1) {
/* … */
}
+1897: return -1
{
__pyx_r = -1;
}
goto __pyx_L0;
+1898: num = _to_decimal(c)
__pyx_v_num = __QUICKTIONS_to_decimal(__pyx_v_c);
+1899: if num == -1:
__pyx_t_1 = (__pyx_v_num == -1L);
if (__pyx_t_1) {
/* … */
}
+1900: return -1
{
__pyx_r = -1;
}
goto __pyx_L0;
+1901: unum = <unsigned int> num
__pyx_v_unum = ((unsigned int)__pyx_v_num);
+1902: c = <Py_UCS4> (num + c'0')
__pyx_v_c = ((Py_UCS4)(__pyx_v_num + '0'));
+1903: if c_digits:
__pyx_t_1 = (__pyx_v_c_digits != 0);
if (__pyx_t_1) {
/* … */
}
+1904: c_digits[0][0] = <char> c
((__pyx_v_c_digits[0])[0]) = ((char)__pyx_v_c);
+1905: c_digits[0] += 1
__pyx_t_2 = 0;
(__pyx_v_c_digits[__pyx_t_2]) = ((__pyx_v_c_digits[__pyx_t_2]) + 1);
+1906: return <int> unum
{
__pyx_r = ((int)__pyx_v_unum);
}
goto __pyx_L0;
1907:
1908:
+1909: 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;
}
+1910: c_digits_end[0][0] = 0
((__pyx_v_c_digits_end[0])[0]) = 0;
+1911: 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, 1911, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_py_number = __pyx_t_1; __pyx_t_1 = 0;
+1912: c_digits_end[0] = c_digits_start # reset
(__pyx_v_c_digits_end[0]) = __pyx_v_c_digits_start;
+1913: return py_number
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__Pyx_INCREF(__pyx_v_py_number);
__pyx_r = __pyx_v_py_number;
}
__Pyx_XDECREF(__pyx_temp);
}
goto __pyx_L0;
1914:
1915:
+1916: @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;
1917: cdef tuple _parse_fraction(AnyString s, Py_ssize_t s_len, orig_str):
1918: """
1919: Parse a string into a number tuple: (numerator, denominator, is_normalised)
1920: """
+1921: cdef Py_ssize_t pos, decimal_len = 0
__pyx_v_decimal_len = 0; /* … */ __pyx_v_decimal_len = 0;
1922: cdef Py_UCS4 c
+1923: cdef ParserState state = BEGIN_SPACE
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE; /* … */ __pyx_v_state = __pyx_e_10quicktions_BEGIN_SPACE;
1924:
+1925: 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;
1926: cdef int digit
1927: cdef unsigned int udigit
+1928: 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;
1929: cdef ullong igcd
+1930: cdef object num = None, decimal, denom
__Pyx_INCREF(Py_None); __pyx_v_num = Py_None; /* … */ __Pyx_INCREF(Py_None); __pyx_v_num = Py_None;
1931: # 2^n > 10^(n * 5/17)
+1932: 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);
1933:
1934: # Incremental Unicode iteration isn't in Cython yet.
+1935: cdef int allow_unicode = AnyString is unicode
__pyx_v_allow_unicode = 1; /* … */ __pyx_v_allow_unicode = 0;
+1936: cdef int s_kind = 1
__pyx_v_s_kind = 1; /* … */ __pyx_v_s_kind = 1;
+1937: cdef void* s_data = NULL
__pyx_v_s_data = NULL; /* … */ __pyx_v_s_data = NULL;
+1938: cdef char* cdata = NULL
__pyx_v_cdata = NULL; /* … */ __pyx_v_cdata = NULL;
1939:
1940: if AnyString is unicode:
+1941: _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, 1941, __pyx_L1_error)
+1942: if s_kind == 1:
__pyx_t_2 = (__pyx_v_s_kind == 1);
if (__pyx_t_2) {
/* … */
}
+1943: return _parse_fraction(<char*> s_data, s_len, orig_str)
__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, 1943, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = ((PyObject*)__pyx_t_3); } __Pyx_XDECREF(__pyx_temp); } __pyx_t_3 = 0; goto __pyx_L0;
+1944: cdata = <char*> s_data
__pyx_v_cdata = ((char *)__pyx_v_s_data);
+1945: cdata += 0 # mark used
__pyx_v_cdata = (__pyx_v_cdata + 0);
1946: else:
+1947: cdata = s
__pyx_v_cdata = __pyx_v_s;
1948:
1949: # We collect the digits in inum / idenum as long as the value fits their integer size
1950: # and additionally in a char* buffer in case it grows too large.
+1951: cdef bytes digits = b'\0' * s_len
__pyx_t_3 = __Pyx_PySequence_Multiply(__pyx_mstate_global->__pyx_kp_b__16, __pyx_v_s_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1951, __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__16, __pyx_v_s_len); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1951, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_v_digits = ((PyObject*)__pyx_t_1); __pyx_t_1 = 0;
+1952: 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, 1952, __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, 1952, __pyx_L1_error) __pyx_v_c_digits_start = __pyx_t_2;
+1953: 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;
1954:
+1955: pos = 0
__pyx_v_pos = 0; /* … */ __pyx_v_pos = 0;
+1956: 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;
+1957: 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;
+1958: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+1959: 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);
+1960: 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) {
/* … */
}
+1961: if c == u'/':
switch (__pyx_v_c) {
case 47:
/* … */
break;
case 46:
/* … */
switch (__pyx_v_c) {
case 47:
/* … */
break;
case 46:
+1962: 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:
+1963: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1963, __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, 1963, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1964: elif state in (NUM, NUM_SPACE):
case __pyx_e_10quicktions_NUM_SPACE:
/* … */
break;
default:
/* … */
case __pyx_e_10quicktions_NUM_SPACE:
/* … */
break;
default:
+1965: 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, 1965, __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, 1965, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1966: else:
+1967: _raise_invalid_input(orig_str)
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1967, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; break; } /* … */ __pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1967, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1968: state = DENOM_START
__pyx_v_state = __pyx_e_10quicktions_DENOM_START;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_START;
+1969: break
goto __pyx_L5_break;
/* … */
goto __pyx_L4_break;
+1970: elif c == u'.':
break;
case 69:
/* … */
break;
case 69:
+1971: 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:
+1972: state = START_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
/* … */
__pyx_v_state = __pyx_e_10quicktions_START_DECIMAL_DOT;
+1973: elif state == SMALL_NUM:
break;
case __pyx_e_10quicktions_NUM:
/* … */
break;
case __pyx_e_10quicktions_NUM:
+1974: state = SMALL_DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_DOT;
+1975: elif state == NUM:
break;
default:
/* … */
break;
default:
+1976: state = DECIMAL_DOT
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_DOT;
1977: else:
+1978: _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, 1978, __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, 1978, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1979: break
goto __pyx_L5_break;
/* … */
goto __pyx_L4_break;
+1980: elif c in u'eE':
case 0x65:
/* … */
break;
case 43:
/* … */
case 0x65:
/* … */
break;
case 43:
+1981: 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:
+1982: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1982, __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, 1982, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+1983: elif state == NUM:
break;
default:
/* … */
break;
default:
+1984: 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, 1984, __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, 1984, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
1985: else:
+1986: _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, 1986, __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, 1986, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+1987: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
+1988: break
goto __pyx_L5_break;
/* … */
goto __pyx_L4_break;
+1989: elif c in u'-+':
case 45:
/* … */
break;
case 95:
/* … */
case 45:
/* … */
break;
case 95:
+1990: 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;
}
+1991: is_neg = c == u'-'
__pyx_v_is_neg = (__pyx_v_c == 45);
/* … */
__pyx_v_is_neg = (__pyx_v_c == 45);
+1992: state = BEGIN_SIGN
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
/* … */
__pyx_v_state = __pyx_e_10quicktions_BEGIN_SIGN;
1993: else:
+1994: _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, 1994, __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, 1994, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L6:;
+1995: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
+1996: elif c == u'_':
break;
default:
/* … */
break;
default:
+1997: 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:
+1998: state = SMALL_NUM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM_US;
+1999: elif state == NUM:
break;
default:
/* … */
break;
default:
+2000: state = NUM_US
__pyx_v_state = __pyx_e_10quicktions_NUM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM_US;
2001: else:
+2002: _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, 2002, __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, 2002, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2003: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
2004: else:
+2005: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2005, __pyx_L1_error) if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2005, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+2006: 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;
+2007: 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]);
+2008: if not c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2008, __pyx_L1_error) __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2008, __pyx_L1_error) __pyx_t_5 = (!__pyx_t_3); if (__pyx_t_5) { /* … */ }
+2009: break
goto __pyx_L10_break;
/* … */
goto __pyx_L9_break;
+2010: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L10_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L9_break:;
2011:
+2012: 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:
+2013: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
+2014: elif state == SMALL_NUM:
break;
case __pyx_e_10quicktions_NUM:
/* … */
break;
case __pyx_e_10quicktions_NUM:
+2015: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2015, __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, 2015, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+2016: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
+2017: elif state == NUM:
break;
default:
/* … */
break;
default:
+2018: 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, 2018, __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, 2018, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+2019: state = NUM_SPACE
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM_SPACE;
2020: else:
+2021: _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, 2021, __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, 2021, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2022: continue
goto __pyx_L4_continue;
/* … */
goto __pyx_L3_continue;
2023:
+2024: _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, 2024, __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, 2024, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2025: continue
goto __pyx_L4_continue;
break;
}
/* … */
goto __pyx_L3_continue;
break;
}
2026:
2027: # normal digit found
+2028: 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:
+2029: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+2030: state = SMALL_NUM
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_NUM;
2031:
2032: # fast-path for consecutive digits
+2033: 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;
+2034: 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]);
+2035: 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);
+2036: 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) {
/* … */
}
+2037: break
goto __pyx_L13_break;
/* … */
goto __pyx_L12_break;
+2038: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+2039: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L13_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L12_break:;
2040:
+2041: 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) {
/* … */
}
+2042: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM;
+2043: elif state == NUM_US:
break;
default: break;
}
/* … */
break;
default: break;
}
+2044: state = NUM
__pyx_v_state = __pyx_e_10quicktions_NUM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_NUM;
2045:
2046: # We might have switched to NUM above, so continue right here in that case.
+2047: 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:
2048: pass # handled above
+2049: elif state == NUM:
break;
default:
/* … */
break;
default:
2050: # fast-path for consecutive digits
+2051: 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;
+2052: 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]);
+2053: 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);
+2054: 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) {
/* … */
}
+2055: break
goto __pyx_L19_break;
/* … */
goto __pyx_L18_break;
+2056: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L19_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L18_break:;
2057: else:
+2058: _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, 2058, __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, 2058, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L3_continue:; } __pyx_L4_break:;
2059:
+2060: 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:
2061: # NUM '/' | SMALL_NUM '/'
+2062: 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;
+2063: 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]);
+2064: if not c.isspace():
__pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2064, __pyx_L1_error) __pyx_t_2 = (!__pyx_t_6); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_5 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 2064, __pyx_L1_error) __pyx_t_3 = (!__pyx_t_5); if (__pyx_t_3) { /* … */ }
+2065: break
goto __pyx_L22_break;
/* … */
goto __pyx_L21_break;
+2066: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L22_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L21_break:;
2067:
2068: # Start fresh digits collection.
+2069: c_digits = c_digits_start
__pyx_v_c_digits = __pyx_v_c_digits_start;
/* … */
__pyx_v_c_digits = __pyx_v_c_digits_start;
+2070: 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;
+2071: 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]);
+2072: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2073: 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);
+2074: 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) {
/* … */
}
+2075: 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:
+2076: 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;
}
+2077: 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));
+2078: state = DENOM_SIGN
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_SIGN;
2079: else:
+2080: _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, 2080, __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, 2080, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L26:;
+2081: continue
goto __pyx_L24_continue;
/* … */
goto __pyx_L23_continue;
+2082: elif c == u'_':
break;
default:
/* … */
break;
default:
+2083: 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:
+2084: state = SMALL_DENOM_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM_US;
+2085: elif state == DENOM:
break;
default:
/* … */
break;
default:
+2086: state = DENOM_US
__pyx_v_state = __pyx_e_10quicktions_DENOM_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_US;
2087: else:
+2088: _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, 2088, __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, 2088, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2089: continue
goto __pyx_L24_continue;
/* … */
goto __pyx_L23_continue;
2090: else:
+2091: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2091, __pyx_L1_error) if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2091, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+2092: 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;
+2093: 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]);
+2094: if not c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2094, __pyx_L1_error) __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2094, __pyx_L1_error) __pyx_t_5 = (!__pyx_t_3); if (__pyx_t_5) { /* … */ }
+2095: break
goto __pyx_L30_break;
/* … */
goto __pyx_L29_break;
+2096: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L30_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L29_break:;
2097:
+2098: 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:
2099: pass
+2100: elif state == SMALL_DENOM:
break;
case __pyx_e_10quicktions_DENOM:
/* … */
break;
case __pyx_e_10quicktions_DENOM:
+2101: denom = idenom
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2101, __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, 2101, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
+2102: elif state == DENOM:
break;
default:
/* … */
break;
default:
+2103: 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, 2103, __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, 2103, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2104: else:
+2105: _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, 2105, __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, 2105, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2106: state = DENOM_SPACE
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM_SPACE;
+2107: continue
goto __pyx_L24_continue;
/* … */
goto __pyx_L23_continue;
2108:
+2109: _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, 2109, __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, 2109, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2110: continue
goto __pyx_L24_continue;
break;
}
/* … */
goto __pyx_L23_continue;
break;
}
2111:
2112: # normal digit found
+2113: 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:
+2114: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
/* … */
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+2115: state = SMALL_DENOM
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DENOM;
2116:
2117: # fast-path for consecutive digits
+2118: 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;
+2119: 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]);
+2120: 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);
+2121: 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) {
/* … */
}
+2122: break
goto __pyx_L33_break;
/* … */
goto __pyx_L32_break;
+2123: idenom = idenom * 10 + digit
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
/* … */
__pyx_v_idenom = ((__pyx_v_idenom * 10) + __pyx_v_digit);
+2124: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L33_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L32_break:;
2125:
+2126: 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) {
/* … */
}
+2127: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM;
+2128: elif state == DENOM_US:
break;
default: break;
}
/* … */
break;
default: break;
}
+2129: state = DENOM
__pyx_v_state = __pyx_e_10quicktions_DENOM;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DENOM;
2130:
2131: # We might have switched to DENOM above, so continue right here in that case.
+2132: 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:
2133: pass # handled above
+2134: elif state == DENOM:
break;
default:
/* … */
break;
default:
2135: # fast-path for consecutive digits
+2136: 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;
+2137: c = _char_at(s_data, s_kind, pos) if AnyString is unicode else cdata[pos]
__pyx_v_c = __QUICKTIONS_char_at(__pyx_v_s_data, __pyx_v_s_kind, __pyx_v_pos);
/* … */
__pyx_v_c = (__pyx_v_cdata[__pyx_v_pos]);
+2138: digit = _parse_digit(&c_digits, c, allow_unicode)
__pyx_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: break
goto __pyx_L39_break;
/* … */
goto __pyx_L38_break;
+2141: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L39_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L38_break:;
2142: else:
+2143: _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, 2143, __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, 2143, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L23_continue:; }
2144:
+2145: 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;
}
2146: # SMALL_NUM '.' | '.'
+2147: 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;
+2148: 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]);
+2149: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2150: 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);
+2151: 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) {
/* … */
}
+2152: if c == u'_':
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
/* … */
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
+2153: 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;
}
+2154: state = SMALL_DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL_US;
2155: else:
+2156: _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, 2156, __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, 2156, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L43:;
+2157: continue
goto __pyx_L41_continue;
/* … */
goto __pyx_L40_continue;
+2158: elif c in u'eE':
case 0x65:
/* … */
break;
default:
/* … */
case 0x65:
/* … */
break;
default:
+2159: 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:
+2160: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2160, __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, 2160, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2161: else:
+2162: _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, 2162, __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, 2162, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2163: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
+2164: break
goto __pyx_L42_break;
/* … */
goto __pyx_L41_break;
2165: else:
+2166: if c.isspace():
__pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2166, __pyx_L1_error) if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_5 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 2166, __pyx_L1_error) if (__pyx_t_5) { /* … */ }
+2167: 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;
+2168: 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]);
+2169: if not c.isspace():
__pyx_t_6 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_6 == ((int)-1))) __PYX_ERR(0, 2169, __pyx_L1_error) __pyx_t_2 = (!__pyx_t_6); if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_5 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_5 == ((int)-1))) __PYX_ERR(0, 2169, __pyx_L1_error) __pyx_t_3 = (!__pyx_t_5); if (__pyx_t_3) { /* … */ }
+2170: break
goto __pyx_L47_break;
/* … */
goto __pyx_L46_break;
+2171: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L47_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L46_break:;
2172:
+2173: 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:
+2174: num = inum
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2174, __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, 2174, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
+2175: state = SMALL_END_SPACE
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_END_SPACE;
2176: else:
+2177: _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, 2177, __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, 2177, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2178: continue
goto __pyx_L41_continue;
/* … */
goto __pyx_L40_continue;
2179:
+2180: _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, 2180, __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, 2180, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2181: continue
goto __pyx_L41_continue;
break;
}
/* … */
goto __pyx_L40_continue;
break;
}
2182:
2183: # normal digit found
+2184: 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:
+2185: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+2186: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2187: state = SMALL_DECIMAL
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
/* … */
__pyx_v_state = __pyx_e_10quicktions_SMALL_DECIMAL;
2188:
2189: # fast-path for consecutive digits
+2190: 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;
+2191: 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]);
+2192: 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);
+2193: 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) {
/* … */
}
+2194: break
goto __pyx_L50_break;
/* … */
goto __pyx_L49_break;
+2195: inum = inum * 10 + digit
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
/* … */
__pyx_v_inum = ((__pyx_v_inum * 10) + __pyx_v_digit);
+2196: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2197: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L50_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L49_break:;
2198:
+2199: 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) {
/* … */
}
+2200: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
+2201: break
goto __pyx_L42_break;
/* … */
goto __pyx_L41_break;
2202: else:
+2203: _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, 2203, __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, 2203, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L40_continue:; } __pyx_L41_break:;
2204:
+2205: 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;
}
2206: # NUM '.' | SMALL_DECIMAL->DECIMAL
+2207: 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;
+2208: 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]);
+2209: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2210: 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);
+2211: 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) {
/* … */
}
+2212: if c == u'_':
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
/* … */
switch (__pyx_v_c) {
case 95:
/* … */
break;
case 69:
+2213: 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;
}
+2214: state = DECIMAL_US
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL_US;
2215: else:
+2216: _raise_invalid_input(orig_str)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0;
}
__pyx_L61:;
/* … */
/*else*/ {
__pyx_t_1 = __pyx_f_10quicktions__raise_invalid_input(__pyx_v_orig_str); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2216, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L60:;
+2217: continue
goto __pyx_L58_continue;
/* … */
goto __pyx_L57_continue;
+2218: elif c in u'eE':
case 0x65:
/* … */
break;
default:
/* … */
case 0x65:
/* … */
break;
default:
+2219: 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:
+2220: 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, 2220, __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, 2220, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2221: else:
+2222: _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, 2222, __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, 2222, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2223: state = EXP_E
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_E;
+2224: break
goto __pyx_L59_break;
/* … */
goto __pyx_L58_break;
2225: else:
+2226: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2226, __pyx_L1_error) if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2226, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+2227: 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:
+2228: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2229: else:
+2230: _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, 2230, __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, 2230, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; }
+2231: break
goto __pyx_L59_break;
/* … */
goto __pyx_L58_break;
2232:
+2233: _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, 2233, __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, 2233, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2234: continue
goto __pyx_L58_continue;
break;
}
/* … */
goto __pyx_L57_continue;
break;
}
2235:
2236: # normal digit found
+2237: 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:
+2238: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2239: state = DECIMAL
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
/* … */
__pyx_v_state = __pyx_e_10quicktions_DECIMAL;
2240:
2241: # fast-path for consecutive digits
+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: 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);
+2245: 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) {
/* … */
}
+2246: break
goto __pyx_L64_break;
/* … */
goto __pyx_L63_break;
+2247: decimal_len += 1
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
/* … */
__pyx_v_decimal_len = (__pyx_v_decimal_len + 1);
+2248: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L64_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L63_break:;
2249: else:
+2250: _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, 2250, __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, 2250, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L57_continue:; } __pyx_L58_break:;
2251:
+2252: 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) {
/* … */
}
2253: # (SMALL_) NUM ['.' DECIMAL] 'E'
+2254: 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;
+2255: 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]);
+2256: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
+2257: 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);
+2258: 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) {
/* … */
}
+2259: 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:
+2260: 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;
}
+2261: exp_is_neg = c == u'-'
__pyx_v_exp_is_neg = (__pyx_v_c == 45);
/* … */
__pyx_v_exp_is_neg = (__pyx_v_c == 45);
+2262: state = EXP_SIGN
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_SIGN;
2263: else:
+2264: _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, 2264, __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, 2264, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L69:;
+2265: continue
goto __pyx_L67_continue;
/* … */
goto __pyx_L66_continue;
+2266: elif c == u'_':
break;
default:
/* … */
break;
default:
+2267: 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;
}
+2268: state = EXP_US
__pyx_v_state = __pyx_e_10quicktions_EXP_US;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP_US;
2269: else:
+2270: _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, 2270, __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, 2270, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L70:;
+2271: continue
goto __pyx_L67_continue;
/* … */
goto __pyx_L66_continue;
2272: else:
+2273: if c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2273, __pyx_L1_error) if (__pyx_t_2) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2273, __pyx_L1_error) if (__pyx_t_3) { /* … */ }
+2274: 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;
}
+2275: state = END_SPACE
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
/* … */
__pyx_v_state = __pyx_e_10quicktions_END_SPACE;
2276: else:
+2277: _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, 2277, __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, 2277, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
}
__pyx_L72:;
+2278: break
goto __pyx_L68_break;
/* … */
goto __pyx_L67_break;
2279:
+2280: _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, 2280, __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, 2280, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
+2281: continue
goto __pyx_L67_continue;
break;
}
/* … */
goto __pyx_L66_continue;
break;
}
2282:
2283: # normal digit found
+2284: 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:
+2285: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
/* … */
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2286: state = EXP
__pyx_v_state = __pyx_e_10quicktions_EXP;
/* … */
__pyx_v_state = __pyx_e_10quicktions_EXP;
2287:
2288: # fast-path for consecutive digits
+2289: 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;
+2290: 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]);
+2291: 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);
+2292: 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) {
/* … */
}
+2293: break
goto __pyx_L75_break;
/* … */
goto __pyx_L74_break;
+2294: iexp = iexp * 10 + digit
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
/* … */
__pyx_v_iexp = ((__pyx_v_iexp * 10) + __pyx_v_digit);
+2295: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L75_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L74_break:;
2296:
+2297: 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) {
/* … */
}
+2298: _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, 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_parse_overflow(__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: else:
+2300: _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, 2300, __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, 2300, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; break; } __pyx_L66_continue:; } __pyx_L67_break:;
2301:
+2302: 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;
}
+2303: 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;
+2304: 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]);
+2305: if not c.isspace():
__pyx_t_2 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_2 == ((int)-1))) __PYX_ERR(0, 2305, __pyx_L1_error) __pyx_t_6 = (!__pyx_t_2); if (__pyx_t_6) { /* … */ } /* … */ __pyx_t_3 = __Pyx_Py_UNICODE_ISSPACE(__pyx_v_c); if (unlikely(__pyx_t_3 == ((int)-1))) __PYX_ERR(0, 2305, __pyx_L1_error) __pyx_t_5 = (!__pyx_t_3); if (__pyx_t_5) { /* … */ }
+2306: break
goto __pyx_L81_break;
/* … */
goto __pyx_L80_break;
+2307: pos += 1
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L81_break:;
/* … */
__pyx_v_pos = (__pyx_v_pos + 1);
}
__pyx_L80_break:;
2308:
+2309: 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) {
/* … */
}
+2310: _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, 2310, __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, 2310, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
2311:
+2312: cdef bint is_normalised = False
__pyx_v_is_normalised = 0; /* … */ __pyx_v_is_normalised = 0;
+2313: 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:
2314: # Special case for 'small' numbers: normalise directly in C space.
+2315: 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;
}
2316: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2317: 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;
}
+2318: 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, 2318, __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, 2318, __pyx_L1_error) __pyx_v_idenom = __pyx_t_6;
+2319: 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, 2319, __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, 2319, __pyx_L1_error) __pyx_v_igcd = __pyx_t_7;
+2320: 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;
}
+2321: inum //= igcd
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
/* … */
__pyx_v_inum = (__pyx_v_inum / __pyx_v_igcd);
+2322: 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, 2322, __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, 2322, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2323: else:
+2324: denom = pow10(decimal_len)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2324, __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, 2324, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1);
__pyx_t_1 = 0;
}
__pyx_L89:;
2325: else:
+2326: denom = pow10(decimal_len)
/*else*/ {
__pyx_t_3 = __pyx_f_10quicktions_pow10(__pyx_v_decimal_len); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2326, __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, 2326, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1);
__pyx_t_1 = 0;
}
__pyx_L86:;
2327: else:
+2328: 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:;
+2329: if is_neg:
if (__pyx_v_is_neg) {
/* … */
}
/* … */
if (__pyx_v_is_neg) {
/* … */
}
+2330: inum = -inum
__pyx_v_inum = (-__pyx_v_inum);
/* … */
__pyx_v_inum = (-__pyx_v_inum);
+2331: return inum, denom, True
__pyx_t_3 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2331, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_3); __pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2331, __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, 2331, __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, 2331, __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, 2331, __pyx_L1_error); __pyx_t_3 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = ((PyObject*)__pyx_t_9); } __Pyx_XDECREF(__pyx_temp); } __pyx_t_9 = 0; goto __pyx_L0; /* … */ __pyx_t_1 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_inum); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2331, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2331, __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, 2331, __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, 2331, __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, 2331, __pyx_L1_error); __pyx_t_1 = 0; { PyObject *__pyx_temp; { __pyx_temp = __pyx_r; __pyx_r = ((PyObject*)__pyx_t_8); } __Pyx_XDECREF(__pyx_temp); } __pyx_t_8 = 0; goto __pyx_L0;
2332:
+2333: elif state == SMALL_DENOM:
break;
case __pyx_e_10quicktions_NUM:
/* … */
break;
case __pyx_e_10quicktions_NUM:
+2334: denom = idenom
__pyx_t_9 = __Pyx_PyLong_From_PY_LONG_LONG(__pyx_v_idenom); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2334, __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, 2334, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_8); __pyx_t_8 = 0;
+2335: 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:
+2336: is_normalised = True # will be repaired below for iexp < 0
__pyx_v_is_normalised = 1;
/* … */
__pyx_v_is_normalised = 1;
+2337: 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);
+2338: 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, 2338, __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, 2338, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_8); __pyx_t_8 = 0;
+2339: elif state == DENOM:
break;
case __pyx_e_10quicktions_NUM_SPACE:
/* … */
break;
case __pyx_e_10quicktions_NUM_SPACE:
+2340: 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, 2340, __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, 2340, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_8); __pyx_t_8 = 0;
+2341: 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:
+2342: is_normalised = True
__pyx_v_is_normalised = 1;
/* … */
__pyx_v_is_normalised = 1;
+2343: 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);
+2344: elif state == DENOM_SPACE:
break;
default:
/* … */
break;
default:
2345: pass
2346: else:
+2347: _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, 2347, __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, 2347, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; break; }
2348:
+2349: 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) {
/* … */
}
+2350: _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, 2350, __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, 2350, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0;
+2351: if exp_is_neg:
if (__pyx_v_exp_is_neg) {
/* … */
}
/* … */
if (__pyx_v_exp_is_neg) {
/* … */
}
+2352: iexp = -iexp
__pyx_v_iexp = (-__pyx_v_iexp);
/* … */
__pyx_v_iexp = (-__pyx_v_iexp);
+2353: iexp -= decimal_len
__pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len); /* … */ __pyx_v_iexp = (__pyx_v_iexp - __pyx_v_decimal_len);
2354:
+2355: 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;
}
+2356: num *= pow10(iexp)
__pyx_t_9 = __pyx_f_10quicktions_pow10(__pyx_v_iexp); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_9); __pyx_t_3 = __Pyx_PyNumber_InPlaceMultiply_object_object(__pyx_v_num, __pyx_t_9); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2356, __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, 2356, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = __Pyx_PyNumber_InPlaceMultiply_object_object(__pyx_v_num, __pyx_t_8); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2356, __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;
+2357: 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:;
2358: # Only need to normalise if the numerator contains factors of a power of 10 (2 or 5).
+2359: 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, 2359, __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, 2359, __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, 2359, __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, 2359, __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, 2359, __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, 2359, __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, 2359, __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, 2359, __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;
+2360: denom = pow10(-iexp)
__pyx_t_3 = __pyx_f_10quicktions_pow10((-__pyx_v_iexp)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2360, __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, 2360, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_XDECREF_SET(__pyx_v_denom, __pyx_t_1); __pyx_t_1 = 0;
2361:
+2362: if is_neg:
if (__pyx_v_is_neg) {
/* … */
}
/* … */
if (__pyx_v_is_neg) {
/* … */
}
+2363: num = -num
__pyx_t_3 = PyNumber_Negative(__pyx_v_num); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2363, __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, 2363, __pyx_L1_error) __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF_SET(__pyx_v_num, __pyx_t_1); __pyx_t_1 = 0;
2364:
+2365: return num, denom, is_normalised
if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2365, __pyx_L1_error) }
__pyx_t_3 = __Pyx_PyBool_FromLong(__pyx_v_is_normalised); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 2365, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_3);
__pyx_t_9 = PyTuple_New(3); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 2365, __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, 2365, __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, 2365, __pyx_L1_error);
__Pyx_GIVEREF(__pyx_t_3);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_9, 2, __pyx_t_3) != (0)) __PYX_ERR(0, 2365, __pyx_L1_error);
__pyx_t_3 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = ((PyObject*)__pyx_t_9);
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_9 = 0;
goto __pyx_L0;
/* … */
if (unlikely(!__pyx_v_denom)) { __Pyx_RaiseUnboundLocalError("denom"); __PYX_ERR(0, 2365, __pyx_L1_error) }
__pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_is_normalised); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 2365, __pyx_L1_error)
__Pyx_GOTREF(__pyx_t_1);
__pyx_t_8 = PyTuple_New(3); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 2365, __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, 2365, __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, 2365, __pyx_L1_error);
__Pyx_GIVEREF(__pyx_t_1);
if (__Pyx_PyTuple_SET_ITEM(__pyx_t_8, 2, __pyx_t_1) != (0)) __PYX_ERR(0, 2365, __pyx_L1_error);
__pyx_t_1 = 0;
{
PyObject *__pyx_temp;
{
__pyx_temp = __pyx_r;
__pyx_r = ((PyObject*)__pyx_t_8);
}
__Pyx_XDECREF(__pyx_temp);
}
__pyx_t_8 = 0;
goto __pyx_L0;