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