OSDN Git Service

* gcc.dg/nodfp-1.c: New test.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / usual-arith-conv.c
1 /* { dg-do run } */
2 /* { dg-options "-std=gnu99 -O0" } */
3
4 /* N1150 5.4: Usual arithmetic conversions.
5    C99 6.3.1.8[1] (New).
6
7    Test arithmetic operators with different decimal float types, and
8    between decimal float types and integer types.  */
9
10 extern void abort (void);
11 static int failcnt = 0;
12                                                                                 
13 /* Support compiling the test to report individual failures; default is
14    to abort as soon as a check fails.  */
15 #ifdef DBG
16 #include <stdio.h>
17 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
18 #else
19 #define FAILURE abort ();
20 #endif
21
22 volatile _Decimal32 d32a, d32b, d32c;
23 volatile _Decimal64 d64a, d64b, d64c;
24 volatile _Decimal128 d128a, d128b, d128c;
25 volatile int i;
26
27 void
28 init ()
29 {
30   d32b = 123.456e94df;
31   d64b = 12.3456789012345e383dd;
32   d128b = 12345.6789012345678901e4000dl;
33
34   d32c = 1.3df;
35   d64c = 1.2dd;
36   d128c = 1.1dl;
37
38   i = 2;
39 }
40
41 int
42 main ()
43 {
44   init ();
45
46   /* Usual arithmetic conversions between decimal float types; addition.  */
47   d128a = d128b + d32b;
48   if (d128a < d128b)
49     FAILURE
50   d128a = d32b + d128b;
51   if (d128a < d128b)
52     FAILURE
53   d128a = d128b + d64b;
54   if (d128a < d128b)
55     FAILURE
56   d128a = d64b + d128b;
57   if (d128a < d128b)
58     FAILURE
59   d64a = d64b + d32b;
60   if (d64a < d64b)
61     FAILURE
62   d64a = d32b + d64b;
63   if (d64a < d64b)
64     FAILURE
65
66   /* Usual arithmetic conversions between decimal float types;
67      multiplication.  */
68   d128a = d128b * d32c;
69   if (d128a < d128b)
70     FAILURE
71   d128a = d32c * d128b;
72   if (d128a < d128b)
73     FAILURE
74   d128a = d128b * d64c;
75   if (d128a < d128b)
76     FAILURE
77   d128a = d64c * d128b;
78   if (d128a < d128b)
79     FAILURE
80   d64a = d64b * d32c;
81   if (d64a < d64b)
82     FAILURE
83   d64a = d32c * d64b;
84   if (d64a < d64b)
85     FAILURE
86
87   /* Usual arithmetic conversions between decimal float and integer types.  */
88   d32a = d32c + i;
89   if (d32a != d32c + 2.0df)
90     FAILURE
91   d32a = d32c - i;
92   if (d32a != d32c - 2.0df)
93     FAILURE
94   d32a = i * d32c;
95   if (d32a != d32c + d32c)
96     FAILURE
97   d32a = d32c / i;
98   if (d32a != d32c / 2.0df)
99     FAILURE
100
101   d64a = i + d64c;
102   if (d64a != d64c + 2.0dd)
103     FAILURE
104   d64a = d64c - i;
105   if (d64a != d64c - 2.0dd)
106     FAILURE
107   d64a = d64c * i;
108   if (d64a != d64c + d64c)
109     FAILURE
110   d64a = d64c / i;
111   if (d64a != d64c / 2.0dd)
112     FAILURE
113
114   d128a = d128c + i;
115   if (d128a != d128c + 2.0dl)
116     FAILURE
117   d128a = d128c - i;
118   if (d128a != d128c - 2.0dl)
119     FAILURE
120   d128a = i * d128c;
121   if (d128a != d128c + d128c)
122     FAILURE
123   d128a = d128c / i;
124   if (d128a != d128c / 2.0dl)
125     FAILURE
126
127   return 0;
128 }