OSDN Git Service

7b2b6d8351962687a1c07b8a2cc721fb5ad6c027
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / cast.c
1 /* { dg-do run } */
2 /* { dg-options "-std=gnu99" } */
3
4 /* C99 6.5.4 Cast operators.
5    Test valid casts involving decimal float.  */
6
7 extern void abort (void);
8
9 _Decimal32 d32;
10 _Decimal64 d64;
11 _Decimal128 d128;
12
13 static float f = 2.f;
14 static double d = 2.l;
15
16 int
17 main (void)
18 {
19   /* Casts between DFP types.  */
20   d32 = 1.2df;
21   d64 = 1.2dd;
22   d128 = 1.2dl;
23
24   if (d32 != (_Decimal32) d64)
25     abort ();
26   if (d32 != (_Decimal32) d128)
27     abort ();
28
29   if (d64 != (_Decimal64) d32)
30     abort ();
31   if (d64 != (_Decimal64) d128)
32     abort ();
33
34   if (d128 != (_Decimal128) d32)
35     abort ();
36   if (d128 != (_Decimal128) d64)
37     abort ();
38
39   /* Casts between generic and decimal floating point types.  Use a
40      value that we can assume can be represented exactly in all
41      representations. */
42   
43   d32 = 2.0df;
44   d64 = 2.0dd;
45   d128 = 2.0dl;
46
47   /* To generic floating types.  */
48   if ((float) d32 != 2.0f)
49     abort ();
50   if ((double) d32 != 2.0l)
51     abort ();
52   if ((float) d64 != 2.0f)
53     abort ();
54   if ((double) d64 != 2.0l)
55     abort ();
56   if ((float) d128 != 2.0f)
57     abort ();
58   if ((double) d128 != 2.0l)
59     abort ();
60
61   /* float to decimal floating types.  */
62   if (d32 != (_Decimal32) f)
63     abort ();
64   if (d64 != (_Decimal64) f)
65     abort ();
66   if (d128 != (_Decimal128) f)
67     abort ();
68
69   /* double to decimal floating types.  */
70   if (d32 != (_Decimal32) d)
71     abort ();
72   if (d64 != (_Decimal64) d)
73     abort ();
74   if (d128 != (_Decimal128) d)
75     abort ();
76
77   return 0;
78 }