@@ -632,35 +632,33 @@ NPY_INPLACE @type@
632
632
npy_remainder @c @(@type @ a , @type @ b )
633
633
{
634
634
@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 {
636
644
npy_divmod @c @(a , b , & mod );
637
645
return mod ;
638
646
}
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 ;
648
647
}
649
648
650
649
NPY_INPLACE @type @
651
650
npy_floor_divide @c @(@type @ a , @type @ b ) {
652
651
@type @ mod ;
653
- if (b ) {
654
- return npy_divmod @c @(a , b , & mod );
655
- }
656
- else {
652
+ if (!b ) {
657
653
/*
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).
661
656
*/
662
657
return a / b ;
663
658
}
659
+ else {
660
+ return npy_divmod @c @(a , b , & mod );
661
+ }
664
662
}
665
663
666
664
/*
0 commit comments