aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
diff options
context:
space:
mode:
authorGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-07-13 11:14:59 -0700
committerGravatar Benoit Steiner <benoit.steiner.goog@gmail.com>2015-07-13 11:14:59 -0700
commit3912ca0d5388fc58853d2fd8f1773e920f55523b (patch)
tree463f6de4bbe1e32ec562ff3381888d0f3344045d /unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h
parentea8756156406e928d8783940d3174d2db0a88986 (diff)
Fixed a bug in the integer division code that caused some large numerators to be incorrectly handled
Diffstat (limited to 'unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h')
-rw-r--r--unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h7
1 files changed, 5 insertions, 2 deletions
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<uint64_t>(1) << (N+log_div)) / divider - (static_cast<uint64_t>(1) << N) + 1;
shift1 = log_div > 1 ? 1 : log_div;
shift2 = log_div > 1 ? log_div-1 : 0;