6 #include "../vnix/rat/encoding.hpp" 15 TEST_CASE(
"Constants are computed correctly.",
"[encoding]") {
17 REQUIRE(en::BITS == 8);
18 REQUIRE(en::DNM_MASK == 0x07);
19 REQUIRE(en::NMR_MASK == 0xF8);
23 TEST_CASE(
"Limiting values are encoded and decoded.",
"[encoding]") {
24 en8_t
const e1
(np8_t
(-16
, 1
));
25 en8_t
const e2
(np8_t
(+15
, 1
));
26 en8_t
const e3
(np8_t
(+1
, 8
));
27 en9_t
const e4
(np9_t
(-16
, 1
));
28 en9_t
const e5
(np9_t
(+15
, 1
));
29 en9_t
const e6
(np9_t
(+1
, 16
));
31 REQUIRE(e1
.n() == -16);
34 REQUIRE(e2
.n() == +15);
37 REQUIRE(e3
.n() == +1);
40 REQUIRE(e4
.n() == -16);
43 REQUIRE(e5
.n() == +15);
46 REQUIRE(e6
.n() == +1);
47 REQUIRE(e6
.d() == 16);
Numerator and denominator of a rational number as separate numbers, not encoded into the same word...
constexpr int_types< DNM_BITS >::UF d() const
Normalized denominator.
constexpr normalized_pair(S nn, S dd)
Initialize normalized numerator and denominator for encoding of rational number.
constexpr encoding(normalized_pair< NMR_BITS, DNM_BITS > p)
Initialize from normalized numerator and denominator.
Thomas E. Vaughan's public software.
constexpr int_types< NMR_BITS >::SF n() const
Normalized numerator.
Classes and functions supporting a model of a fixed-precision rational number.
Encoding of numerator and denominator into unsigned word.