OSDN Git Service

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