OSDN Git Service

Merged with libbbid branch at revision 126349.
[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 static int failcnt;
17
18 /* Support compiling the test to report individual failures; default is
19    to abort as soon as a check fails.  */
20 #ifdef DBG
21 #include <stdio.h>
22 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
23 #else
24 #define FAILURE abort ();
25 #endif
26
27 volatile _Decimal32 d32;
28 volatile _Decimal64 d64;
29 volatile _Decimal128 d128;
30
31 int
32 main ()
33 {
34   /* Conversions to larger types.  */
35   d32 = 123.4df;
36   d64 = d32;
37   if (d64 != 123.4dd)
38     FAILURE
39   d128 = d32;
40   if (d128 != 123.4dl)
41     FAILURE
42   d64 = 345.678dd;
43   d128 = d64;
44   if (d128 != 345.678dl)
45     FAILURE
46
47   /* Conversions to smaller types for which the value fits.  */
48   d64 = 3456.789dd;
49   d32 = d64;
50   if (d32 != 3456.789df)
51     FAILURE
52   d128 = 123.4567dl;
53   d32 = d128;
54   if (d32 != 123.4567df)
55     FAILURE
56
57   d128 = 1234567890.123456dl;
58   d64 = d128;
59   if (d64 != 1234567890.123456dd)
60     FAILURE
61
62   /* Test demotion to non-representable decimal floating type. */
63
64   /* Assumes a default rounding mode of 'near'.  This uses the rules
65      describe in the 27 July 2005 draft of IEEE 754r, which are much
66      more clear that what's described in draft 5 of N1107.  */
67
68   /* Rounds to what _Decimal32 can handle.  */
69   d64 = 9.99999949E96DD;
70   d32 = d64;
71   if (d32 != DEC32_MAX)
72     FAILURE
73
74   /* Rounds to more than _Decimal32 can handle.  */
75   d64 = 9.9999995E96DD;
76   d32 = d64;
77   if (d32 != __builtin_infd32())
78     FAILURE
79
80   /* Rounds to what _Decimal32 can handle.  */
81   d128 = 9.99999949E96DD;
82   d32 = d128;
83   if (d32 != DEC32_MAX)
84     FAILURE
85
86   /* Rounds to more than _Decimal32 can handle.  */
87   d128= 9.9999995E96DD;
88   d32 = d128;
89   if (d32 != __builtin_infd32())
90     FAILURE
91
92   /* Rounds to what _Decimal64 can handle.  */
93   d128 = 9.99999999999999949E384DL;
94   d64 = d128;
95   if (d64 != DEC64_MAX)
96     FAILURE
97
98   /* Rounds to more than _Decimal64 can handle.  */
99   d128 = 9.9999999999999995E384DL;
100   d64 = d128;
101   if (d64 != __builtin_infd64())
102     FAILURE
103
104   if (failcnt != 0)
105     abort ();
106
107   return 0;
108 }