OSDN Git Service

* gcc.dg/nodfp-1.c: New test.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / convert-complex.c
1 /* { dg-do run } */
2 /* { dg-options "-O3" } */
3
4 /* N1150 5.3 Conversions between decimal floating and complex.
5    C99 6.3.1.7 Conversions, arithmetic operands, real and complex.  */
6
7 extern void abort(void);
8 static int failcnt;
9                                                                                 
10 /* Support compiling the test to report individual failures; default is
11    to abort as soon as a check fails.  */
12 #ifdef DBG
13 #include <stdio.h>
14 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
15 #else
16 #define FAILURE abort ();
17 #endif
18
19 int
20 main ()
21 {
22   _Complex float cf;
23   _Complex double cd;
24   _Complex long double cld;
25
26   _Decimal32 d32;
27   _Decimal64 d64;
28   _Decimal128 d128;
29
30   cf = 2.0f *  __extension__ 1i + 3.0f;
31   cd = 2.0 * __extension__ 1i + 3.0;
32   cld = 2.0l * __extension__ 1i + 3.0l;
33
34   /* Convert complex to decimal floating.  */
35   d32 = cf;
36   d64 = cd;
37   d128 = cld;
38
39   if (d32 != 3.0DF)
40     FAILURE
41   if (d64 != 3.0dd)
42     FAILURE
43   if (d128 != 3.0dl)
44     FAILURE
45
46   /* Convert decimal floating to complex.  */
47   d32 = 2.5DF;
48   d64 = 1.5DD;
49   d128 = 2.5DL;
50
51   cf = d32;
52   cd = d64;
53   cld = d128;
54  
55   /* N1107 5.3 Conversions between decimal floating and complex. 
56      When a value of decimal floating type converted to a complex
57      type, the real part of the complex result value is undermined
58      by the rules of conversions in N1107 5.2 and the imaginary part
59      of the complex result value is zero.  */
60
61   if (__real__ cf != 2.5f)
62     FAILURE
63   if (__real__ cd !=1.5)
64     FAILURE
65   if (__real__ cld !=  2.5)
66     FAILURE
67   if (__imag__ cf != 0.0f)
68     FAILURE
69   if (__imag__ cd != 0.0)
70     FAILURE
71   if (__imag__ cld != 0.0l)
72     FAILURE
73
74   /*  Verify that the conversions from DFP types to complex is
75       determined by the rules of conversion to the real part.  */
76
77   /*  Convert _Decimal64 to _Complex float.  */
78   d64 = 0.125dl;
79   cf = d64;
80   if (__real__ cf != 0.125f)
81     FAILURE
82   /*  Convert _Decimal128 to _Complex double.  */
83   d128 = 1.25E-7dl;
84   cd = d128;
85   if (__real__ cd != 1.25E-7)
86     FAILURE
87
88   /*  Verify that conversion from complex to decimal floating types
89       results in the value of the real part converted to the result
90       type according to the rules of conversion between those types.  */
91
92   /*  Convert _Complex float to decimal float types.  */
93   cf = 2.0f *  __extension__ 1i + 2.25f;
94   d32 = cf;
95   d64 = cf;
96   d128 = cf;
97   if (d32 != 2.25DF)
98     FAILURE
99   if (d64 != 2.25DD)
100     FAILURE
101   if (d128 != 2.25DL)
102     FAILURE
103
104   /*  Convert _Complex double to decimal float types.  */
105   cd = 2.0 *  __extension__ 1i + 1.25;
106   d32 = cd;
107   d64 = cd;
108   d128 = cd;
109   if (d32 != 1.25DF)
110     FAILURE
111   if (d64 != 1.25DD)
112     FAILURE
113   if (d128 != 1.25DL)
114     FAILURE
115
116   /*  Convert _Complex long double to decimal float types.  */
117   cld = 2.0l *  __extension__ 1i + 0.0625l;
118   d32 = cld;
119   d64 = cld;
120   d128 = cld;
121   if (d32 != 0.0625DF)
122     FAILURE
123   if (d64 != 0.0625DD)
124     FAILURE
125   if (d128 != 0.0625DL)
126     FAILURE
127
128   return 0;
129 }