From c15b386203af5d9f0553ceb1404780282a651271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 14 Feb 2023 18:30:58 +0000 Subject: [PATCH] Fix MSVC atan2 test. --- test/array_cwise.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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