@@ -2416,16 +2416,25 @@ binary_op_fail_kind(int oparg, PyObject *lhs, PyObject *rhs)
2416
2416
2417
2417
/* float-long */
2418
2418
2419
- static int
2419
+ static inline int
2420
2420
float_compactlong_guard (PyObject * lhs , PyObject * rhs )
2421
2421
{
2422
2422
return (
2423
2423
PyFloat_CheckExact (lhs ) &&
2424
+ !isnan (PyFloat_AsDouble (lhs )) &&
2424
2425
PyLong_CheckExact (rhs ) &&
2425
2426
_PyLong_IsCompact ((PyLongObject * )rhs )
2426
2427
);
2427
2428
}
2428
2429
2430
+ static inline int
2431
+ nonzero_float_compactlong_guard (PyObject * lhs , PyObject * rhs )
2432
+ {
2433
+ return (
2434
+ float_compactlong_guard (lhs , rhs ) && !PyLong_IsZero (rhs )
2435
+ );
2436
+ }
2437
+
2429
2438
#define FLOAT_LONG_ACTION (NAME , OP ) \
2430
2439
static PyObject * \
2431
2440
(NAME)(PyObject *lhs, PyObject *rhs) \
@@ -2442,13 +2451,22 @@ FLOAT_LONG_ACTION(float_compactlong_true_div, /)
2442
2451
2443
2452
/* long-float */
2444
2453
2445
- static int
2454
+ static inline int
2446
2455
compactlong_float_guard (PyObject * lhs , PyObject * rhs )
2447
2456
{
2448
2457
return (
2449
- PyFloat_CheckExact (rhs ) &&
2450
2458
PyLong_CheckExact (lhs ) &&
2451
- _PyLong_IsCompact ((PyLongObject * )lhs )
2459
+ _PyLong_IsCompact ((PyLongObject * )lhs ) &&
2460
+ PyFloat_CheckExact (rhs ) &&
2461
+ !isnan (PyFloat_AsDouble (rhs ))
2462
+ );
2463
+ }
2464
+
2465
+ static inline int
2466
+ nonzero_compactlong_float_guard (PyObject * lhs , PyObject * rhs )
2467
+ {
2468
+ return (
2469
+ compactlong_float_guard (lhs , rhs ) && PyFloat_AsDouble (rhs ) != 0.0
2452
2470
);
2453
2471
}
2454
2472
@@ -2469,14 +2487,14 @@ LONG_FLOAT_ACTION(compactlong_float_true_div, /)
2469
2487
static _PyBinaryOpSpecializationDescr float_compactlong_specs [NB_OPARG_LAST + 1 ] = {
2470
2488
[NB_ADD ] = {float_compactlong_guard , float_compactlong_add },
2471
2489
[NB_SUBTRACT ] = {float_compactlong_guard , float_compactlong_subtract },
2472
- [NB_TRUE_DIVIDE ] = {float_compactlong_guard , float_compactlong_true_div },
2490
+ [NB_TRUE_DIVIDE ] = {nonzero_float_compactlong_guard , float_compactlong_true_div },
2473
2491
[NB_MULTIPLY ] = {float_compactlong_guard , float_compactlong_multiply },
2474
2492
};
2475
2493
2476
2494
static _PyBinaryOpSpecializationDescr compactlong_float_specs [NB_OPARG_LAST + 1 ] = {
2477
2495
[NB_ADD ] = {compactlong_float_guard , compactlong_float_add },
2478
2496
[NB_SUBTRACT ] = {compactlong_float_guard , compactlong_float_subtract },
2479
- [NB_TRUE_DIVIDE ] = {compactlong_float_guard , compactlong_float_true_div },
2497
+ [NB_TRUE_DIVIDE ] = {nonzero_compactlong_float_guard , compactlong_float_true_div },
2480
2498
[NB_MULTIPLY ] = {compactlong_float_guard , compactlong_float_multiply },
2481
2499
};
2482
2500
0 commit comments