From 3912ca0d5388fc58853d2fd8f1773e920f55523b Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Mon, 13 Jul 2015 11:14:59 -0700 Subject: Fixed a bug in the integer division code that caused some large numerators to be incorrectly handled --- unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h') diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h b/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h index 4c5e784c9..47fefff92 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h @@ -62,8 +62,11 @@ struct TensorIntDivisor { // fast ln2 const int leading_zeros = count_leading_zeros(divider); - const int log_div = N - (leading_zeros+1); - + int log_div = N - leading_zeros; + // If divider is a power of two then log_div is 1 more than it should be. + if ((1ull << (log_div-1)) == divider) { + log_div--; + } multiplier = (static_cast(1) << (N+log_div)) / divider - (static_cast(1) << N) + 1; shift1 = log_div > 1 ? 1 : log_div; shift2 = log_div > 1 ? log_div-1 : 0; -- cgit v1.2.3