mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-20 08:39:37 +08:00
Adjust overflow threshold bound for pow tests.
This commit is contained in:
parent
3e44f960ed
commit
69f50e3a67
@ -129,15 +129,15 @@ void pow_test() {
|
|||||||
template <typename Scalar, typename ScalarExponent>
|
template <typename Scalar, typename ScalarExponent>
|
||||||
Scalar calc_overflow_threshold(const ScalarExponent exponent) {
|
Scalar calc_overflow_threshold(const ScalarExponent exponent) {
|
||||||
EIGEN_USING_STD(exp2);
|
EIGEN_USING_STD(exp2);
|
||||||
|
EIGEN_USING_STD(log2);
|
||||||
EIGEN_STATIC_ASSERT((NumTraits<Scalar>::digits() < 2 * NumTraits<double>::digits()), BASE_TYPE_IS_TOO_BIG);
|
EIGEN_STATIC_ASSERT((NumTraits<Scalar>::digits() < 2 * NumTraits<double>::digits()), BASE_TYPE_IS_TOO_BIG);
|
||||||
|
|
||||||
if (exponent < 2)
|
if (exponent < 2)
|
||||||
return NumTraits<Scalar>::highest();
|
return NumTraits<Scalar>::highest();
|
||||||
else {
|
else {
|
||||||
const double max_exponent = static_cast<double>(NumTraits<Scalar>::digits());
|
// base^e <= highest ==> base <= 2^(log2(highest)/e)
|
||||||
const double clamped_exponent = exponent < max_exponent ? static_cast<double>(exponent) : max_exponent;
|
return static_cast<Scalar>(
|
||||||
const double threshold = exp2(max_exponent / clamped_exponent);
|
numext::floor(exp2(log2(NumTraits<Scalar>::highest()) / static_cast<double>(exponent))));
|
||||||
return static_cast<Scalar>(threshold);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user