Merge from mainline
[official-gcc.git] / gcc / testsuite / gcc.dg / dfp / convert-bfp.c
blob53258489ebbfadad297cd094fd193453ed27a4fa
1 /* { dg-options "-std=gnu99" } */
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. */
7 volatile _Decimal32 d32;
8 volatile _Decimal64 d64;
9 volatile _Decimal128 d128;
10 volatile float sf;
11 volatile double df;
12 volatile long double tf;
14 extern void abort (void);
16 int
17 main ()
19 /* Conversions from decimal float to binary float. */
21 /* Conversions from _Decimal32. */
22 d32 = 2.0df;
23 sf = d32;
24 if (sf != 2.0f)
25 abort ();
27 df = d32;
28 if (df != 2.0)
29 abort ();
31 tf = d32;
32 if (tf != 2.0l)
33 abort ();
35 /* Conversions from _Decimal64. */
36 d64 = -7.0dd;
37 sf = d64;
38 if (sf != -7.0f)
39 abort ();
41 df = d64;
42 if (df != -7.0)
43 abort ();
45 tf = d64;
46 if (tf != -7.0l)
47 abort ();
49 /* Conversions from _Decimal128. */
50 d128 = 30.0dl;
51 sf = d128;
52 if (sf != 30.0f)
53 abort ();
55 df = d128;
56 if (df != 30.0)
57 abort ();
59 df = d128;
60 if (df != 30.0l)
61 abort ();
63 /* Conversions from binary float to decimal float. */
64 sf = 30.0f;
65 d32 = sf;
66 if (d32 != 30.0df)
67 abort ();
69 d64 = sf;
70 if (d64 != 30.0dd)
71 abort ();
73 df = -2.0;
74 d32 = df;
75 if (d32 != -2.0df)
76 abort ();
78 d64 = df;
79 if (d64 != -2.0dd)
80 abort ();
82 d128 = df;
83 if (d128 != -2.0dl)
84 abort ();
86 sf = 30.0f;
87 d128 = sf;
88 if (d128 != 30.0dl)
89 abort ();
91 tf = -22.0l;
92 d32 = tf;
93 if (d32 != -22.0df)
94 abort ();
96 d64 = tf;
97 if (d64 != -22.0dd)
98 abort ();
100 d128 = tf;
101 if (d128 != -22.0dl)
102 abort ();
104 /* 2**(-11) = 0.00048828125. */
105 d128 = 0.000488281251dl;
106 sf = d128;
107 if (sf != 0.00048828125f)
108 abort ();
109 /* 2**(-25) = 0.298023223876953125E-7. */
110 d128 = 2.98023223876953125E-8dl;
111 df = d128;
112 if (df < (2.9802322387695312e-08 - 0.00000000001)
113 || df > (2.9802322387695312e-08 + 0.00000000001))
114 abort ();
116 return 0;