From 69f50e3a6732e854623695df273d0940db346ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20S=C3=A1nchez?= Date: Tue, 6 Sep 2022 19:53:29 +0000 Subject: [PATCH] Adjust overflow threshold bound for pow tests. --- test/array_cwise.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/array_cwise.cpp b/test/array_cwise.cpp index 502d1cc9d..5b1c08fea 100644 --- a/test/array_cwise.cpp +++ b/test/array_cwise.cpp @@ -129,15 +129,15 @@ void pow_test() { template Scalar calc_overflow_threshold(const ScalarExponent exponent) { EIGEN_USING_STD(exp2); + EIGEN_USING_STD(log2); EIGEN_STATIC_ASSERT((NumTraits::digits() < 2 * NumTraits::digits()), BASE_TYPE_IS_TOO_BIG); if (exponent < 2) return NumTraits::highest(); else { - const double max_exponent = static_cast(NumTraits::digits()); - const double clamped_exponent = exponent < max_exponent ? static_cast(exponent) : max_exponent; - const double threshold = exp2(max_exponent / clamped_exponent); - return static_cast(threshold); + // base^e <= highest ==> base <= 2^(log2(highest)/e) + return static_cast( + numext::floor(exp2(log2(NumTraits::highest()) / static_cast(exponent)))); } }