OSDN Git Service

* gcc.dg/dfp/func-array.c: Support -DDBG to report individual failures.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / convert-bfp.c
1 /* { dg-options "-std=gnu99" } */
2
3 /* N1150 5.2 Conversions among decimal floating types and between
4    decimal floating types and generic floating types.
5    C99 6.3.1.5(4) Conversions, arithmetic operands, real floating types.  */
6
7 /* Long double isn't supported yet at runtime, so disable those checks.  */
8 #define SKIP_LONG_DOUBLE
9
10 extern void abort (void);
11 static int failcnt;
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 d32;
23 volatile _Decimal64 d64;
24 volatile _Decimal128 d128;
25 volatile float sf;
26 volatile double df;
27 #ifndef SKIP_LONG_DOUBLE
28 volatile long double tf;
29 #endif
30
31 int
32 main ()
33 {
34   /* Conversions from decimal float to binary float. */
35
36   /* Conversions from _Decimal32. */
37   d32 = 2.0df;
38   sf = d32;
39   if (sf != 2.0f)
40     FAILURE
41
42   df = d32;
43   if (df != 2.0)
44     FAILURE
45
46 #ifndef SKIP_LONG_DOUBLE
47   tf = d32;
48   if (tf != 2.0l)
49     FAILURE
50 #endif
51
52   /* Conversions from _Decimal64. */
53   d64 = -7.0dd;
54   sf = d64;
55   if (sf != -7.0f)
56     FAILURE
57   
58   df = d64;
59   if (df != -7.0)
60     FAILURE
61
62 #ifndef SKIP_LONG_DOUBLE
63   tf = d64;
64   if (tf != -7.0l)
65     FAILURE
66 #endif
67
68   /* Conversions from _Decimal128. */
69   d128 = 30.0dl;
70   sf = d128;
71   if (sf != 30.0f)
72     FAILURE
73
74   df = d128;
75   if (df != 30.0)
76     FAILURE
77
78   df = d128;
79   if (df != 30.0l)
80     FAILURE
81
82   /* Conversions from binary float to decimal float. */
83   sf = 30.0f;
84   d32 = sf;
85   if (d32 != 30.0df)
86     FAILURE
87
88   d64 = sf;
89   if (d64 != 30.0dd)
90     FAILURE
91
92   df = -2.0;
93   d32 = df;
94   if (d32 != -2.0df)
95     FAILURE
96
97   d64 = df;
98   if (d64 != -2.0dd)
99     FAILURE
100
101   d128 = df;
102   if (d128 != -2.0dl)
103     FAILURE
104   
105   sf = 30.0f;
106   d128 = sf;
107   if (d128 != 30.0dl)
108     FAILURE
109
110 #ifndef SKIP_LONG_DOUBLE
111   tf = -22.0l;
112   d32 = tf;
113   if (d32 != -22.0df)
114     FAILURE
115
116   d64 = tf;
117   if (d64 != -22.0dd)
118     FAILURE
119
120   d128 = tf;
121   if (d128 != -22.0dl)
122     FAILURE
123 #endif
124
125   /* 2**(-11) = 0.00048828125. */
126   d128 = 0.000488281251dl;
127   sf = d128;
128   if (sf != 0.00048828125f)
129     FAILURE
130   /* 2**(-25) = 0.298023223876953125E-7.  */
131   d128 = 2.98023223876953125E-8dl;
132   df = d128;
133   if (df < (2.9802322387695312e-08 - 0.00000000001)
134       || df > (2.9802322387695312e-08 + 0.00000000001))
135     FAILURE
136
137   if (failcnt != 0)
138     abort ();
139
140   return 0;
141 }