44static void testReverseNBits(
unsigned x,
unsigned n,
unsigned expected)
51 testReverseNBits(0x0, 4, 0x0);
52 testReverseNBits(0x1, 4, 0x8);
53 testReverseNBits(0x2, 4, 0x4);
54 testReverseNBits(0x3, 4, 0xC);
55 testReverseNBits(0x4, 4, 0x2);
56 testReverseNBits(0x8, 4, 0x1);
57 testReverseNBits(0x6, 4, 0x6);
58 testReverseNBits(0xE, 4, 0x7);
59 testReverseNBits(0xF, 4, 0xF);
60 testReverseNBits(0x00012345, 22, 0x0028B120);
61 testReverseNBits(0x0010000F, 32, 0xF0000800);
64static void testReverseByte(uint8_t x, uint8_t expected)
74 testReverseByte(0x00, 0x00);
75 testReverseByte(0x01, 0x80);
76 testReverseByte(0x02, 0x40);
77 testReverseByte(0x07, 0xE0);
78 testReverseByte(0x12, 0x48);
79 testReverseByte(0x73, 0xCE);
80 testReverseByte(0x7F, 0xFE);
81 testReverseByte(0x8C, 0x31);
82 testReverseByte(0xAB, 0xD5);
83 testReverseByte(0xE4, 0x27);
84 testReverseByte(0xF0, 0x0F);
114 auto test = [](
int D,
int d,
int q,
int r) {
115 REQUIRE(d * q + r ==
D);
117 CHECK(qr.quotient == q);
118 CHECK(qr.remainder == r);
122 test( 10, -3, -4, -2);
123 test(-10, -3, 3, -1);
127 test( 10, -2, -5, 0);
void test(const IterableBitSet< N > &s, std::initializer_list< size_t > list)
TEST_CASE("Math::clipToInt16")
constexpr QuotientRemainder div_mod_floor(int dividend, int divisor)
constexpr unsigned reverseNBits(unsigned x, unsigned bits)
Reverse the lower N bits of a given value.
constexpr auto floodRight(std::unsigned_integral auto x) noexcept
Returns the smallest number of the form 2^n-1 that is greater or equal to the given number.
uint8_t clipIntToByte(int x)
Clip x to range [0,255].
int16_t clipToInt16(T x)
Clip x to range [-32768,32767].
constexpr uint8_t reverseByte(uint8_t a)
Reverse the bits in a byte.