Skip to content

Commit 29baeba

Browse files
Merge branch 'main' into fix/rangeSFix
2 parents 2deff36 + a24ea68 commit 29baeba

2 files changed

Lines changed: 36 additions & 36 deletions

File tree

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=FixMath
2-
version=1.0.3
2+
version=1.0.5
33
author=Thomas Combriat and Thomas Friedrichsmeier
44
maintainer=Thomas Combriat <tomcombriat@live.fr>
55
sentence=Fixed Point Arithmetics for Arduino and others

src/FixMath_Autotests.h

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ namespace FixMathPrivate {
2020
constexpr auto c = UFix<8,0>(33); // 33
2121

2222
// basics
23-
static_assert(a < b && b < c);
24-
static_assert(a.getNF() == 1 && b.getNF() == 2);
23+
static_assert(a < b && b < c, "test fail");
24+
static_assert(a.getNF() == 1 && b.getNF() == 2, "test fail");
2525

2626
// addition
2727
constexpr auto d = a + b;
28-
static_assert(d.getNI() == 9);
29-
static_assert(d.getNF() == 2); // NF is always max in addition
30-
static_assert((a + c).getNF() == 1);
31-
static_assert(d.asRaw() == 258);
28+
static_assert(d.getNI() == 9, "test fail");
29+
static_assert(d.getNF() == 2, "test fail"); // NF is always max in addition
30+
static_assert((a + c).getNF() == 1, "test fail");
31+
static_assert(d.asRaw() == 258, "test fail");
3232
constexpr auto e = d + b + c; // addition of one 9 (NI) bit and two 8 (NI) bit numbers needs promotion to 10 bits, not 11, only.
33-
static_assert(e.getNI() == 10);
34-
static_assert(e.getNF() == 2);
33+
static_assert(e.getNI() == 10, "test fail");
34+
static_assert(e.getNF() == 2, "test fail");
3535
e.assertSize<12>();
36-
static_assert((d + d).getNI() == 10);
37-
static_assert((e + e).getNF() == 2);
38-
static_assert((d + e).getNI() == 11);
36+
static_assert((d + d).getNI() == 10, "test fail");
37+
static_assert((e + e).getNF() == 2, "test fail");
38+
static_assert((d + e).getNI() == 11, "test fail");
3939

4040
// Two's complement peculiar additions
4141
static_assert(SFixAuto<-128>().getNI() == 7);
@@ -47,43 +47,43 @@ namespace FixMathPrivate {
4747

4848
// the point of this block is to ascertain that addtion does not overflow, internally, where the internal_type of the operands is too small to hold the result
4949
constexpr auto large = UFix<32,0>(1LL << 31, true);
50-
static_assert(sizeof(decltype(large.asRaw())) == 4);
51-
static_assert((large+large).asRaw() == (1LL << 32));
52-
static_assert(sizeof(decltype((large+large).asRaw())) > 4);
50+
static_assert(sizeof(decltype(large.asRaw())) == 4, "test fail");
51+
static_assert((large+large).asRaw() == (1LL << 32), "test fail");
52+
static_assert(sizeof(decltype((large+large).asRaw())) > 4, "test fail");
5353

5454
// subtraction
55-
static_assert(b - a == c - b);
56-
static_assert(c - UFix<17,8>(1) == a);
57-
static_assert(c - SFix<13,9>(1) == a);
58-
static_assert(b + a - b == a);
59-
static_assert(b + a + (-b) == a); // same with unary minus
60-
static_assert(-(-a) == a);
55+
static_assert(b - a == c - b, "test fail");
56+
static_assert(c - UFix<17,8>(1) == a, "test fail");
57+
static_assert(c - SFix<13,9>(1) == a, "test fail");
58+
static_assert(b + a - b == a, "test fail");
59+
static_assert(b + a + (-b) == a, "test fail"); // same with unary minus
60+
static_assert(-(-a) == a, "test fail");
6161
#if __cplusplus >= 202002L
6262
// These here involve shifts of negative numbers, which used to be "implementation defined" before C++-20.
6363
// It doesn't cause a real-world problem, but the compiler won't accept it in a constexpr
64-
static_assert(UFix<43,9>(0) - b - a == -(a+b));
65-
static_assert(SFix<4, 3>(-1) == SFix<4, 5>(-1)); // NOTE This is a simpler test case for the above problem. Note the difference in NF, which prompts shifting
64+
static_assert(UFix<43,9>(0) - b - a == -(a+b), "test fail");
65+
static_assert(SFix<4, 3>(-1) == SFix<4, 5>(-1), "test fail"); // NOTE This is a simpler test case for the above problem. Note the difference in NF, which prompts shifting
6666
#endif
6767
// here's a variant that avoids the problem by using only positive numbers
68-
static_assert(UFix<12,1>(999) - UFix<43,9>(0) - b - a == UFix<19,2>(999) + (-(a+b)));
69-
static_assert(-SFix<4, 3>(-8, true) == -SFix<4, 5>(-32, true));
68+
static_assert(UFix<12,1>(999) - UFix<43,9>(0) - b - a == UFix<19,2>(999) + (-(a+b)), "test fail");
69+
static_assert(-SFix<4, 3>(-8, true) == -SFix<4, 5>(-32, true), "test fail");
7070

7171
// multiplication
72-
static_assert(c * UFix<36, 5>(3ll << 31) == UFix<58,0>(33ll*(3ll << 31))); // NOTE: The exact values are aribrary, but we want something that would overflow the initial type range
73-
static_assert(a * UFix<0, 2>(3, true) == UFix<17, 8>(24)); // 32 * .75 == 24
74-
static_assert(a * UFix<5, 0>(4).invAccurate() == UFix<17, 8>(8)); // 32 * (1/4) == 8
75-
static_assert(a * toUFraction((int8_t) 16) == UFix<3, 9>(2)); // 32 * (16/256) == 2
72+
static_assert(c * UFix<36, 5>(3ll << 31) == UFix<58,0>(33ll*(3ll << 31)), "test fail"); // NOTE: The exact values are aribrary, but we want something that would overflow the initial type range
73+
static_assert(a * UFix<0, 2>(3, true) == UFix<17, 8>(24), "test fail"); // 32 * .75 == 24
74+
static_assert(a * UFix<5, 0>(4).invAccurate() == UFix<17, 8>(8), "test fail"); // 32 * (1/4) == 8
75+
static_assert(a * toUFraction((int8_t) 16) == UFix<3, 9>(2), "test fail"); // 32 * (16/256) == 2
7676

7777
// type conversions
78-
static_assert(a.getNI() == a.asSFix().getNI());
79-
static_assert(a.getNF() == a.asSFix().getNF());
78+
static_assert(a.getNI() == a.asSFix().getNI(), "test fail");
79+
static_assert(a.getNF() == a.asSFix().getNF(), "test fail");
8080

8181
// UFixAuto() / SFixAuto()
82-
static_assert(FixMathPrivate::NIcount<0>() == 0);
83-
static_assert(FixMathPrivate::NIcount<1>() == 1);
84-
static_assert(FixMathPrivate::NIcount<2>() == 2);
85-
static_assert(FixMathPrivate::NIcount<3>() == 2);
86-
static_assert(FixMathPrivate::NIcount<4>() == 3);
82+
static_assert(FixMathPrivate::NIcount<0>() == 0, "test fail");
83+
static_assert(FixMathPrivate::NIcount<1>() == 1, "test fail");
84+
static_assert(FixMathPrivate::NIcount<2>() == 2, "test fail");
85+
static_assert(FixMathPrivate::NIcount<3>() == 2, "test fail");
86+
static_assert(FixMathPrivate::NIcount<4>() == 3, "test fail");
8787

8888
UFixAuto<3>().assertSize<2>();
8989
UFixAuto<3>().sR<2>().assertSize<2>();

0 commit comments

Comments
 (0)