diff --git a/unsupported/test/special_packetmath.cpp b/unsupported/test/special_packetmath.cpp index 044ce671e..1a53a09ff 100644 --- a/unsupported/test/special_packetmath.cpp +++ b/unsupported/test/special_packetmath.cpp @@ -12,6 +12,20 @@ #include "packetmath_test_shared.h" #include "../Eigen/SpecialFunctions" +#if EIGEN_ARCH_ARM +// Note: 32-bit arm always flushes subnormals to zero. +#define MAYBE_FLUSH(op) \ + [](Scalar x) { \ + Scalar y = static_cast(op(x)); \ + if (Eigen::numext::abs(y) < (std::numeric_limits::min)()) { \ + y = y * decltype(y)(0); /* Preserve sign. */ \ + } \ + return y; \ + } +#else +#define MAYBE_FLUSH(op) op +#endif + template void packetmath_real() { using std::abs; @@ -119,7 +133,7 @@ void packetmath_real() { CHECK_CWISE1_IF(internal::packet_traits::HasErf, std::erf, internal::perf); // FIXME(rmlarsen): This test occasionally fails due to difference in tiny subnormal results // near the underflow boundary. I am not sure which version is correct. - CHECK_CWISE1_IF(internal::packet_traits::HasErfc, std::erfc, internal::perfc); + CHECK_CWISE1_IF(internal::packet_traits::HasErfc, MAYBE_FLUSH(std::erfc), internal::perfc); #endif }