@@ -398,8 +398,8 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
398
398
/**end repeat1**/
399
399
400
400
/**begin repeat1
401
- * #kind = atan2,hypot,pow,copysign#
402
- * #KIND = ATAN2,HYPOT,POW,COPYSIGN#
401
+ * #kind = atan2,hypot,pow,fmod, copysign#
402
+ * #KIND = ATAN2,HYPOT,POW,FMOD, COPYSIGN#
403
403
*/
404
404
#ifdef @kind @@c @
405
405
#undef @kind@@c@
@@ -412,29 +412,6 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
412
412
#endif
413
413
/**end repeat1**/
414
414
415
- /**begin repeat1
416
- * #kind = fmod#
417
- * #KIND = FMOD#
418
- */
419
- #ifdef @kind @@c @
420
- #undef @kind@@c@
421
- #endif
422
- #ifndef HAVE_MODF @C @
423
- NPY_INPLACE @type @
424
- npy_ @kind @@c @(@type @ x , @type @ y )
425
- {
426
- int are_inputs_inf = (npy_isinf (x ) && npy_isinf (y ));
427
-
428
- if (are_inputs_inf || !y ) {
429
- if (!npy_isnan (x )) {
430
- npy_set_floatstatus_invalid ();
431
- }
432
- }
433
- return (@type @) npy_ @kind @((double )x , (double ) y );
434
- }
435
- #endif
436
- /**end repeat1**/
437
-
438
415
#ifdef modf @c @
439
416
#undef modf@c@
440
417
#endif
@@ -496,8 +473,8 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
496
473
/**end repeat1**/
497
474
498
475
/**begin repeat1
499
- * #kind = atan2,hypot,pow,copysign#
500
- * #KIND = ATAN2,HYPOT,POW,COPYSIGN#
476
+ * #kind = atan2,hypot,pow,fmod, copysign#
477
+ * #KIND = ATAN2,HYPOT,POW,FMOD, COPYSIGN#
501
478
*/
502
479
#ifdef HAVE_ @KIND @@C @
503
480
NPY_INPLACE @type @ npy_ @kind @@c @(@type @ x , @type @ y )
@@ -507,26 +484,6 @@ NPY_INPLACE @type@ npy_@kind@@c@(@type@ x, @type@ y)
507
484
#endif
508
485
/**end repeat1**/
509
486
510
- /**begin repeat1
511
- * #kind = fmod#
512
- * #KIND = FMOD#
513
- */
514
- #ifdef HAVE_FMOD @C @
515
- NPY_INPLACE @type @
516
- npy_ @kind @@c @(@type @ x , @type @ y )
517
- {
518
- int are_inputs_inf = (npy_isinf (x ) && npy_isinf (y ));
519
-
520
- if (are_inputs_inf || !y ) {
521
- if (!npy_isnan (x )) {
522
- npy_set_floatstatus_invalid ();
523
- }
524
- }
525
- return @kind @@c @(x , y );
526
- }
527
- #endif
528
- /**end repeat1**/
529
-
530
487
#ifdef HAVE_MODF @C @
531
488
NPY_INPLACE @type @ npy_modf @c @(@type @ x , @type @ * iptr )
532
489
{
@@ -676,25 +633,32 @@ npy_remainder@c@(@type@ a, @type@ b)
676
633
{
677
634
@type @ mod ;
678
635
if (NPY_UNLIKELY (!b )) {
636
+ /*
637
+ * in2 == 0 (and not NaN): normal fmod will give the correct
638
+ * result (always NaN). `divmod` may set additional FPE for the
639
+ * division by zero creating an inf.
640
+ */
679
641
mod = npy_fmod @c @(a , b );
680
- } else {
642
+ }
643
+ else {
681
644
npy_divmod @c @(a , b , & mod );
682
645
}
683
646
return mod ;
684
647
}
685
648
686
649
NPY_INPLACE @type @
687
650
npy_floor_divide @c @(@type @ a , @type @ b ) {
688
- @type @ div , mod ;
651
+ @type @ mod ;
689
652
if (NPY_UNLIKELY (!b )) {
653
+ /*
654
+ * in2 == 0 (and not NaN): normal division will give the correct
655
+ * result (Inf or NaN). `divmod` may set additional FPE for the modulo
656
+ * evaluating to NaN.
657
+ */
690
658
div = a / b ;
691
- if (!a || npy_isnan (a )) {
692
- npy_set_floatstatus_invalid ();
693
- } else {
694
- npy_set_flo
F438
atstatus_divbyzero ();
695
- }
696
- } else {
697
- div = npy_divmod @c @(a , b , & mod );
659
+ }
660
+ else {
661
+ div = npy_divmod @c @(a , b , & mod );;
698
662
}
699
663
return div ;
700
664
}
@@ -711,21 +675,17 @@ npy_divmod@c@(@type@ a, @type@ b, @type@ *modulus)
711
675
712
676
mod = npy_fmod @c @(a , b );
713
677
if (NPY_UNLIKELY (!b )) {
714
- div = a / b ;
715
- if (a && !npy_isnan (a )) {
716
- npy_set_floatstatus_divbyzero ();
717
- }
718
- /* If b == 0, return result of fmod. For IEEE is nan */
678
+ /* b == 0 (not NaN): return result of fmod. For IEEE is nan */
719
679
* modulus = mod ;
720
- return div ;
680
+ return a / b ;
721
681
}
722
682
723
683
/* a - mod should be very nearly an integer multiple of b */
724
684
div = (a - mod ) / b ;
725
685
726
686
/* adjust fmod result to conform to Python convention of remainder */
727
687
if (mod ) {
728
- if (( b < 0 ) != (mod < 0 )) {
688
+ if (isless ( b , 0 ) != isless (mod , 0 )) {
729
689
mod += b ;
730
690
div -= 1.0 @c @;
731
691
}
@@ -738,7 +698,7 @@ npy_divmod@c@(@type@ a, @type@ b, @type@ *modulus)
738
698
/* snap quotient to nearest integral value */
739
699
if (div ) {
740
700
floordiv = npy_floor @c @(div );
741
- if (div - floordiv > 0.5 @c @)
701
+ if (isgreater ( div - floordiv , 0.5 @c @) )
742
702
floordiv += 1.0 @c @;
743
703
}
744
704
else {
0 commit comments