Skip to content

Commit

Permalink
Merge pull request #19994 from charris/backport-19974
Browse files Browse the repository at this point in the history
BUG: np.tan(np.inf) test failure
  • Loading branch information
charris committed Sep 29, 2021
2 parents 51b7c50 + d169a12 commit c3de0e6
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions numpy/core/src/npymath/npy_math_internal.h.src
Expand Up @@ -483,21 +483,40 @@ NPY_INPLACE @type@ npy_frexp@c@(@type@ x, int* exp)
* #c = l,,f#
* #C = L,,F#
*/

/*
* On arm64 macOS, there's a bug with sin, cos, and tan where they don't
* raise "invalid" when given INFINITY as input.
*/
#if defined(__APPLE__) && defined(__arm64__)
#define WORKAROUND_APPLE_TRIG_BUG 1
#else
#define WORKAROUND_APPLE_TRIG_BUG 0
#endif

/**begin repeat1
* #kind = sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,rint,trunc,sqrt,log10,
* log,exp,expm1,asin,acos,atan,asinh,acosh,atanh,log1p,exp2,log2#
* #KIND = SIN,COS,TAN,SINH,COSH,TANH,FABS,FLOOR,CEIL,RINT,TRUNC,SQRT,LOG10,
* LOG,EXP,EXPM1,ASIN,ACOS,ATAN,ASINH,ACOSH,ATANH,LOG1P,EXP2,LOG2#
* #TRIG_WORKAROUND = WORKAROUND_APPLE_TRIG_BUG*3, 0*22#
*/
#ifdef HAVE_@KIND@@C@
NPY_INPLACE @type@ npy_@kind@@c@(@type@ x)
{
#if @TRIG_WORKAROUND@
if (!npy_isfinite(x)) {
return (x - x);
}
#endif
return @kind@@c@(x);
}
#endif

/**end repeat1**/

#undef WORKAROUND_APPLE_TRIG_BUG

/**begin repeat1
* #kind = atan2,hypot,pow,copysign#
* #KIND = ATAN2,HYPOT,POW,COPYSIGN#
Expand Down

0 comments on commit c3de0e6

Please sign in to comment.