Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / conversion-from-integral.cc
blob1ab4cc2426319b2b46c1b809a8fdc72c4ce37989
1 // Copyright (C) 2009-2013 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-require-effective-target dfp }
20 // ISO/IEC TR 24733 3.2.2.3 Conversion from integral type (decimal32).
21 // ISO/IEC TR 24733 3.2.3.3 Conversion from integral type (decimal64).
22 // ISO/IEC TR 24733 3.2.4.3 Conversion from integral type (decimal128).
24 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
27 using namespace std::decimal;
29 void
30 conversion_from_integral_p32 ()
32 bool test __attribute__((unused)) = true;
33 decimal32 d;
34 decimal32 from_si (1);
35 decimal32 from_ui (2U);
36 decimal32 from_sl (3L);
37 decimal32 from_ul (4UL);
38 decimal32 from_sll (5LL);
39 decimal32 from_ull (6ULL);
41 d++; VERIFY (from_si == d);
42 d++; VERIFY (from_ui == d);
43 d++; VERIFY (from_sl == d);
44 d++; VERIFY (from_ul == d);
45 d++; VERIFY (from_sll == d);
46 d++; VERIFY (from_ull == d);
48 from_si = 7;
49 d++; VERIFY (from_si == d);
50 from_ui = 8U;
51 d++; VERIFY (from_ui == d);
52 from_sl = 9L;
53 d++; VERIFY (from_sl == d);
54 from_ul = 10UL;
55 d++; VERIFY (from_ul == d);
56 from_sll = 11LL;
57 d++; VERIFY (from_sll == d);
58 from_ull = 12ULL;
59 d++; VERIFY (from_ull == d);
62 void
63 conversion_from_integral_m32 ()
65 bool test __attribute__((unused)) = true;
66 decimal32 d;
67 decimal32 from_si (-1);
68 decimal32 from_sl (-2L);
69 decimal32 from_sll (-3LL);
71 d--; VERIFY (from_si == d);
72 d--; VERIFY (from_sl == d);
73 d--; VERIFY (from_sll == d);
75 from_si = -4;
76 d--; VERIFY (from_si == d);
77 from_sl = -5L;
78 d--; VERIFY (from_sl == d);
79 from_sll = -6LL;
80 d--; VERIFY (from_sll == d);
83 void
84 conversion_from_integral_p64 ()
86 bool test __attribute__((unused)) = true;
87 decimal64 d;
88 decimal64 from_si (1);
89 decimal64 from_ui (2U);
90 decimal64 from_sl (3L);
91 decimal64 from_ul (4UL);
92 decimal64 from_sll (5LL);
93 decimal64 from_ull (6ULL);
95 d++; VERIFY (from_si == d);
96 d++; VERIFY (from_ui == d);
97 d++; VERIFY (from_sl == d);
98 d++; VERIFY (from_ul == d);
99 d++; VERIFY (from_sll == d);
100 d++; VERIFY (from_ull == d);
102 from_si = 7;
103 d++; VERIFY (from_si == d);
104 from_ui = 8U;
105 d++; VERIFY (from_ui == d);
106 from_sl = 9L;
107 d++; VERIFY (from_sl == d);
108 from_ul = 10UL;
109 d++; VERIFY (from_ul == d);
110 from_sll = 11LL;
111 d++; VERIFY (from_sll == d);
112 from_ull = 12ULL;
113 d++; VERIFY (from_ull == d);
116 void
117 conversion_from_integral_m64 ()
119 bool test __attribute__((unused)) = true;
120 decimal64 d;
121 decimal64 from_si (-1);
122 decimal64 from_sl (-2L);
123 decimal64 from_sll (-3LL);
125 d--; VERIFY (from_si == d);
126 d--; VERIFY (from_sl == d);
127 d--; VERIFY (from_sll == d);
129 from_si = -4;
130 d--; VERIFY (from_si == d);
131 from_sl = -5L;
132 d--; VERIFY (from_sl == d);
133 from_sll = -6LL;
134 d--; VERIFY (from_sll == d);
137 void
138 conversion_from_integral_p128 ()
140 bool test __attribute__((unused)) = true;
141 decimal128 d;
142 decimal128 from_si (1);
143 decimal128 from_ui (2U);
144 decimal128 from_sl (3L);
145 decimal128 from_ul (4UL);
146 decimal128 from_sll (5LL);
147 decimal128 from_ull (6ULL);
149 d++; VERIFY (from_si == d);
150 d++; VERIFY (from_ui == d);
151 d++; VERIFY (from_sl == d);
152 d++; VERIFY (from_ul == d);
153 d++; VERIFY (from_sll == d);
154 d++; VERIFY (from_ull == d);
156 from_si = 7;
157 d++; VERIFY (from_si == d);
158 from_ui = 8U;
159 d++; VERIFY (from_ui == d);
160 from_sl = 9L;
161 d++; VERIFY (from_sl == d);
162 from_ul = 10UL;
163 d++; VERIFY (from_ul == d);
164 from_sll = 11LL;
165 d++; VERIFY (from_sll == d);
166 from_ull = 12ULL;
169 void
170 conversion_from_integral_m128 ()
172 bool test __attribute__((unused)) = true;
173 decimal128 d;
174 decimal128 from_si (-1);
175 decimal128 from_sl (-2L);
176 decimal128 from_sll (-3LL);
178 d--; VERIFY (from_si == d);
179 d--; VERIFY (from_sl == d);
180 d--; VERIFY (from_sll == d);
182 from_si = -4;
183 d--; VERIFY (from_si == d);
184 from_sl = -5L;
185 d--; VERIFY (from_sl == d);
186 from_sll = -6LL;
187 d--; VERIFY (from_sll == d);
191 main ()
193 conversion_from_integral_p32 ();
194 conversion_from_integral_m32 ();
195 conversion_from_integral_p64 ();
196 conversion_from_integral_m64 ();
197 conversion_from_integral_p128 ();
198 conversion_from_integral_m128 ();