| 1 |
// RUN: %clang_cc1 %s -fsyntax-only -ffixed-point -verify=expected,both -fexperimental-new-constant-interpreter |
| 2 |
// RUN: %clang_cc1 %s -fsyntax-only -ffixed-point -verify=ref,both |
| 3 |
|
| 4 |
static_assert((bool)1.0k); |
| 5 |
static_assert(!((bool)0.0k)); |
| 6 |
static_assert((bool)0.0k); // both-error {{static assertion failed}} |
| 7 |
|
| 8 |
static_assert(1.0k == 1.0k); |
| 9 |
static_assert(1.0k == 1); |
| 10 |
static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k != 1.0k'}} |
| 11 |
static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 1'}} |
| 12 |
static_assert(-12.0k == -(-(-12.0k))); |
| 13 |
|
| 14 |
constexpr _Accum acc = (0.5r, 6.9k); |
| 15 |
|
| 16 |
/// Zero-init. |
| 17 |
constexpr _Accum A{}; |
| 18 |
static_assert(A == 0.0k); |
| 19 |
static_assert(A == 0); |
| 20 |
static_assert(!A); |
| 21 |
|
| 22 |
constexpr bool toBool() { |
| 23 |
if (A) |
| 24 |
return true; |
| 25 |
return false; |
| 26 |
} |
| 27 |
static_assert(!toBool()); |
| 28 |
|
| 29 |
namespace IntToFixedPointCast { |
| 30 |
constexpr _Accum B = 13; |
| 31 |
static_assert(B == 13.0k); |
| 32 |
static_assert(B == 13); |
| 33 |
|
| 34 |
constexpr _Fract sf = -1; |
| 35 |
static_assert(sf == -1.0k); |
| 36 |
static_assert(sf == -1); |
| 37 |
} |
| 38 |
|
| 39 |
namespace FixedPointToIntCasts { |
| 40 |
constexpr _Accum A = -13.0k; |
| 41 |
constexpr int I = A; |
| 42 |
static_assert(I == -13); |
| 43 |
} |
| 44 |
|
| 45 |
namespace FloatToFixedPointCast { |
| 46 |
constexpr _Fract sf = 1.0; // both-error {{must be initialized by a constant expression}} \ |
| 47 |
// both-note {{outside the range of representable values of type 'const _Fract'}} |
| 48 |
|
| 49 |
constexpr _Fract sf2 = 0.5; |
| 50 |
static_assert(sf2 == 0.5); |
| 51 |
constexpr float sf2f = sf2; |
| 52 |
static_assert(sf2f == 0.5); |
| 53 |
} |
| 54 |
|
| 55 |
namespace BinOps { |
| 56 |
constexpr _Accum A = 13; |
| 57 |
static_assert(A + 1 == 14.0k); |
| 58 |
static_assert(1 + A == 14.0k); |
| 59 |
static_assert((A + A) == 26); |
| 60 |
|
| 61 |
static_assert(A + 100000 == 14.0k); // both-error {{is not an integral constant expression}} \ |
| 62 |
// both-note {{is outside the range of representable values}} |
| 63 |
|
| 64 |
static_assert((A - A) == 0); |
| 65 |
constexpr short _Accum mul_ovf1 = 255.0hk * 4.5hk; // both-error {{must be initialized by a constant expression}} \ |
| 66 |
// both-note {{value 123.5 is outside the range of representable values of type 'short _Accum'}} |
| 67 |
constexpr short _Accum div_ovf1 = 255.0hk / 0.5hk; // both-error {{must be initialized by a constant expression}} \ |
| 68 |
// both-note {{value -2.0 is outside the range of representable values of type 'short _Accum'}} |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
namespace FixedPointCasts { |
| 73 |
constexpr _Fract B = 0.3; |
| 74 |
constexpr _Accum A = B; |
| 75 |
constexpr _Fract C = A; |
| 76 |
} |
| 77 |
|
| 78 |
namespace Cmp { |
| 79 |
constexpr _Accum A = 13.0k; |
| 80 |
constexpr _Accum B = 14.0k; |
| 81 |
static_assert(B > A); |
| 82 |
static_assert(B >= A); |
| 83 |
static_assert(A < B); |
| 84 |
static_assert(A <= B); |
| 85 |
} |