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 21 namespace IntToFixedPointCast { 22 constexpr _Accum B = 13; 23 static_assert(B == 13.0k); 24 static_assert(B == 13); 25 26 constexpr _Fract sf = -1; 27 static_assert(sf == -1.0k); 28 static_assert(sf == -1); 29 } 30 31 namespace FixedPointToIntCasts { 32 constexpr _Accum A = -13.0k; 33 constexpr int I = A; 34 static_assert(I == -13); 35 } 36 37 namespace FloatToFixedPointCast { 38 constexpr _Fract sf = 1.0; // both-error {{must be initialized by a constant expression}} \ 39 // both-note {{outside the range of representable values of type 'const _Fract'}} 40 41 constexpr _Fract sf2 = 0.5; 42 static_assert(sf2 == 0.5); 43 constexpr float sf2f = sf2; 44 static_assert(sf2f == 0.5); 45 } 46 47 namespace BinOps { 48 constexpr _Accum A = 13; 49 static_assert(A + 1 == 14.0k); 50 static_assert(1 + A == 14.0k); 51 static_assert((A + A) == 26); 52 53 static_assert(A + 100000 == 14.0k); // both-error {{is not an integral constant expression}} \ 54 // both-note {{is outside the range of representable values}} 55 56 static_assert((A - A) == 0); 57 constexpr short _Accum mul_ovf1 = 255.0hk * 4.5hk; // both-error {{must be initialized by a constant expression}} \ 58 // both-note {{value 123.5 is outside the range of representable values of type 'short _Accum'}} 59 constexpr short _Accum div_ovf1 = 255.0hk / 0.5hk; // both-error {{must be initialized by a constant expression}} \ 60 // both-note {{value -2.0 is outside the range of representable values of type 'short _Accum'}} 61 62 } 63 64 namespace FixedPointCasts { 65 constexpr _Fract B = 0.3; 66 constexpr _Accum A = B; 67 constexpr _Fract C = A; 68 } 69 70 namespace Cmp { 71 constexpr _Accum A = 13.0k; 72 constexpr _Accum B = 14.0k; 73 static_assert(B > A); 74 static_assert(B >= A); 75 static_assert(A < B); 76 static_assert(A <= B); 77 } 78