Browse Source

Math: use a more common integer rounding calculation in BitVector.

The

    (size - 1)/8 + 1

expression is the same as

    (size - 1)/8 + 8/8

which is the same as the following in all cases except when size == 0,
for which it underflows:

    (size - 1 + 8)/8 == (size + 7)/8

To avoid needless surprises, I'm changing to what's used everywhere
else, including the BitArray, and also reusing the already-calculated
value for the _data array size.
pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
e5844b23b7
  1. 4
      src/Magnum/Math/BitVector.h

4
src/Magnum/Math/BitVector.h

@ -88,7 +88,7 @@ template<std::size_t size> class BitVector {
public:
enum: std::size_t {
Size = size, /**< Vector size */
DataSize = (size-1)/8+1 /**< Vector storage size */
DataSize = (size + 7)/8 /**< Vector storage size */
};
/**
@ -303,7 +303,7 @@ template<std::size_t size> class BitVector {
/* Implementation for Vector<size, T>::Vector(U) */
template<std::size_t ...sequence> constexpr explicit BitVector(Corrade::Containers::Implementation::Sequence<sequence...>, UnsignedByte value): _data{Implementation::repeat(value, sequence)...} {}
UnsignedByte _data[(size-1)/8+1];
UnsignedByte _data[DataSize];
};
#ifndef CORRADE_NO_DEBUG

Loading…
Cancel
Save