OSDN Git Service

49d15d2382dc2bfcea1059ef1197c79ef8f745a9
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / operator-assignment.c
1 /* { dg-options "-std=gnu99" } */
2
3 /* C99 6.5.16 Assignment operators.
4    Verify the compound assignment operator for decimal float types,
5    using it with other decimal float types, integers, and other binary
6    float types cast to decimal float types.  */
7
8 extern void abort (void);
9 static int failcnt;
10
11 /* Support compiling the test to report individual failures; default is
12    to abort as soon as a check fails.  */
13 #ifdef DBG
14 #include <stdio.h>
15 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
16 #else
17 #define FAILURE abort ();
18 #endif
19
20 #define OPERATE(OPRD1,OPRT,OPRD2,RLT)           \
21   if (( OPRD1 OPRT OPRD2 )!= RLT)               \
22     FAILURE
23
24 #define DECIMAL_COMPOUND_ASSIGNMENT(TYPE, OPRD) \
25 {                                               \
26   _Decimal##TYPE d = OPRD;                      \
27   OPERATE(d,+=,1,(OPRD + 1));           \
28   d = OPRD;                             \
29   OPERATE(d,+=,0,OPRD);                 \
30   d = OPRD;                             \
31   OPERATE(d,+=,(-1),(OPRD - 1));        \
32   d = OPRD;                             \
33   OPERATE(d,+=,d32a,(OPRD + d32a));     \
34   d = OPRD;                             \
35   OPERATE(d,+=,d64a,(OPRD + d64a));     \
36   d = OPRD;                             \
37   OPERATE(d,+=,d128a,(OPRD + d128a));   \
38   d = OPRD;                             \
39   OPERATE(d,+=,(_Decimal##TYPE)1.1,(OPRD + (_Decimal##TYPE)1.1));       \
40   d = OPRD;                             \
41   OPERATE(d,+=,(_Decimal##TYPE)2.2f,(OPRD + (_Decimal##TYPE)2.2f));     \
42   d = OPRD;                             \
43   OPERATE(d,-=,1,(OPRD - 1));           \
44   d = OPRD;                             \
45   OPERATE(d,-=,0,OPRD);                 \
46   d = OPRD;                             \
47   OPERATE(d,-=,(-1),(OPRD + 1));        \
48   d = OPRD;                             \
49   OPERATE(d,-=,d32a,OPRD-d32a);         \
50   d = OPRD;                             \
51   OPERATE(d,-=,d64a,OPRD-d64a);         \
52   d = OPRD;                             \
53   OPERATE(d,-=,d128a,OPRD-d128a);       \
54 }
55
56 int
57 main ()
58 {
59   _Decimal32 d32 = 1.23456df, d32a = 1.2df;
60   _Decimal64 d64 = 23.456789dd, d64a = 2.8dd;
61   _Decimal128 d128 = 345.67890123456789dl, d128a = 4.7dl;
62
63   DECIMAL_COMPOUND_ASSIGNMENT(32, d32);
64   DECIMAL_COMPOUND_ASSIGNMENT(64, d64);
65   DECIMAL_COMPOUND_ASSIGNMENT(128, d128);
66
67   if (failcnt != 0)
68     abort ();
69
70   return 0;
71 }