OSDN Git Service

b84e67d40716d61dfc7b057ad7c17004acd881e4
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / convert-dfp.c
1 /* { dg-options "-std=gnu99 -O0" } */
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(3) New.
6
7    Test various conversions involving decimal floating types. */
8
9 #ifndef __STDC_WANT_DEC_FP__
10 #define __STDC_WANT_DEC_FP__ 1
11 #endif
12
13 #include <float.h>
14
15 extern void abort (void);
16
17 volatile _Decimal32 d32;
18 volatile _Decimal64 d64;
19 volatile _Decimal128 d128;
20
21 int
22 main ()
23 {
24   /* Conversions to larger types.  */
25   d32 = 123.4df;
26   d64 = d32;
27   if (d64 != 123.4dd)
28     abort ();
29   d128 = d32;
30   if (d128 != 123.4dl)
31     abort ();
32   d64 = 345.678dd;
33   d128 = d64;
34   if (d128 != 345.678dl)
35     abort ();
36
37   /* Conversions to smaller types for which the value fits.  */
38   d64 = 3456.789dd;
39   d32 = d64;
40   if (d32 != 3456.789df)
41     abort ();
42   d128 = 123.4567dl;
43   d32 = d128;
44   if (d32 != 123.4567dl)
45     abort ();
46
47   d128 = 1234567890.123456dl;
48   d64 = d128;
49   if (d64 != 1234567890.123456dd)
50     abort ();
51
52   /* Test demotion to non-representable decimal floating type. */
53
54   /* Assumes a default rounding mode of 'near'.  This uses the rules
55      describe in the 27 July 2005 draft of IEEE 754r, which are much
56      more clear that what's described in draft 5 of N1107.  */
57
58   /* Rounds to what _Decimal32 can handle.  */
59   d64 = 9.99999949E96DD;
60   d32 = d64;
61   if (d32 != DEC32_MAX)
62     abort();
63
64   /* Rounds to more than _Decimal32 can handle.  */
65   d64 = 9.9999995E96DD;
66   d32 = d64;
67   if (d32 != __builtin_infd32())
68     abort();
69
70   /* Rounds to what _Decimal32 can handle.  */
71   d128 = 9.99999949E96DD;
72   d32 = d128;
73   if (d32 != DEC32_MAX)
74     abort();
75
76   /* Rounds to more than _Decimal32 can handle.  */
77   d128= 9.9999995E96DD;
78   d32 = d128;
79   if (d32 != __builtin_infd32())
80     abort();
81
82   /* Rounds to what _Decimal64 can handle.  */
83   d128 = 9.99999999999999949E384DL;
84   d64 = d128;
85   if (d64 != DEC64_MAX)
86     abort();
87
88   /* Rounds to more than _Decimal64 can handle.  */
89   d128 = 9.9999999999999995E384DL;
90   d64 = d128;
91   if (d64 != __builtin_infd64())
92     abort();
93
94   return 0;
95 }