diff --git a/Numeric/BitSpread.hpp b/Numeric/BitSpread.hpp index 56553aff1..220ebacab 100644 --- a/Numeric/BitSpread.hpp +++ b/Numeric/BitSpread.hpp @@ -16,7 +16,7 @@ namespace Numeric { /// keeping the least-significant bit in its original position. /// /// i.e. if @c input is abcdefgh then the result is 0a0b0c0d0e0f0g0h -constexpr uint16_t spread_bits(uint8_t input) { +constexpr uint16_t spread_bits(const uint8_t input) { uint16_t result = uint16_t(input); // 0000 0000 abcd efgh result = (result | (result << 4)) & 0x0f0f; // 0000 abcd 0000 efgh result = (result | (result << 2)) & 0x3333; // 00ab 00cd 00ef 00gh @@ -26,11 +26,12 @@ constexpr uint16_t spread_bits(uint8_t input) { /// Performs the opposite action to @c spread_bits; given the 16-bit input /// @c abcd @c efgh @c ijkl @c mnop, returns the byte value @c bdfhjlnp /// i.e. every other bit is retained, keeping the least-significant bit in place. -constexpr uint8_t unspread_bits(uint16_t input) { - input &= 0x5555; // 0a0b 0c0d 0e0f 0g0h - input = (input | (input >> 1)) & 0x3333; // 00ab 00cd 00ef 00gh - input = (input | (input >> 2)) & 0x0f0f; // 0000 abcd 0000 efgh - return uint8_t(input | (input >> 4)); // 0000 0000 abcd efgh +constexpr uint8_t unspread_bits(const uint16_t input) { + uint16_t result = input; + result &= 0x5555; // 0a0b 0c0d 0e0f 0g0h + result = (result | (result >> 1)) & 0x3333; // 00ab 00cd 00ef 00gh + result = (result | (result >> 2)) & 0x0f0f; // 0000 abcd 0000 efgh + return uint8_t(result | (result >> 4)); // 0000 0000 abcd efgh } } diff --git a/Numeric/LFSR.hpp b/Numeric/LFSR.hpp index f2cf4f7d8..58f0959f6 100644 --- a/Numeric/LFSR.hpp +++ b/Numeric/LFSR.hpp @@ -61,7 +61,7 @@ public: An initial value of 0 is invalid. */ - LFSR(IntType initial_value) : value_(initial_value) {} + LFSR(const IntType initial_value) : value_(initial_value) {} /*! Advances the LSFR, returning either an @c IntType of value @c 1 or @c 0, diff --git a/Numeric/NumericCoder.hpp b/Numeric/NumericCoder.hpp index 6644a5ead..10252b6db 100644 --- a/Numeric/NumericCoder.hpp +++ b/Numeric/NumericCoder.hpp @@ -30,13 +30,13 @@ namespace Numeric { template class NumericCoder { public: /// Modifies @c target to hold @c value at @c index. - template static void encode(int &target, int value) { + template static void encode(int &target, const int value) { static_assert(index < sizeof...(Sizes), "Index must be within range"); NumericEncoder::template encode(target, value); } /// @returns The value from @c source at @c index. - template static int decode(int source) { + template static int decode(const int source) { static_assert(index < sizeof...(Sizes), "Index must be within range"); return NumericDecoder::template decode(source); } @@ -45,7 +45,7 @@ private: template struct NumericEncoder { - template static void encode(int &target, int value) { + template static void encode(int &target, const int value) { if constexpr (i == index) { const int suffix = target % divider; target /= divider; @@ -61,7 +61,7 @@ private: template struct NumericDecoder { - template static int decode(int source) { + template static int decode(const int source) { if constexpr (i == index) { return (source / divider) % size; } else {