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
4 static_assert((bool)1.0k
);
5 static_assert(!((bool)0.0k
));
6 static_assert((bool)0.0k
); // both-error {{static assertion failed}}
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
)));
14 constexpr _Accum acc
= (0.5r
, 6.9k
);
18 static_assert(A
== 0.0k
);
19 static_assert(A
== 0);
21 namespace IntToFixedPointCast
{
22 constexpr _Accum B
= 13;
23 static_assert(B
== 13.0k
);
24 static_assert(B
== 13);
26 constexpr _Fract sf
= -1;
27 static_assert(sf
== -1.0k
);
28 static_assert(sf
== -1);
31 namespace FixedPointToIntCasts
{
32 constexpr _Accum A
= -13.0k
;
34 static_assert(I
== -13);
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'}}
41 constexpr _Fract sf2
= 0.5;
42 static_assert(sf2
== 0.5);
43 constexpr float sf2f
= sf2
;
44 static_assert(sf2f
== 0.5);
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);
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}}
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'}}
64 namespace FixedPointCasts
{
65 constexpr _Fract B
= 0.3;
66 constexpr _Accum A
= B
;
67 constexpr _Fract C
= A
;
71 constexpr _Accum A
= 13.0k
;
72 constexpr _Accum B
= 14.0k
;
74 static_assert(B
>= A
);
76 static_assert(A
<= B
);