7#include "nuitka/prelude.h"
10#include "HelpersOperationBinaryDivmodUtils.c"
13#if PYTHON_VERSION < 0x300
15static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
16 CHECK_OBJECT(operand1);
17 assert(PyInt_CheckExact(operand1));
18 CHECK_OBJECT(operand2);
19 assert(PyInt_CheckExact(operand2));
26#pragma warning(disable : 4101)
28 NUITKA_MAY_BE_UNUSED
bool cbool_result;
29 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
30 NUITKA_MAY_BE_UNUSED
long clong_result;
31 NUITKA_MAY_BE_UNUSED
double cfloat_result;
36 CHECK_OBJECT(operand1);
37 assert(PyInt_CheckExact(operand1));
38 CHECK_OBJECT(operand2);
39 assert(PyInt_CheckExact(operand2));
41 const long a = PyInt_AS_LONG(operand1);
42 const long b = PyInt_AS_LONG(operand2);
44 if (unlikely(b == 0)) {
45 PyThreadState *tstate = PyThreadState_GET();
47 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"integer division or modulo by zero");
48 goto exit_result_exception;
51 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
53 long a_mod_b = (long)(a - (
unsigned long)a_div_b * b);
55 if (a_mod_b && (b ^ a_mod_b) < 0) {
60 PyObject *r = Py_BuildValue(
"(ll)", a_div_b, a_mod_b);
62 goto exit_result_object;
66 PyObject *operand1_object = operand1;
67 PyObject *operand2_object = operand2;
69 PyObject *r = PyLong_Type.tp_as_number->nb_divmod(operand1_object, operand2_object);
70 assert(r != Py_NotImplemented);
73 goto exit_result_object;
77 if (unlikely(obj_result == NULL)) {
78 goto exit_result_exception;
90PyObject *BINARY_OPERATION_DIVMOD_OBJECT_INT_INT(PyObject *operand1, PyObject *operand2) {
91 return _BINARY_OPERATION_DIVMOD_OBJECT_INT_INT(operand1, operand2);
95#if PYTHON_VERSION < 0x300
97static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_INT(PyObject *operand1,
99 PyTypeObject *type1 = Py_TYPE(operand1);
103#pragma warning(disable : 4101)
105 NUITKA_MAY_BE_UNUSED
bool cbool_result;
106 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
112 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divmod : NULL;
113 binaryfunc slot2 = NULL;
115 if (!(type1 == &PyInt_Type)) {
118 slot2 = PyInt_Type.tp_as_number->nb_divmod;
120 if (slot1 == slot2) {
126 PyObject *x = slot1(operand1, operand2);
128 if (x != Py_NotImplemented) {
130 goto exit_binary_result_object;
133 Py_DECREF_IMMORTAL(x);
137 PyObject *x = slot2(operand1, operand2);
139 if (x != Py_NotImplemented) {
141 goto exit_binary_result_object;
144 Py_DECREF_IMMORTAL(x);
147#if PYTHON_VERSION < 0x300
148 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
150 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
153 PyObject *coerced1 = operand1;
154 PyObject *coerced2 = operand2;
156 int err = c1(&coerced1, &coerced2);
158 if (unlikely(err < 0)) {
159 goto exit_binary_exception;
163 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
165 if (likely(mv == NULL)) {
166 binaryfunc slot = mv->nb_divmod;
168 if (likely(slot != NULL)) {
169 PyObject *x = slot(coerced1, coerced2);
175 goto exit_binary_result_object;
184 coercion c2 = PyInt_Type.tp_as_number->nb_coerce;
187 PyObject *coerced1 = operand1;
188 PyObject *coerced2 = operand2;
190 int err = c2(&coerced2, &coerced1);
192 if (unlikely(err < 0)) {
193 goto exit_binary_exception;
197 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
199 if (likely(mv == NULL)) {
200 binaryfunc slot = mv->nb_divmod;
202 if (likely(slot != NULL)) {
203 PyObject *x = slot(coerced1, coerced2);
209 goto exit_binary_result_object;
221 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): '%s' and 'int'", type1->tp_name);
222 goto exit_binary_exception;
224exit_binary_result_object:
227exit_binary_exception:
230static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
231 CHECK_OBJECT(operand1);
232 CHECK_OBJECT(operand2);
233 assert(PyInt_CheckExact(operand2));
235 PyTypeObject *type1 = Py_TYPE(operand1);
237 if (type1 == &PyInt_Type) {
245#pragma warning(disable : 4101)
247 NUITKA_MAY_BE_UNUSED
bool cbool_result;
248 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
249 NUITKA_MAY_BE_UNUSED
long clong_result;
250 NUITKA_MAY_BE_UNUSED
double cfloat_result;
255 CHECK_OBJECT(operand1);
256 assert(PyInt_CheckExact(operand1));
257 CHECK_OBJECT(operand2);
258 assert(PyInt_CheckExact(operand2));
260 const long a = PyInt_AS_LONG(operand1);
261 const long b = PyInt_AS_LONG(operand2);
263 if (unlikely(b == 0)) {
264 PyThreadState *tstate = PyThreadState_GET();
266 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"integer division or modulo by zero");
267 goto exit_result_exception;
270 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
271 long a_div_b = a / b;
272 long a_mod_b = (long)(a - (
unsigned long)a_div_b * b);
274 if (a_mod_b && (b ^ a_mod_b) < 0) {
279 PyObject *r = Py_BuildValue(
"(ll)", a_div_b, a_mod_b);
281 goto exit_result_object;
285 PyObject *operand1_object = operand1;
286 PyObject *operand2_object = operand2;
288 PyObject *r = PyLong_Type.tp_as_number->nb_divmod(operand1_object, operand2_object);
289 assert(r != Py_NotImplemented);
292 goto exit_result_object;
296 if (unlikely(obj_result == NULL)) {
297 goto exit_result_exception;
305 exit_result_exception:
309 return __BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_INT(operand1, operand2);
312PyObject *BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_INT(PyObject *operand1, PyObject *operand2) {
313 return _BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_INT(operand1, operand2);
317#if PYTHON_VERSION < 0x300
319static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_DIVMOD_OBJECT_INT_OBJECT(PyObject *operand1,
320 PyObject *operand2) {
321 PyTypeObject *type2 = Py_TYPE(operand2);
325#pragma warning(disable : 4101)
327 NUITKA_MAY_BE_UNUSED
bool cbool_result;
328 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
333 binaryfunc slot1 = PyInt_Type.tp_as_number->nb_divmod;
334 binaryfunc slot2 = NULL;
336 if (!(&PyInt_Type == type2)) {
339 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divmod : NULL;
341 if (slot1 == slot2) {
348 if (Nuitka_Type_IsSubtype(type2, &PyInt_Type)) {
349 PyObject *x = slot2(operand1, operand2);
351 if (x != Py_NotImplemented) {
353 goto exit_binary_result_object;
356 Py_DECREF_IMMORTAL(x);
361 PyObject *x = slot1(operand1, operand2);
363 if (x != Py_NotImplemented) {
365 goto exit_binary_result_object;
368 Py_DECREF_IMMORTAL(x);
372 PyObject *x = slot2(operand1, operand2);
374 if (x != Py_NotImplemented) {
376 goto exit_binary_result_object;
379 Py_DECREF_IMMORTAL(x);
382#if PYTHON_VERSION < 0x300
383 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
384 coercion c1 = PyInt_Type.tp_as_number->nb_coerce;
387 PyObject *coerced1 = operand1;
388 PyObject *coerced2 = operand2;
390 int err = c1(&coerced1, &coerced2);
392 if (unlikely(err < 0)) {
393 goto exit_binary_exception;
397 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
399 if (likely(mv == NULL)) {
400 binaryfunc slot = mv->nb_divmod;
402 if (likely(slot != NULL)) {
403 PyObject *x = slot(coerced1, coerced2);
409 goto exit_binary_result_object;
419 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
422 PyObject *coerced1 = operand1;
423 PyObject *coerced2 = operand2;
425 int err = c2(&coerced2, &coerced1);
427 if (unlikely(err < 0)) {
428 goto exit_binary_exception;
432 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
434 if (likely(mv == NULL)) {
435 binaryfunc slot = mv->nb_divmod;
437 if (likely(slot != NULL)) {
438 PyObject *x = slot(coerced1, coerced2);
444 goto exit_binary_result_object;
456 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'int' and '%s'", type2->tp_name);
457 goto exit_binary_exception;
459exit_binary_result_object:
462exit_binary_exception:
465static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
466 CHECK_OBJECT(operand1);
467 assert(PyInt_CheckExact(operand1));
468 CHECK_OBJECT(operand2);
470 PyTypeObject *type2 = Py_TYPE(operand2);
472 if (&PyInt_Type == type2) {
480#pragma warning(disable : 4101)
482 NUITKA_MAY_BE_UNUSED
bool cbool_result;
483 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
484 NUITKA_MAY_BE_UNUSED
long clong_result;
485 NUITKA_MAY_BE_UNUSED
double cfloat_result;
490 CHECK_OBJECT(operand1);
491 assert(PyInt_CheckExact(operand1));
492 CHECK_OBJECT(operand2);
493 assert(PyInt_CheckExact(operand2));
495 const long a = PyInt_AS_LONG(operand1);
496 const long b = PyInt_AS_LONG(operand2);
498 if (unlikely(b == 0)) {
499 PyThreadState *tstate = PyThreadState_GET();
501 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"integer division or modulo by zero");
502 goto exit_result_exception;
505 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
506 long a_div_b = a / b;
507 long a_mod_b = (long)(a - (
unsigned long)a_div_b * b);
509 if (a_mod_b && (b ^ a_mod_b) < 0) {
514 PyObject *r = Py_BuildValue(
"(ll)", a_div_b, a_mod_b);
516 goto exit_result_object;
520 PyObject *operand1_object = operand1;
521 PyObject *operand2_object = operand2;
523 PyObject *r = PyLong_Type.tp_as_number->nb_divmod(operand1_object, operand2_object);
524 assert(r != Py_NotImplemented);
527 goto exit_result_object;
531 if (unlikely(obj_result == NULL)) {
532 goto exit_result_exception;
540 exit_result_exception:
544 return __BINARY_OPERATION_DIVMOD_OBJECT_INT_OBJECT(operand1, operand2);
547PyObject *BINARY_OPERATION_DIVMOD_OBJECT_INT_OBJECT(PyObject *operand1, PyObject *operand2) {
548 return _BINARY_OPERATION_DIVMOD_OBJECT_INT_OBJECT(operand1, operand2);
553static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
554 CHECK_OBJECT(operand1);
555 assert(PyLong_CheckExact(operand1));
556 CHECK_OBJECT(operand2);
557 assert(PyLong_CheckExact(operand2));
564#pragma warning(disable : 4101)
566 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
567 NUITKA_MAY_BE_UNUSED
long clong_result;
572 PyObject *x = PyLong_Type.tp_as_number->nb_divmod(operand1, operand2);
573 assert(x != Py_NotImplemented);
576 goto exit_result_object;
579 if (unlikely(obj_result == NULL)) {
580 goto exit_result_exception;
588exit_result_exception:
592PyObject *BINARY_OPERATION_DIVMOD_OBJECT_LONG_LONG(PyObject *operand1, PyObject *operand2) {
593 return _BINARY_OPERATION_DIVMOD_OBJECT_LONG_LONG(operand1, operand2);
597static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_LONG(PyObject *operand1,
598 PyObject *operand2) {
599 PyTypeObject *type1 = Py_TYPE(operand1);
603#pragma warning(disable : 4101)
605 NUITKA_MAY_BE_UNUSED
bool cbool_result;
606 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
612 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divmod : NULL;
613 binaryfunc slot2 = NULL;
615 if (!(type1 == &PyLong_Type)) {
618 slot2 = PyLong_Type.tp_as_number->nb_divmod;
620 if (slot1 == slot2) {
626 PyObject *x = slot1(operand1, operand2);
628 if (x != Py_NotImplemented) {
630 goto exit_binary_result_object;
633 Py_DECREF_IMMORTAL(x);
637 PyObject *x = slot2(operand1, operand2);
639 if (x != Py_NotImplemented) {
641 goto exit_binary_result_object;
644 Py_DECREF_IMMORTAL(x);
647#if PYTHON_VERSION < 0x300
648 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
650 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
653 PyObject *coerced1 = operand1;
654 PyObject *coerced2 = operand2;
656 int err = c1(&coerced1, &coerced2);
658 if (unlikely(err < 0)) {
659 goto exit_binary_exception;
663 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
665 if (likely(mv == NULL)) {
666 binaryfunc slot = mv->nb_divmod;
668 if (likely(slot != NULL)) {
669 PyObject *x = slot(coerced1, coerced2);
675 goto exit_binary_result_object;
684 coercion c2 = PyLong_Type.tp_as_number->nb_coerce;
687 PyObject *coerced1 = operand1;
688 PyObject *coerced2 = operand2;
690 int err = c2(&coerced2, &coerced1);
692 if (unlikely(err < 0)) {
693 goto exit_binary_exception;
697 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
699 if (likely(mv == NULL)) {
700 binaryfunc slot = mv->nb_divmod;
702 if (likely(slot != NULL)) {
703 PyObject *x = slot(coerced1, coerced2);
709 goto exit_binary_result_object;
721#if PYTHON_VERSION < 0x300
722 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): '%s' and 'long'", type1->tp_name);
724 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): '%s' and 'int'", type1->tp_name);
726 goto exit_binary_exception;
728exit_binary_result_object:
731exit_binary_exception:
734static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
735 CHECK_OBJECT(operand1);
736 CHECK_OBJECT(operand2);
737 assert(PyLong_CheckExact(operand2));
739 PyTypeObject *type1 = Py_TYPE(operand1);
741 if (type1 == &PyLong_Type) {
749#pragma warning(disable : 4101)
751 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
752 NUITKA_MAY_BE_UNUSED
long clong_result;
757 PyObject *x = PyLong_Type.tp_as_number->nb_divmod(operand1, operand2);
758 assert(x != Py_NotImplemented);
761 goto exit_result_object;
764 if (unlikely(obj_result == NULL)) {
765 goto exit_result_exception;
773 exit_result_exception:
777 return __BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_LONG(operand1, operand2);
780PyObject *BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_LONG(PyObject *operand1, PyObject *operand2) {
781 return _BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_LONG(operand1, operand2);
785static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_DIVMOD_OBJECT_LONG_OBJECT(PyObject *operand1,
786 PyObject *operand2) {
787 PyTypeObject *type2 = Py_TYPE(operand2);
791#pragma warning(disable : 4101)
793 NUITKA_MAY_BE_UNUSED
bool cbool_result;
794 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
799 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_divmod;
800 binaryfunc slot2 = NULL;
802 if (!(&PyLong_Type == type2)) {
805 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divmod : NULL;
807 if (slot1 == slot2) {
814 if (Nuitka_Type_IsSubtype(type2, &PyLong_Type)) {
815 PyObject *x = slot2(operand1, operand2);
817 if (x != Py_NotImplemented) {
819 goto exit_binary_result_object;
822 Py_DECREF_IMMORTAL(x);
827 PyObject *x = slot1(operand1, operand2);
829 if (x != Py_NotImplemented) {
831 goto exit_binary_result_object;
834 Py_DECREF_IMMORTAL(x);
838 PyObject *x = slot2(operand1, operand2);
840 if (x != Py_NotImplemented) {
842 goto exit_binary_result_object;
845 Py_DECREF_IMMORTAL(x);
848#if PYTHON_VERSION < 0x300
849 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
850 coercion c1 = PyLong_Type.tp_as_number->nb_coerce;
853 PyObject *coerced1 = operand1;
854 PyObject *coerced2 = operand2;
856 int err = c1(&coerced1, &coerced2);
858 if (unlikely(err < 0)) {
859 goto exit_binary_exception;
863 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
865 if (likely(mv == NULL)) {
866 binaryfunc slot = mv->nb_divmod;
868 if (likely(slot != NULL)) {
869 PyObject *x = slot(coerced1, coerced2);
875 goto exit_binary_result_object;
885 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
888 PyObject *coerced1 = operand1;
889 PyObject *coerced2 = operand2;
891 int err = c2(&coerced2, &coerced1);
893 if (unlikely(err < 0)) {
894 goto exit_binary_exception;
898 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
900 if (likely(mv == NULL)) {
901 binaryfunc slot = mv->nb_divmod;
903 if (likely(slot != NULL)) {
904 PyObject *x = slot(coerced1, coerced2);
910 goto exit_binary_result_object;
922#if PYTHON_VERSION < 0x300
923 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'long' and '%s'", type2->tp_name);
925 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'int' and '%s'", type2->tp_name);
927 goto exit_binary_exception;
929exit_binary_result_object:
932exit_binary_exception:
935static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
936 CHECK_OBJECT(operand1);
937 assert(PyLong_CheckExact(operand1));
938 CHECK_OBJECT(operand2);
940 PyTypeObject *type2 = Py_TYPE(operand2);
942 if (&PyLong_Type == type2) {
950#pragma warning(disable : 4101)
952 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
953 NUITKA_MAY_BE_UNUSED
long clong_result;
958 PyObject *x = PyLong_Type.tp_as_number->nb_divmod(operand1, operand2);
959 assert(x != Py_NotImplemented);
962 goto exit_result_object;
965 if (unlikely(obj_result == NULL)) {
966 goto exit_result_exception;
974 exit_result_exception:
978 return __BINARY_OPERATION_DIVMOD_OBJECT_LONG_OBJECT(operand1, operand2);
981PyObject *BINARY_OPERATION_DIVMOD_OBJECT_LONG_OBJECT(PyObject *operand1, PyObject *operand2) {
982 return _BINARY_OPERATION_DIVMOD_OBJECT_LONG_OBJECT(operand1, operand2);
986static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_FLOAT(PyObject *operand1, PyObject *operand2) {
987 CHECK_OBJECT(operand1);
988 assert(PyFloat_CheckExact(operand1));
989 CHECK_OBJECT(operand2);
990 assert(PyFloat_CheckExact(operand2));
996#pragma warning(disable : 4101)
999 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1000 NUITKA_MAY_BE_UNUSED
long clong_result;
1001 NUITKA_MAY_BE_UNUSED
double cfloat_result;
1002#if defined(_MSC_VER)
1006 CHECK_OBJECT(operand1);
1007 assert(PyFloat_CheckExact(operand1));
1008 CHECK_OBJECT(operand2);
1009 assert(PyFloat_CheckExact(operand2));
1011 const double a = PyFloat_AS_DOUBLE(operand1);
1012 const double b = PyFloat_AS_DOUBLE(operand2);
1014 if (unlikely(b == 0.0)) {
1015 PyThreadState *tstate = PyThreadState_GET();
1017 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"float modulo");
1018 goto exit_result_exception;
1022 double mod = fmod(a, b);
1023 double div = (a - mod) / b;
1026 if ((b < 0) != (mod < 0)) {
1031 mod = copysign(0.0, b);
1036 floordiv = floor(div);
1037 if (div - floordiv > 0.5) {
1041 floordiv = copysign(0.0, a / b);
1044 PyObject *r = Py_BuildValue(
"(dd)", floordiv, mod);
1047 goto exit_result_object;
1051 if (unlikely(obj_result == NULL)) {
1052 goto exit_result_exception;
1054 result = obj_result;
1055 goto exit_result_ok;
1060exit_result_exception:
1064PyObject *BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_FLOAT(PyObject *operand1, PyObject *operand2) {
1065 return _BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_FLOAT(operand1, operand2);
1069static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_FLOAT(PyObject *operand1,
1070 PyObject *operand2) {
1071 PyTypeObject *type1 = Py_TYPE(operand1);
1073#if defined(_MSC_VER)
1074#pragma warning(push)
1075#pragma warning(disable : 4101)
1077 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1078 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1079#if defined(_MSC_VER)
1084 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divmod : NULL;
1085 binaryfunc slot2 = NULL;
1087 if (!(type1 == &PyFloat_Type)) {
1090 slot2 = PyFloat_Type.tp_as_number->nb_divmod;
1092 if (slot1 == slot2) {
1097 if (slot1 != NULL) {
1098 PyObject *x = slot1(operand1, operand2);
1100 if (x != Py_NotImplemented) {
1102 goto exit_binary_result_object;
1105 Py_DECREF_IMMORTAL(x);
1108 if (slot2 != NULL) {
1109 PyObject *x = slot2(operand1, operand2);
1111 if (x != Py_NotImplemented) {
1113 goto exit_binary_result_object;
1116 Py_DECREF_IMMORTAL(x);
1119#if PYTHON_VERSION < 0x300
1120 if (!NEW_STYLE_NUMBER_TYPE(type1) || !1) {
1122 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
1125 PyObject *coerced1 = operand1;
1126 PyObject *coerced2 = operand2;
1128 int err = c1(&coerced1, &coerced2);
1130 if (unlikely(err < 0)) {
1131 goto exit_binary_exception;
1135 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1137 if (likely(mv == NULL)) {
1138 binaryfunc slot = mv->nb_divmod;
1140 if (likely(slot != NULL)) {
1141 PyObject *x = slot(coerced1, coerced2);
1143 Py_DECREF(coerced1);
1144 Py_DECREF(coerced2);
1147 goto exit_binary_result_object;
1152 Py_DECREF(coerced1);
1153 Py_DECREF(coerced2);
1156 coercion c2 = PyFloat_Type.tp_as_number->nb_coerce;
1159 PyObject *coerced1 = operand1;
1160 PyObject *coerced2 = operand2;
1162 int err = c2(&coerced2, &coerced1);
1164 if (unlikely(err < 0)) {
1165 goto exit_binary_exception;
1169 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1171 if (likely(mv == NULL)) {
1172 binaryfunc slot = mv->nb_divmod;
1174 if (likely(slot != NULL)) {
1175 PyObject *x = slot(coerced1, coerced2);
1177 Py_DECREF(coerced1);
1178 Py_DECREF(coerced2);
1181 goto exit_binary_result_object;
1186 Py_DECREF(coerced1);
1187 Py_DECREF(coerced2);
1193 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): '%s' and 'float'", type1->tp_name);
1194 goto exit_binary_exception;
1196exit_binary_result_object:
1199exit_binary_exception:
1202static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_FLOAT(PyObject *operand1, PyObject *operand2) {
1203 CHECK_OBJECT(operand1);
1204 CHECK_OBJECT(operand2);
1205 assert(PyFloat_CheckExact(operand2));
1207 PyTypeObject *type1 = Py_TYPE(operand1);
1209 if (type1 == &PyFloat_Type) {
1214#if defined(_MSC_VER)
1215#pragma warning(push)
1216#pragma warning(disable : 4101)
1219 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1220 NUITKA_MAY_BE_UNUSED
long clong_result;
1221 NUITKA_MAY_BE_UNUSED
double cfloat_result;
1222#if defined(_MSC_VER)
1226 CHECK_OBJECT(operand1);
1227 assert(PyFloat_CheckExact(operand1));
1228 CHECK_OBJECT(operand2);
1229 assert(PyFloat_CheckExact(operand2));
1231 const double a = PyFloat_AS_DOUBLE(operand1);
1232 const double b = PyFloat_AS_DOUBLE(operand2);
1234 if (unlikely(b == 0.0)) {
1235 PyThreadState *tstate = PyThreadState_GET();
1237 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"float modulo");
1238 goto exit_result_exception;
1242 double mod = fmod(a, b);
1243 double div = (a - mod) / b;
1246 if ((b < 0) != (mod < 0)) {
1251 mod = copysign(0.0, b);
1256 floordiv = floor(div);
1257 if (div - floordiv > 0.5) {
1261 floordiv = copysign(0.0, a / b);
1264 PyObject *r = Py_BuildValue(
"(dd)", floordiv, mod);
1267 goto exit_result_object;
1271 if (unlikely(obj_result == NULL)) {
1272 goto exit_result_exception;
1274 result = obj_result;
1275 goto exit_result_ok;
1280 exit_result_exception:
1284 return __BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_FLOAT(operand1, operand2);
1287PyObject *BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_FLOAT(PyObject *operand1, PyObject *operand2) {
1288 return _BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_FLOAT(operand1, operand2);
1292static HEDLEY_NEVER_INLINE PyObject *__BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_OBJECT(PyObject *operand1,
1293 PyObject *operand2) {
1294 PyTypeObject *type2 = Py_TYPE(operand2);
1296#if defined(_MSC_VER)
1297#pragma warning(push)
1298#pragma warning(disable : 4101)
1300 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1301 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1302#if defined(_MSC_VER)
1306 binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_divmod;
1307 binaryfunc slot2 = NULL;
1309 if (!(&PyFloat_Type == type2)) {
1312 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divmod : NULL;
1314 if (slot1 == slot2) {
1319 if (slot1 != NULL) {
1320 if (slot2 != NULL) {
1321 if (Nuitka_Type_IsSubtype(type2, &PyFloat_Type)) {
1322 PyObject *x = slot2(operand1, operand2);
1324 if (x != Py_NotImplemented) {
1326 goto exit_binary_result_object;
1329 Py_DECREF_IMMORTAL(x);
1334 PyObject *x = slot1(operand1, operand2);
1336 if (x != Py_NotImplemented) {
1338 goto exit_binary_result_object;
1341 Py_DECREF_IMMORTAL(x);
1344 if (slot2 != NULL) {
1345 PyObject *x = slot2(operand1, operand2);
1347 if (x != Py_NotImplemented) {
1349 goto exit_binary_result_object;
1352 Py_DECREF_IMMORTAL(x);
1355#if PYTHON_VERSION < 0x300
1356 if (!1 || !NEW_STYLE_NUMBER_TYPE(type2)) {
1357 coercion c1 = PyFloat_Type.tp_as_number->nb_coerce;
1360 PyObject *coerced1 = operand1;
1361 PyObject *coerced2 = operand2;
1363 int err = c1(&coerced1, &coerced2);
1365 if (unlikely(err < 0)) {
1366 goto exit_binary_exception;
1370 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1372 if (likely(mv == NULL)) {
1373 binaryfunc slot = mv->nb_divmod;
1375 if (likely(slot != NULL)) {
1376 PyObject *x = slot(coerced1, coerced2);
1378 Py_DECREF(coerced1);
1379 Py_DECREF(coerced2);
1382 goto exit_binary_result_object;
1387 Py_DECREF(coerced1);
1388 Py_DECREF(coerced2);
1392 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
1395 PyObject *coerced1 = operand1;
1396 PyObject *coerced2 = operand2;
1398 int err = c2(&coerced2, &coerced1);
1400 if (unlikely(err < 0)) {
1401 goto exit_binary_exception;
1405 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
1407 if (likely(mv == NULL)) {
1408 binaryfunc slot = mv->nb_divmod;
1410 if (likely(slot != NULL)) {
1411 PyObject *x = slot(coerced1, coerced2);
1413 Py_DECREF(coerced1);
1414 Py_DECREF(coerced2);
1417 goto exit_binary_result_object;
1422 Py_DECREF(coerced1);
1423 Py_DECREF(coerced2);
1429 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'float' and '%s'", type2->tp_name);
1430 goto exit_binary_exception;
1432exit_binary_result_object:
1435exit_binary_exception:
1438static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_OBJECT(PyObject *operand1, PyObject *operand2) {
1439 CHECK_OBJECT(operand1);
1440 assert(PyFloat_CheckExact(operand1));
1441 CHECK_OBJECT(operand2);
1443 PyTypeObject *type2 = Py_TYPE(operand2);
1445 if (&PyFloat_Type == type2) {
1450#if defined(_MSC_VER)
1451#pragma warning(push)
1452#pragma warning(disable : 4101)
1455 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1456 NUITKA_MAY_BE_UNUSED
long clong_result;
1457 NUITKA_MAY_BE_UNUSED
double cfloat_result;
1458#if defined(_MSC_VER)
1462 CHECK_OBJECT(operand1);
1463 assert(PyFloat_CheckExact(operand1));
1464 CHECK_OBJECT(operand2);
1465 assert(PyFloat_CheckExact(operand2));
1467 const double a = PyFloat_AS_DOUBLE(operand1);
1468 const double b = PyFloat_AS_DOUBLE(operand2);
1470 if (unlikely(b == 0.0)) {
1471 PyThreadState *tstate = PyThreadState_GET();
1473 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"float modulo");
1474 goto exit_result_exception;
1478 double mod = fmod(a, b);
1479 double div = (a - mod) / b;
1482 if ((b < 0) != (mod < 0)) {
1487 mod = copysign(0.0, b);
1492 floordiv = floor(div);
1493 if (div - floordiv > 0.5) {
1497 floordiv = copysign(0.0, a / b);
1500 PyObject *r = Py_BuildValue(
"(dd)", floordiv, mod);
1503 goto exit_result_object;
1507 if (unlikely(obj_result == NULL)) {
1508 goto exit_result_exception;
1510 result = obj_result;
1511 goto exit_result_ok;
1516 exit_result_exception:
1520 return __BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_OBJECT(operand1, operand2);
1523PyObject *BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_OBJECT(PyObject *operand1, PyObject *operand2) {
1524 return _BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_OBJECT(operand1, operand2);
1528static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_LONG(PyObject *operand1, PyObject *operand2) {
1529 CHECK_OBJECT(operand1);
1530 assert(PyFloat_CheckExact(operand1));
1531 CHECK_OBJECT(operand2);
1532 assert(PyLong_CheckExact(operand2));
1534#if defined(_MSC_VER)
1535#pragma warning(push)
1536#pragma warning(disable : 4101)
1538 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1539 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1540#if defined(_MSC_VER)
1544 binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_divmod;
1547 if (slot1 != NULL) {
1548 PyObject *x = slot1(operand1, operand2);
1550 if (x != Py_NotImplemented) {
1552 goto exit_binary_result_object;
1555 Py_DECREF_IMMORTAL(x);
1560#if PYTHON_VERSION < 0x300
1561 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'float' and 'long'");
1563 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'float' and 'int'");
1565 goto exit_binary_exception;
1567exit_binary_result_object:
1570exit_binary_exception:
1574PyObject *BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_LONG(PyObject *operand1, PyObject *operand2) {
1575 return _BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_LONG(operand1, operand2);
1579static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_LONG_FLOAT(PyObject *operand1, PyObject *operand2) {
1580 CHECK_OBJECT(operand1);
1581 assert(PyLong_CheckExact(operand1));
1582 CHECK_OBJECT(operand2);
1583 assert(PyFloat_CheckExact(operand2));
1585#if defined(_MSC_VER)
1586#pragma warning(push)
1587#pragma warning(disable : 4101)
1589 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1590 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1591#if defined(_MSC_VER)
1596 binaryfunc slot2 = NULL;
1601 slot2 = PyFloat_Type.tp_as_number->nb_divmod;
1604 if (slot2 != NULL) {
1605 PyObject *x = slot2(operand1, operand2);
1607 if (x != Py_NotImplemented) {
1609 goto exit_binary_result_object;
1612 Py_DECREF_IMMORTAL(x);
1617#if PYTHON_VERSION < 0x300
1618 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'long' and 'float'");
1620 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'int' and 'float'");
1622 goto exit_binary_exception;
1624exit_binary_result_object:
1627exit_binary_exception:
1631PyObject *BINARY_OPERATION_DIVMOD_OBJECT_LONG_FLOAT(PyObject *operand1, PyObject *operand2) {
1632 return _BINARY_OPERATION_DIVMOD_OBJECT_LONG_FLOAT(operand1, operand2);
1635#if PYTHON_VERSION < 0x300
1637static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_INT(PyObject *operand1, PyObject *operand2) {
1638 CHECK_OBJECT(operand1);
1639 assert(PyFloat_CheckExact(operand1));
1640 CHECK_OBJECT(operand2);
1641 assert(PyInt_CheckExact(operand2));
1643#if defined(_MSC_VER)
1644#pragma warning(push)
1645#pragma warning(disable : 4101)
1647 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1648 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1649#if defined(_MSC_VER)
1653 binaryfunc slot1 = PyFloat_Type.tp_as_number->nb_divmod;
1656 if (slot1 != NULL) {
1657 PyObject *x = slot1(operand1, operand2);
1659 if (x != Py_NotImplemented) {
1661 goto exit_binary_result_object;
1664 Py_DECREF_IMMORTAL(x);
1669 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'float' and 'int'");
1670 goto exit_binary_exception;
1672exit_binary_result_object:
1675exit_binary_exception:
1679PyObject *BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_INT(PyObject *operand1, PyObject *operand2) {
1680 return _BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_INT(operand1, operand2);
1684#if PYTHON_VERSION < 0x300
1686static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_INT_FLOAT(PyObject *operand1, PyObject *operand2) {
1687 CHECK_OBJECT(operand1);
1688 assert(PyInt_CheckExact(operand1));
1689 CHECK_OBJECT(operand2);
1690 assert(PyFloat_CheckExact(operand2));
1692#if defined(_MSC_VER)
1693#pragma warning(push)
1694#pragma warning(disable : 4101)
1696 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1697 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1698#if defined(_MSC_VER)
1703 binaryfunc slot2 = NULL;
1708 slot2 = PyFloat_Type.tp_as_number->nb_divmod;
1711 if (slot2 != NULL) {
1712 PyObject *x = slot2(operand1, operand2);
1714 if (x != Py_NotImplemented) {
1716 goto exit_binary_result_object;
1719 Py_DECREF_IMMORTAL(x);
1724 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'int' and 'float'");
1725 goto exit_binary_exception;
1727exit_binary_result_object:
1730exit_binary_exception:
1734PyObject *BINARY_OPERATION_DIVMOD_OBJECT_INT_FLOAT(PyObject *operand1, PyObject *operand2) {
1735 return _BINARY_OPERATION_DIVMOD_OBJECT_INT_FLOAT(operand1, operand2);
1739#if PYTHON_VERSION < 0x300
1741static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
1742 CHECK_OBJECT(operand1);
1743 assert(PyLong_CheckExact(operand1));
1744 CHECK_OBJECT(operand2);
1745 assert(PyInt_CheckExact(operand2));
1747#if defined(_MSC_VER)
1748#pragma warning(push)
1749#pragma warning(disable : 4101)
1751 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1752 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1753#if defined(_MSC_VER)
1757 binaryfunc slot1 = PyLong_Type.tp_as_number->nb_divmod;
1760 if (slot1 != NULL) {
1761 PyObject *x = slot1(operand1, operand2);
1763 if (x != Py_NotImplemented) {
1765 goto exit_binary_result_object;
1768 Py_DECREF_IMMORTAL(x);
1773 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'long' and 'int'");
1774 goto exit_binary_exception;
1776exit_binary_result_object:
1779exit_binary_exception:
1783PyObject *BINARY_OPERATION_DIVMOD_OBJECT_LONG_INT(PyObject *operand1, PyObject *operand2) {
1784 return _BINARY_OPERATION_DIVMOD_OBJECT_LONG_INT(operand1, operand2);
1788#if PYTHON_VERSION < 0x300
1790static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
1791 CHECK_OBJECT(operand1);
1792 assert(PyInt_CheckExact(operand1));
1793 CHECK_OBJECT(operand2);
1794 assert(PyLong_CheckExact(operand2));
1796#if defined(_MSC_VER)
1797#pragma warning(push)
1798#pragma warning(disable : 4101)
1800 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1801 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1802#if defined(_MSC_VER)
1807 binaryfunc slot2 = NULL;
1812 slot2 = PyLong_Type.tp_as_number->nb_divmod;
1815 if (slot2 != NULL) {
1816 PyObject *x = slot2(operand1, operand2);
1818 if (x != Py_NotImplemented) {
1820 goto exit_binary_result_object;
1823 Py_DECREF_IMMORTAL(x);
1828 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): 'int' and 'long'");
1829 goto exit_binary_exception;
1831exit_binary_result_object:
1834exit_binary_exception:
1838PyObject *BINARY_OPERATION_DIVMOD_OBJECT_INT_LONG(PyObject *operand1, PyObject *operand2) {
1839 return _BINARY_OPERATION_DIVMOD_OBJECT_INT_LONG(operand1, operand2);
1843#if PYTHON_VERSION < 0x300
1845static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_INT_CLONG(PyObject *operand1,
long operand2) {
1846 CHECK_OBJECT(operand1);
1847 assert(PyInt_CheckExact(operand1));
1852#if defined(_MSC_VER)
1853#pragma warning(push)
1854#pragma warning(disable : 4101)
1856 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1857 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1858 NUITKA_MAY_BE_UNUSED
long clong_result;
1859 NUITKA_MAY_BE_UNUSED
double cfloat_result;
1860#if defined(_MSC_VER)
1864 CHECK_OBJECT(operand1);
1865 assert(PyInt_CheckExact(operand1));
1867 const long a = PyInt_AS_LONG(operand1);
1868 const long b = operand2;
1870 if (unlikely(b == 0)) {
1871 PyThreadState *tstate = PyThreadState_GET();
1873 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"integer division or modulo by zero");
1874 goto exit_result_exception;
1877 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
1878 long a_div_b = a / b;
1879 long a_mod_b = (long)(a - (
unsigned long)a_div_b * b);
1881 if (a_mod_b && (b ^ a_mod_b) < 0) {
1886 PyObject *r = Py_BuildValue(
"(ll)", a_div_b, a_mod_b);
1888 goto exit_result_object;
1892 PyObject *operand1_object = operand1;
1893 PyObject *operand2_object = Nuitka_PyLong_FromLong(operand2);
1895 PyObject *r = PyLong_Type.tp_as_number->nb_divmod(operand1_object, operand2_object);
1896 assert(r != Py_NotImplemented);
1898 Py_DECREF(operand2_object);
1901 goto exit_result_object;
1905 if (unlikely(obj_result == NULL)) {
1906 goto exit_result_exception;
1908 result = obj_result;
1909 goto exit_result_ok;
1914exit_result_exception:
1918PyObject *BINARY_OPERATION_DIVMOD_OBJECT_INT_CLONG(PyObject *operand1,
long operand2) {
1919 return _BINARY_OPERATION_DIVMOD_OBJECT_INT_CLONG(operand1, operand2);
1923#if PYTHON_VERSION < 0x300
1925static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_CLONG_INT(
long operand1, PyObject *operand2) {
1927 CHECK_OBJECT(operand2);
1928 assert(PyInt_CheckExact(operand2));
1933#if defined(_MSC_VER)
1934#pragma warning(push)
1935#pragma warning(disable : 4101)
1937 NUITKA_MAY_BE_UNUSED
bool cbool_result;
1938 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
1939 NUITKA_MAY_BE_UNUSED
long clong_result;
1940 NUITKA_MAY_BE_UNUSED
double cfloat_result;
1941#if defined(_MSC_VER)
1945 CHECK_OBJECT(operand2);
1946 assert(PyInt_CheckExact(operand2));
1948 const long a = operand1;
1949 const long b = PyInt_AS_LONG(operand2);
1951 if (unlikely(b == 0)) {
1952 PyThreadState *tstate = PyThreadState_GET();
1954 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"integer division or modulo by zero");
1955 goto exit_result_exception;
1958 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
1959 long a_div_b = a / b;
1960 long a_mod_b = (long)(a - (
unsigned long)a_div_b * b);
1962 if (a_mod_b && (b ^ a_mod_b) < 0) {
1967 PyObject *r = Py_BuildValue(
"(ll)", a_div_b, a_mod_b);
1969 goto exit_result_object;
1973 PyObject *operand1_object = Nuitka_PyLong_FromLong(operand1);
1974 PyObject *operand2_object = operand2;
1976 PyObject *r = PyLong_Type.tp_as_number->nb_divmod(operand1_object, operand2_object);
1977 assert(r != Py_NotImplemented);
1979 Py_DECREF(operand1_object);
1982 goto exit_result_object;
1986 if (unlikely(obj_result == NULL)) {
1987 goto exit_result_exception;
1989 result = obj_result;
1990 goto exit_result_ok;
1995exit_result_exception:
1999PyObject *BINARY_OPERATION_DIVMOD_OBJECT_CLONG_INT(
long operand1, PyObject *operand2) {
2000 return _BINARY_OPERATION_DIVMOD_OBJECT_CLONG_INT(operand1, operand2);
2005static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_CFLOAT(PyObject *operand1,
double operand2) {
2006 CHECK_OBJECT(operand1);
2007 assert(PyFloat_CheckExact(operand1));
2011#if defined(_MSC_VER)
2012#pragma warning(push)
2013#pragma warning(disable : 4101)
2016 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2017 NUITKA_MAY_BE_UNUSED
long clong_result;
2018 NUITKA_MAY_BE_UNUSED
double cfloat_result;
2019#if defined(_MSC_VER)
2023 CHECK_OBJECT(operand1);
2024 assert(PyFloat_CheckExact(operand1));
2026 const double a = PyFloat_AS_DOUBLE(operand1);
2027 const double b = operand2;
2029 if (unlikely(b == 0.0)) {
2030 PyThreadState *tstate = PyThreadState_GET();
2032 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"float modulo");
2033 goto exit_result_exception;
2037 double mod = fmod(a, b);
2038 double div = (a - mod) / b;
2041 if ((b < 0) != (mod < 0)) {
2046 mod = copysign(0.0, b);
2051 floordiv = floor(div);
2052 if (div - floordiv > 0.5) {
2056 floordiv = copysign(0.0, a / b);
2059 PyObject *r = Py_BuildValue(
"(dd)", floordiv, mod);
2062 goto exit_result_object;
2066 if (unlikely(obj_result == NULL)) {
2067 goto exit_result_exception;
2069 result = obj_result;
2070 goto exit_result_ok;
2075exit_result_exception:
2079PyObject *BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_CFLOAT(PyObject *operand1,
double operand2) {
2080 return _BINARY_OPERATION_DIVMOD_OBJECT_FLOAT_CFLOAT(operand1, operand2);
2084static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_CFLOAT_FLOAT(
double operand1, PyObject *operand2) {
2086 CHECK_OBJECT(operand2);
2087 assert(PyFloat_CheckExact(operand2));
2091#if defined(_MSC_VER)
2092#pragma warning(push)
2093#pragma warning(disable : 4101)
2096 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2097 NUITKA_MAY_BE_UNUSED
long clong_result;
2098 NUITKA_MAY_BE_UNUSED
double cfloat_result;
2099#if defined(_MSC_VER)
2103 CHECK_OBJECT(operand2);
2104 assert(PyFloat_CheckExact(operand2));
2106 const double a = operand1;
2107 const double b = PyFloat_AS_DOUBLE(operand2);
2109 if (unlikely(b == 0.0)) {
2110 PyThreadState *tstate = PyThreadState_GET();
2112 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"float modulo");
2113 goto exit_result_exception;
2117 double mod = fmod(a, b);
2118 double div = (a - mod) / b;
2121 if ((b < 0) != (mod < 0)) {
2126 mod = copysign(0.0, b);
2131 floordiv = floor(div);
2132 if (div - floordiv > 0.5) {
2136 floordiv = copysign(0.0, a / b);
2139 PyObject *r = Py_BuildValue(
"(dd)", floordiv, mod);
2142 goto exit_result_object;
2146 if (unlikely(obj_result == NULL)) {
2147 goto exit_result_exception;
2149 result = obj_result;
2150 goto exit_result_ok;
2155exit_result_exception:
2159PyObject *BINARY_OPERATION_DIVMOD_OBJECT_CFLOAT_FLOAT(
double operand1, PyObject *operand2) {
2160 return _BINARY_OPERATION_DIVMOD_OBJECT_CFLOAT_FLOAT(operand1, operand2);
2164static PyObject *_BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2165 CHECK_OBJECT(operand1);
2166 CHECK_OBJECT(operand2);
2168#if PYTHON_VERSION < 0x300
2169 if (PyInt_CheckExact(operand1) && PyInt_CheckExact(operand2)) {
2173#if defined(_MSC_VER)
2174#pragma warning(push)
2175#pragma warning(disable : 4101)
2177 NUITKA_MAY_BE_UNUSED
bool cbool_result;
2178 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2179 NUITKA_MAY_BE_UNUSED
long clong_result;
2180 NUITKA_MAY_BE_UNUSED
double cfloat_result;
2181#if defined(_MSC_VER)
2185 CHECK_OBJECT(operand1);
2186 assert(PyInt_CheckExact(operand1));
2187 CHECK_OBJECT(operand2);
2188 assert(PyInt_CheckExact(operand2));
2190 const long a = PyInt_AS_LONG(operand1);
2191 const long b = PyInt_AS_LONG(operand2);
2193 if (unlikely(b == 0)) {
2194 PyThreadState *tstate = PyThreadState_GET();
2196 SET_CURRENT_EXCEPTION_TYPE0_STR(tstate, PyExc_ZeroDivisionError,
"integer division or modulo by zero");
2197 goto exit_result_exception;
2200 if (likely(b != -1 || !UNARY_NEG_WOULD_OVERFLOW(a))) {
2201 long a_div_b = a / b;
2202 long a_mod_b = (long)(a - (
unsigned long)a_div_b * b);
2204 if (a_mod_b && (b ^ a_mod_b) < 0) {
2209 PyObject *r = Py_BuildValue(
"(ll)", a_div_b, a_mod_b);
2211 goto exit_result_object;
2215 PyObject *operand1_object = operand1;
2216 PyObject *operand2_object = operand2;
2218 PyObject *r = PyLong_Type.tp_as_number->nb_divmod(operand1_object, operand2_object);
2219 assert(r != Py_NotImplemented);
2222 goto exit_result_object;
2226 if (unlikely(obj_result == NULL)) {
2227 goto exit_result_exception;
2229 result = obj_result;
2230 goto exit_result_ok;
2235 exit_result_exception:
2240 PyTypeObject *type1 = Py_TYPE(operand1);
2241 PyTypeObject *type2 = Py_TYPE(operand2);
2243#if defined(_MSC_VER)
2244#pragma warning(push)
2245#pragma warning(disable : 4101)
2247 NUITKA_MAY_BE_UNUSED
bool cbool_result;
2248 NUITKA_MAY_BE_UNUSED PyObject *obj_result;
2249#if defined(_MSC_VER)
2254 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_divmod : NULL;
2255 binaryfunc slot2 = NULL;
2257 if (!(type1 == type2)) {
2260 slot2 = (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_divmod : NULL;
2262 if (slot1 == slot2) {
2267 if (slot1 != NULL) {
2268 if (slot2 != NULL) {
2269 if (Nuitka_Type_IsSubtype(type2, type1)) {
2270 PyObject *x = slot2(operand1, operand2);
2272 if (x != Py_NotImplemented) {
2274 goto exit_binary_result_object;
2277 Py_DECREF_IMMORTAL(x);
2282 PyObject *x = slot1(operand1, operand2);
2284 if (x != Py_NotImplemented) {
2286 goto exit_binary_result_object;
2289 Py_DECREF_IMMORTAL(x);
2292 if (slot2 != NULL) {
2293 PyObject *x = slot2(operand1, operand2);
2295 if (x != Py_NotImplemented) {
2297 goto exit_binary_result_object;
2300 Py_DECREF_IMMORTAL(x);
2303#if PYTHON_VERSION < 0x300
2304 if (!NEW_STYLE_NUMBER_TYPE(type1) || !NEW_STYLE_NUMBER_TYPE(type2)) {
2306 (type1->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type1)) ? type1->tp_as_number->nb_coerce : NULL;
2309 PyObject *coerced1 = operand1;
2310 PyObject *coerced2 = operand2;
2312 int err = c1(&coerced1, &coerced2);
2314 if (unlikely(err < 0)) {
2315 goto exit_binary_exception;
2319 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2321 if (likely(mv == NULL)) {
2322 binaryfunc slot = mv->nb_divmod;
2324 if (likely(slot != NULL)) {
2325 PyObject *x = slot(coerced1, coerced2);
2327 Py_DECREF(coerced1);
2328 Py_DECREF(coerced2);
2331 goto exit_binary_result_object;
2336 Py_DECREF(coerced1);
2337 Py_DECREF(coerced2);
2341 (type2->tp_as_number != NULL && NEW_STYLE_NUMBER_TYPE(type2)) ? type2->tp_as_number->nb_coerce : NULL;
2344 PyObject *coerced1 = operand1;
2345 PyObject *coerced2 = operand2;
2347 int err = c2(&coerced2, &coerced1);
2349 if (unlikely(err < 0)) {
2350 goto exit_binary_exception;
2354 PyNumberMethods *mv = Py_TYPE(coerced1)->tp_as_number;
2356 if (likely(mv == NULL)) {
2357 binaryfunc slot = mv->nb_divmod;
2359 if (likely(slot != NULL)) {
2360 PyObject *x = slot(coerced1, coerced2);
2362 Py_DECREF(coerced1);
2363 Py_DECREF(coerced2);
2366 goto exit_binary_result_object;
2371 Py_DECREF(coerced1);
2372 Py_DECREF(coerced2);
2378 PyErr_Format(PyExc_TypeError,
"unsupported operand type(s) for divmod(): '%s' and '%s'", type1->tp_name,
2380 goto exit_binary_exception;
2382exit_binary_result_object:
2385exit_binary_exception:
2389PyObject *BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_OBJECT(PyObject *operand1, PyObject *operand2) {
2390 return _BINARY_OPERATION_DIVMOD_OBJECT_OBJECT_OBJECT(operand1, operand2);