summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/fixed-point/unary.c
blob: 4e0954902aa194d7ba6325658856f842afb7a999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* { dg-do run } */
/* { dg-options "-std=gnu99" } */

/* C99 6.5.3 Unary operators.

   Check unary operators ++ -- + - !.  */

extern void abort (void);

#define INCDEC(TYPE,POSTFIX) \
  { TYPE a = 0.0 ## POSTFIX; \
    if (a++ != 0.0 ## POSTFIX) \
      abort(); \
    if (a != 1.0 ## POSTFIX) \
      abort(); \
    if (a-- != 1.0 ## POSTFIX) \
      abort(); \
    if (a != 0.0 ## POSTFIX) \
      abort(); \
    if (++a != 1.0 ## POSTFIX) \
      abort(); \
    if (a != 1.0 ## POSTFIX) \
      abort(); \
    if (--a != 0.0 ## POSTFIX) \
      abort(); \
    if (a != 0.0 ## POSTFIX) \
      abort(); \
  }

#define FRACT_INCDEC(TYPE,POSTFIX) \
  { TYPE a = -0.5 ## POSTFIX; \
    if (a++ != -0.5 ## POSTFIX) \
      abort(); \
    if (a != 0.5 ## POSTFIX) \
      abort(); \
    if (a-- != 0.5 ## POSTFIX) \
      abort(); \
    if (a != -0.5 ## POSTFIX) \
      abort(); \
    if (++a != 0.5 ## POSTFIX) \
      abort(); \
    if (a != 0.5 ## POSTFIX) \
      abort(); \
    if (--a != -0.5 ## POSTFIX) \
      abort(); \
    if (a != -0.5 ## POSTFIX) \
      abort(); \
  }

#define FRACT_SAT_INCDEC(TYPE,POSTFIX) \
  { TYPE a = 0.9 ## POSTFIX; \
    if (++a != 1.0 ## POSTFIX) \
      abort(); \
    a = -0.1 ## POSTFIX; \
    if (--a != -0.5 ## POSTFIX - 0.5 ## POSTFIX) \
      abort(); \
  }

#define FRACT_SAT_UNS_INCDEC(TYPE,POSTFIX) \
  { TYPE a = 0.9 ## POSTFIX; \
    if (++a != 1.0 ## POSTFIX) \
      abort(); \
    a = 0.1 ## POSTFIX; \
    if (--a != 0.0 ## POSTFIX) \
      abort(); \
  }

#define PLUS(TYPE,POSTFIX) \
  { TYPE a = 0.1 ## POSTFIX; \
    if (+a != 0.1 ## POSTFIX) \
      abort(); \
  }

#define NEG(TYPE,POSTFIX) \
  { TYPE a = -0.1 ## POSTFIX; \
    if (-a != 0.1 ## POSTFIX) \
      abort(); \
  }

#define FRACT_SAT_NEG(TYPE,POSTFIX) \
  { TYPE a = -0.5 ## POSTFIX - 0.5 ## POSTFIX; \
    if (-a != 1.0 ## POSTFIX) \
      abort(); \
  }

#define UNS_NEG(TYPE,POSTFIX) \
  { TYPE a = 0.0 ## POSTFIX; \
    if (-a != 0.0 ## POSTFIX) \
      abort(); \
  }

#define FRACT_SAT_UNS_NEG(TYPE,POSTFIX) \
  { TYPE a = 0.5 ## POSTFIX; \
    if (-a != 0.0 ## POSTFIX) \
      abort(); \
  }

#define LOGNEG(TYPE,POSTFIX) \
  { TYPE a = 0.0 ## POSTFIX; \
    TYPE b = 0.1 ## POSTFIX; \
    if (!a != 1) \
      abort(); \
    if (!b != 0) \
      abort(); \
  }

int main ()
{
  FRACT_INCDEC(short _Fract, hr);
  FRACT_INCDEC(_Fract, r);
  FRACT_INCDEC(long _Fract, lr);
  FRACT_INCDEC(long long _Fract, llr);
  FRACT_INCDEC(_Sat short _Fract, hr);
  FRACT_INCDEC(_Sat _Fract, r);
  FRACT_INCDEC(_Sat long _Fract, lr);
  FRACT_INCDEC(_Sat long long _Fract, llr);

  INCDEC(short _Accum, hk);
  INCDEC(_Accum, k);
  INCDEC(long _Accum, lk);
  INCDEC(long long _Accum, llk);
  INCDEC(unsigned short _Accum, uhk);
  INCDEC(unsigned _Accum, uk);
  INCDEC(unsigned long _Accum, ulk);
  INCDEC(unsigned long long _Accum, ullk);
  INCDEC(_Sat short _Accum, hk);
  INCDEC(_Sat _Accum, k);
  INCDEC(_Sat long _Accum, lk);
  INCDEC(_Sat long long _Accum, llk);
  INCDEC(_Sat unsigned short _Accum, uhk);
  INCDEC(_Sat unsigned _Accum, uk);
  INCDEC(_Sat unsigned long _Accum, ulk);
  INCDEC(_Sat unsigned long long _Accum, ullk);

  FRACT_SAT_INCDEC(_Sat short _Fract, hr);
  FRACT_SAT_INCDEC(_Sat _Fract, r);
  FRACT_SAT_INCDEC(_Sat long _Fract, lr);
  FRACT_SAT_INCDEC(_Sat long long _Fract, llr);

  FRACT_SAT_UNS_INCDEC(_Sat unsigned short _Fract, uhr);
  FRACT_SAT_UNS_INCDEC(_Sat unsigned _Fract, ur);
  FRACT_SAT_UNS_INCDEC(_Sat unsigned long _Fract, ulr);
  FRACT_SAT_UNS_INCDEC(_Sat unsigned long long _Fract, ullr);

  PLUS(short _Fract, hr);
  PLUS(_Fract, r);
  PLUS(long _Fract, lr);
  PLUS(long long _Fract, llr);
  PLUS(unsigned short _Fract, uhr);
  PLUS(unsigned _Fract, ur);
  PLUS(unsigned long _Fract, ulr);
  PLUS(unsigned long long _Fract, ullr);
  PLUS(_Sat short _Fract, hr);
  PLUS(_Sat _Fract, r);
  PLUS(_Sat long _Fract, lr);
  PLUS(_Sat long long _Fract, llr);
  PLUS(_Sat unsigned short _Fract, uhr);
  PLUS(_Sat unsigned _Fract, ur);
  PLUS(_Sat unsigned long _Fract, ulr);
  PLUS(_Sat unsigned long long _Fract, ullr);
  PLUS(short _Accum, hk);
  PLUS(_Accum, k);
  PLUS(long _Accum, lk);
  PLUS(long long _Accum, llk);
  PLUS(unsigned short _Accum, uhk);
  PLUS(unsigned _Accum, uk);
  PLUS(unsigned long _Accum, ulk);
  PLUS(unsigned long long _Accum, ullk);
  PLUS(_Sat short _Accum, hk);
  PLUS(_Sat _Accum, k);
  PLUS(_Sat long _Accum, lk);
  PLUS(_Sat long long _Accum, llk);
  PLUS(_Sat unsigned short _Accum, uhk);
  PLUS(_Sat unsigned _Accum, uk);
  PLUS(_Sat unsigned long _Accum, ulk);
  PLUS(_Sat unsigned long long _Accum, ullk);

  NEG(short _Fract, hr);
  NEG(_Fract, r);
  NEG(long _Fract, lr);
  NEG(long long _Fract, llr);
  NEG(_Sat short _Fract, hr);
  NEG(_Sat _Fract, r);
  NEG(_Sat long _Fract, lr);
  NEG(_Sat long long _Fract, llr);
  NEG(short _Accum, hk);
  NEG(_Accum, k);
  NEG(long _Accum, lk);
  NEG(long long _Accum, llk);
  NEG(_Sat short _Accum, hk);
  NEG(_Sat _Accum, k);
  NEG(_Sat long _Accum, lk);
  NEG(_Sat long long _Accum, llk);

  FRACT_SAT_NEG(_Sat short _Fract, hr);
  FRACT_SAT_NEG(_Sat _Fract, r);
  FRACT_SAT_NEG(_Sat long _Fract, lr);
  FRACT_SAT_NEG(_Sat long long _Fract, llr);

  UNS_NEG(short _Fract, hr);
  UNS_NEG(_Fract, r);
  UNS_NEG(long _Fract, lr);
  UNS_NEG(long long _Fract, llr);
  UNS_NEG(_Sat short _Fract, hr);
  UNS_NEG(_Sat _Fract, r);
  UNS_NEG(_Sat long _Fract, lr);
  UNS_NEG(_Sat long long _Fract, llr);
  UNS_NEG(short _Accum, hk);
  UNS_NEG(_Accum, k);
  UNS_NEG(long _Accum, lk);
  UNS_NEG(long long _Accum, llk);
  UNS_NEG(_Sat short _Accum, hk);
  UNS_NEG(_Sat _Accum, k);
  UNS_NEG(_Sat long _Accum, lk);
  UNS_NEG(_Sat long long _Accum, llk);

  FRACT_SAT_UNS_NEG(_Sat unsigned short _Fract, uhr);
  FRACT_SAT_UNS_NEG(_Sat unsigned _Fract, ur);
  FRACT_SAT_UNS_NEG(_Sat unsigned long _Fract, ulr);
  FRACT_SAT_UNS_NEG(_Sat unsigned long long _Fract, ullr);

  LOGNEG(short _Fract, hr);
  LOGNEG(_Fract, r);
  LOGNEG(long _Fract, lr);
  LOGNEG(long long _Fract, llr);
  LOGNEG(unsigned short _Fract, uhr);
  LOGNEG(unsigned _Fract, ur);
  LOGNEG(unsigned long _Fract, ulr);
  LOGNEG(unsigned long long _Fract, ullr);
  LOGNEG(_Sat short _Fract, hr);
  LOGNEG(_Sat _Fract, r);
  LOGNEG(_Sat long _Fract, lr);
  LOGNEG(_Sat long long _Fract, llr);
  LOGNEG(_Sat unsigned short _Fract, uhr);
  LOGNEG(_Sat unsigned _Fract, ur);
  LOGNEG(_Sat unsigned long _Fract, ulr);
  LOGNEG(_Sat unsigned long long _Fract, ullr);
  LOGNEG(short _Accum, hk);
  LOGNEG(_Accum, k);
  LOGNEG(long _Accum, lk);
  LOGNEG(long long _Accum, llk);
  LOGNEG(unsigned short _Accum, uhk);
  LOGNEG(unsigned _Accum, uk);
  LOGNEG(unsigned long _Accum, ulk);
  LOGNEG(unsigned long long _Accum, ullk);
  LOGNEG(_Sat short _Accum, hk);
  LOGNEG(_Sat _Accum, k);
  LOGNEG(_Sat long _Accum, lk);
  LOGNEG(_Sat long long _Accum, llk);
  LOGNEG(_Sat unsigned short _Accum, uhk);
  LOGNEG(_Sat unsigned _Accum, uk);
  LOGNEG(_Sat unsigned long _Accum, ulk);
  LOGNEG(_Sat unsigned long long _Accum, ullk);

  return 0;
}