diff --git a/test/array_cwise.cpp b/test/array_cwise.cpp index 1e361aa29..b55723de4 100644 --- a/test/array_cwise.cpp +++ b/test/array_cwise.cpp @@ -100,7 +100,18 @@ void binary_ops_test() { [](const auto& x, const auto& y) { return std::pow(x, y); }); binary_op_test("atan2", [](const auto& x, const auto& y) { return Eigen::atan2(x, y); }, - [](const auto& x, const auto& y) { return std::atan2(x, y); }); + [](const auto& x, const auto& y) { + auto t = std::atan2(x, y); +#if EIGEN_COMP_MSVC + // Work around MSVC return value on underflow. + // |atan(y/x)| is bounded above by |y/x|, so on underflow return y/x according to POSIX spec. + // MSVC otherwise returns denorm_min. + if (EIGEN_PREDICT_FALSE(std::abs(t) == std::numeric_limits::denorm_min())) { + return x/y; + } +#endif + return t; + }); } template