You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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
49
49
constexprauto large = UFix<32,0>(1LL << 31, true);
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");
61
61
#if __cplusplus >= 202002L
62
62
// These here involve shifts of negative numbers, which used to be "implementation defined" before C++-20.
63
63
// 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
66
66
#endif
67
67
// 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)));
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
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
0 commit comments