OSDN Git Service

PR c/39035
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / dfp / convert-int-max.c
1 /* { dg-options "-std=gnu99 -O0" } */
2
3 /* N1150 5.1 Conversions from decimal float to integer.  */
4
5 /* Test decimal float to integer conversions for values at the limit of
6    what will fit into the destination type.  This assumes 32-bit int and
7    64-bit long long (there's a check for that below).  */
8
9 extern void abort (void);
10 int failcnt;
11
12 #ifdef DBG
13 extern int printf (const char *, ...);
14 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
15 #else
16 #define FAILURE abort ();
17 #endif
18
19 volatile _Decimal32 d32;
20 volatile _Decimal64 d64;
21 volatile _Decimal128 d128;
22 volatile int si;
23 volatile unsigned int ui;
24 volatile long long sll;
25 volatile unsigned long long ull;
26
27 void
28 doit ()
29 {
30   /* _Decimal32 to int.  */
31
32   d32 = 2147483.E3DF;
33   si = d32;
34   if (si != 2147483000)
35     FAILURE
36
37   d32 = -2147483.E3DF;
38   si = d32;
39   if (si != -2147483000)
40     FAILURE
41
42   /* _Decimal32 to unsigned int.  */
43
44   d32 = 4.294967E9DF;
45   ui = d32;
46   if (ui != 4294967000U)
47     FAILURE
48
49   /* _Decimal32 to long long.  */
50
51   d32 = 922.3372E16DF;
52   sll = d32;
53   if (sll != 9223372000000000000LL)
54     FAILURE
55
56   d32 = -92233.72E14DF;
57   sll = d32;
58   if (sll != -9223372000000000000LL)
59     FAILURE
60
61   /* _Decimal32 to unsigned long long.  */
62
63   d32 = .1844674E20DF;
64   ull = d32;
65   if (ull != 18446740000000000000ULL)
66     FAILURE
67
68   /* _Decimal64 to int.  */
69
70   d64 = 2.147483647E9DD;
71   si = d64;
72   if (si != 2147483647)
73     FAILURE
74
75   d64 = -2147483648.DD;
76   si = d64;
77   if (si != -2147483648)
78     FAILURE
79
80   /* _Decimal64 to unsigned int.  */
81
82   d64 = 42949.67295E5DD;
83   ui = d64;
84   if (ui != 4294967295)
85     FAILURE
86
87   /* _Decimal64 to long long.  */
88
89   d64 = 9.223372036854775E18DD;
90   sll = d64;
91   if (sll != 9223372036854775000LL)
92     FAILURE 
93
94   d64 = -92233720.36854775E11DD;
95   sll = d64;
96   if (sll != -9223372036854775000LL)
97     FAILURE
98
99   /* _Decimal64 to unsigned long long.  */
100   d64 = 1844674407370955.E4DD;
101   ull = d64;
102   if (ull != 18446744073709550000ULL)
103     FAILURE
104
105   /* _Decimal128 to int.  */
106
107   d128 = 2.147483647E9DL;
108   si = d128;
109   if (si != 2147483647)
110     FAILURE
111
112   d128 = -2147483648.DL;
113   si = d128;
114   if (si != -2147483648)
115     FAILURE
116
117   /* _Decimal128 to unsigned int.  */
118
119   d128 = 4294.967295E6DL;
120   ui = d128;
121   if (ui != 4294967295)
122     FAILURE
123
124   /* _Decimal128 to long long.  */
125
126   d128 = 9223372036854775807.DL;
127   sll = d128;
128   if (sll != 9223372036854775807LL)
129     FAILURE 
130
131   d128 = -9.223372036854775808E19DL;
132   sll = d128;
133   if (sll != -9223372036854775807LL - 1LL)
134     FAILURE
135
136   /* _Decimal128 to unsigned long long.  */
137   d128 = 18446744073709551615.DL;
138   ull = d128;
139   if (ull != 18446744073709551615ULL)
140     FAILURE
141 }
142
143 int
144 main ()
145 {
146   /* This test assumes 32-bit int and 64-bit long long.  */
147
148   if (sizeof (int) != 4 || sizeof (long long) != 8)
149     return 0;
150
151   doit ();
152
153   if (failcnt != 0)
154     abort ();
155   return 0;
156 }