OSDN Git Service

PR c/39035
[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 int failcnt;
8                                                                                 
9 #ifdef DBG
10 extern int printf (const char *, ...);
11 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
12 #else
13 #define FAILURE abort ();
14 #endif
15
16 _Decimal32 d32;
17 _Decimal64 d64;
18 _Decimal128 d128;
19
20 static float f = 2.f;
21 static double d = 2.l;
22
23 int
24 main (void)
25 {
26   /* Casts between DFP types.  */
27   d32 = 1.2df;
28   d64 = 1.2dd;
29   d128 = 1.2dl;
30
31   if (d32 != (_Decimal32) d64)
32     FAILURE
33   if (d32 != (_Decimal32) d128)
34     FAILURE
35
36   if (d64 != (_Decimal64) d32)
37     FAILURE
38   if (d64 != (_Decimal64) d128)
39     FAILURE
40
41   if (d128 != (_Decimal128) d32)
42     FAILURE
43   if (d128 != (_Decimal128) d64)
44     FAILURE
45
46   /* Casts between generic and decimal floating point types.  Use a
47      value that we can assume can be represented exactly in all
48      representations. */
49   
50   d32 = 2.0df;
51   d64 = 2.0dd;
52   d128 = 2.0dl;
53
54   /* To generic floating types.  */
55   if ((float) d32 != 2.0f)
56     FAILURE
57   if ((double) d32 != 2.0l)
58     FAILURE
59   if ((float) d64 != 2.0f)
60     FAILURE
61   if ((double) d64 != 2.0l)
62     FAILURE
63   if ((float) d128 != 2.0f)
64     FAILURE
65   if ((double) d128 != 2.0l)
66     FAILURE
67
68   /* float to decimal floating types.  */
69   if (d32 != (_Decimal32) f)
70     FAILURE
71   if (d64 != (_Decimal64) f)
72     FAILURE
73   if (d128 != (_Decimal128) f)
74     FAILURE
75
76   /* double to decimal floating types.  */
77   if (d32 != (_Decimal32) d)
78     FAILURE
79   if (d64 != (_Decimal64) d)
80     FAILURE
81   if (d128 != (_Decimal128) d)
82     FAILURE
83
84   if (failcnt != 0)
85     abort ();
86
87   return 0;
88 }