OSDN Git Service

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