@@ -483,21 +483,40 @@ NPY_INPLACE @type@ npy_frexp@c@(@type@ x, int* exp)
483
483
* #c = l,,f#
484
484
* #C = L,,F#
485
485
*/
486
+
487
+ /*
488
+ * On arm64 macOS, there's a bug with sin, cos, and tan where they don't
489
+ * raise "invalid" when given INFINITY as input.
490
+ */
491
+ #if defined(__APPLE__ ) && defined(__arm64__ )
492
+ #define WORKAROUND_APPLE_TRIG_BUG 1
493
+ #else
494
+ #define WORKAROUND_APPLE_TRIG_BUG 0
495
+ #endif
496
+
486
497
/**begin repeat1
487
498
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
488
499
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
489
500
* #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
490
501
* LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2#
502
+ * #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*22#
491
503
*/
492
504
#ifdef HAVE_ @KIND @@C @
493
505
NPY_INPLACE @type @ npy_ @kind @@c @(@type @ x )
494
506
{
507
+ #if @TRIG_WORKAROUND @
508
+ if (!npy_isfinite (x )) {
509
+ return (x - x );
510
+ }
511
+ #endif
495
512
return @kind @@c @(x );
496
513
}
497
514
#endif
498
515
499
516
/**end repeat1**/
500
517
518
+ #undef WORKAROUND_APPLE_TRIG_BUG
519
+
501
520
/**begin repeat1
502
521
* #kind = atan2,hypot,pow,copysign#
503
522
* #KIND = ATAN2,HYPOT,POW,COPYSIGN#
0 commit comments