|
Ublas : |
Subject: [ublas] functional.hpp signed unsigned div bug?
From: Robin Palotai (palotai.robin_at_[hidden])
Date: 2010-11-15 07:15:42
Hello,
In functional.hpp at a couple of places, for example:
static
BOOST_UBLAS_INLINE
difference_type distance_i (difference_type k, size_type /* size_i */, size_type size_j) {
return size_j != 0 ? k / size_j : 0;
}
k [/|%] size_[i|j] is used, where k is difference_type (signed), size_x
is size_type (unsigned). This results in promoting k to unsigned, and
can yield very strange results when k is negative. For example, m being
a size 2x2 ublas::matrix, m.begin1() - m.end1() yields 2147483646 instad
of -2. Putting a static_cast<difference_type>(size_x) in functional.hpp
seems to solve the problem.
Is this known / intended? If so, what is the rationale? If it is a bug,
is this a valid workaround?
BR,
Robin