8000 MAINT: Try instead using the inverse logic · numpy/numpy@0fe5dcb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0fe5dcb

Browse files
committed
MAINT: Try instead using the inverse logic
1 parent 5d3e85d commit 0fe5dcb

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

numpy/core/src/npymath/npy_math_internal.h.src

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -632,35 +632,33 @@ NPY_INPLACE @type@
632632
npy_remainder@c@(@type@ a, @type@ b)
633633
{
634634
@type@ mod;
635-
if (b) {
635+
if (!b) {
636+
/*
637+
* b == 0 or is NaN. `fmod` will return the right thing (NaN)
638+
* but set the error flags correct (divmod may set too many).
639+
* (Using !b here, since reverse logic set incorrect flags on clang)
640+
*/
641+
return npy_fmod@c@(a, b);
642+
}
643+
else {
636644
npy_divmod@c@(a, b, &mod);
637645
return mod;
638646
}
639-
/*
640-
* in2 == 0 (and not NaN). The result is always NaN here, and we need to
641-
* set the invalid flag if a is not NaN. We should be able to use the
642-
* normal fmod, but clang seems to optimize the warning flags away.
643-
*/
644-
if (!npy_isnan(a)) {
645-
npy_set_floatstatus_invalid();
646-
}
647-
return (@type@)NPY_NAN;
648647
}
649648

650649
NPY_INPLACE @type@
651650
npy_floor_divide@c@(@type@ a, @type@ b) {
652651
@type@ mod;
653-
if (b) {
654-
return npy_divmod@c@(a, b, &mod);
655-
}
656-
else {
652+
if (!b) {
657653
/*
658-
* in2 == 0 (and not NaN), normal division will give the correct
659-
* result (which could be Inf or NaN) and set the correct CPU
660-
* floating point error flag.
654+
* b == 0 or is NaN. Division will return the right thing (Inf or NaN)
655+
* but set the error flags correct (divmod may set too many).
661656
*/
662657
return a / b;
663658
}
659+
else {
660+
return npy_divmod@c@(a, b, &mod);
661+
}
664662
}
665663

666664
/*

0 commit comments

Comments
 (0)
0