s390.h (REGISTER_MOVE_COST, [...]): Remove.
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / binary-arith.cc
blob180bca57167bf7e9b8e599afafd816dc54f672a8
1 // Copyright (C) 2009 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.8 Binary arithmetic operators.
22 #include <decimal/decimal>
23 #include <testsuite_hooks.h>
25 using namespace std::decimal;
27 decimal32 d32 (5);
28 decimal64 d64 (-10);
29 decimal128 d128 (25);
30 int si = -20;
31 unsigned int ui = 50;
32 long sl = -10;
33 unsigned long ul = 20;
34 long long sll = -25;
35 unsigned long long ull = 50;
37 void
38 binary_add_32 (void)
40 decimal32 a (1000), b;
42 b = si + a; VERIFY (b == 980);
43 b = ui + a; VERIFY (b == 1050);
44 b = sl + a; VERIFY (b == 990);
45 b = ul + a; VERIFY (b == 1020);
46 b = sll + a; VERIFY (b == 975);
47 b = ull + a; VERIFY (b == 1050);
48 b = d32 + a; VERIFY (b == 1005);
49 b = (decimal32)(d64 + a); VERIFY (b == 990);
50 b = (decimal32)(d128 + a); VERIFY (b == 1025);
52 b = a + si; VERIFY (b == 980);
53 b = a + ui; VERIFY (b == 1050);
54 b = a + sl; VERIFY (b == 990);
55 b = a + ul; VERIFY (b == 1020);
56 b = a + sll; VERIFY (b == 975);
57 b = a + ull; VERIFY (b == 1050);
58 b = a + d32; VERIFY (b == 1005);
59 b = (decimal32)(a + d64); VERIFY (b == 990);
60 b = (decimal32)(a + d128); VERIFY (b == 1025);
63 void
64 binary_subtract_32 (void)
66 decimal32 a (1000), b;
68 b = a - si; VERIFY (b == 1020);
69 b = a - ui; VERIFY (b == 950);
70 b = a - sl; VERIFY (b == 1010);
71 b = a - ul; VERIFY (b == 980);
72 b = a - sll; VERIFY (b == 1025);
73 b = a - ull; VERIFY (b == 950);
74 b = a - d32; VERIFY (b == 995);
75 b = (decimal32)(a - d64); VERIFY (b == 1010);
76 b = (decimal32)(a - d128); VERIFY (b == 975);
78 a = -1000;
79 b = si - a; VERIFY (b == 980);
80 b = ui - a; VERIFY (b == 1050);
81 b = sl - a; VERIFY (b == 990);
82 b = ul - a; VERIFY (b == 1020);
83 b = sll - a; VERIFY (b == 975);
84 b = ull - a; VERIFY (b == 1050);
85 b = d32 - a; VERIFY (b == 1005);
86 b = (decimal32)(d64 - a); VERIFY (b == 990);
87 b = (decimal32)(d128 - a); VERIFY (b == 1025);
90 void
91 binary_multiply_32 (void)
93 decimal32 a (1000), b;
95 b = a * si; VERIFY (b == -20000);
96 b = a * ui; VERIFY (b == 50000);
97 b = a * sl; VERIFY (b == -10000);
98 b = a * ul; VERIFY (b == 20000);
99 b = a * sll; VERIFY (b == -25000);
100 b = a * ull; VERIFY (b == 50000);
101 b = a * d32; VERIFY (b == 5000);
102 b = (decimal32)(a * d64); VERIFY (b == -10000);
103 b = (decimal32)(a * d128); VERIFY (b == 25000);
105 b = si * a; VERIFY (b == -20000);
106 b = ui * a; VERIFY (b == 50000);
107 b = sl * a; VERIFY (b == -10000);
108 b = ul * a; VERIFY (b == 20000);
109 b = sll * a; VERIFY (b == -25000);
110 b = ull * a; VERIFY (b == 50000);
111 b = d32 * a; VERIFY (b == 5000);
112 b = (decimal32)(d64 * a); VERIFY (b == -10000);
113 b = (decimal32)(d128 * a); VERIFY (b == 25000);
116 void
117 binary_divide_32 (void)
119 decimal32 a (1000), b;
121 b = a / si; VERIFY (b == -50);
122 b = a / ui; VERIFY (b == 20);
123 b = a / sl; VERIFY (b == -100);
124 b = a / ul; VERIFY (b == 50);
125 b = a / sll; VERIFY (b == -40);
126 b = a / ull; VERIFY (b == 20);
127 b = a / d32; VERIFY (b == 200);
128 b = (decimal32)(a / d64); VERIFY (b == -100);
129 b = (decimal32)(a / d128); VERIFY (b == 40);
131 a = 5;
132 b = si / a; VERIFY (b == -4);
133 b = ui / a; VERIFY (b == 10);
134 b = sl / a; VERIFY (b == -2);
135 b = ul / a; VERIFY (b == 4);
136 b = sll / a; VERIFY (b == -5);
137 b = ull / a; VERIFY (b == 10);
138 b = d32 / a; VERIFY (b == 1);
139 b = (decimal32)(d64 / a); VERIFY (b == -2);
140 b = (decimal32)(d128 / a); VERIFY (b == 5);
143 void
144 binary_add_64 (void)
146 decimal64 a (1000), b;
148 b = a + si; VERIFY (b == 980);
149 b = a + ui; VERIFY (b == 1050);
150 b = a + sl; VERIFY (b == 990);
151 b = a + ul; VERIFY (b == 1020);
152 b = a + sll; VERIFY (b == 975);
153 b = a + ull; VERIFY (b == 1050);
154 b = a + d32; VERIFY (b == 1005);
155 b = a + d64; VERIFY (b == 990);
156 b = (decimal64)(a + d128); VERIFY (b == 1025);
158 b = a + si; VERIFY (b == 980);
159 b = a + ui; VERIFY (b == 1050);
160 b = a + sl; VERIFY (b == 990);
161 b = a + ul; VERIFY (b == 1020);
162 b = a + sll; VERIFY (b == 975);
163 b = a + ull; VERIFY (b == 1050);
164 b = a + d32; VERIFY (b == 1005);
165 b = a + d64; VERIFY (b == 990);
166 b = (decimal64)(a + d128); VERIFY (b == 1025);
169 void
170 binary_subtract_64 (void)
172 decimal64 a (1000), b;
174 b = a - si; VERIFY (b == 1020);
175 b = a - ui; VERIFY (b == 950);
176 b = a - sl; VERIFY (b == 1010);
177 b = a - ul; VERIFY (b == 980);
178 b = a - sll; VERIFY (b == 1025);
179 b = a - ull; VERIFY (b == 950);
180 b = a - d32; VERIFY (b == 995);
181 b = a - d64; VERIFY (b == 1010);
182 b = (decimal64)(a - d128); VERIFY (b == 975);
184 a = -1000;
185 b = si - a; VERIFY (b == 980);
186 b = ui - a; VERIFY (b == 1050);
187 b = sl - a; VERIFY (b == 990);
188 b = ul - a; VERIFY (b == 1020);
189 b = sll - a; VERIFY (b == 975);
190 b = ull - a; VERIFY (b == 1050);
191 b = d32 - a; VERIFY (b == 1005);
192 b = d64 - a; VERIFY (b == 990);
193 b = (decimal64)(d128 - a); VERIFY (b == 1025);
196 void
197 binary_multiply_64 (void)
199 decimal64 a (1000), b;
201 b = a * si; VERIFY (b == -20000);
202 b = a * ui; VERIFY (b == 50000);
203 b = a * sl; VERIFY (b == -10000);
204 b = a * ul; VERIFY (b == 20000);
205 b = a * sll; VERIFY (b == -25000);
206 b = a * ull; VERIFY (b == 50000);
207 b = a * d32; VERIFY (b == 5000);
208 b = a * d64; VERIFY (b == -10000);
209 b = (decimal64)(a * d128); VERIFY (b == 25000);
211 b = si * a; VERIFY (b == -20000);
212 b = ui * a; VERIFY (b == 50000);
213 b = sl * a; VERIFY (b == -10000);
214 b = ul * a; VERIFY (b == 20000);
215 b = sll * a; VERIFY (b == -25000);
216 b = ull * a; VERIFY (b == 50000);
217 b = d32 * a; VERIFY (b == 5000);
218 b = d64 * a; VERIFY (b == -10000);
219 b = (decimal64)(d128 * a); VERIFY (b == 25000);
222 void
223 binary_divide_64 (void)
225 decimal64 a (1000), b;
227 b = a / si; VERIFY (b == -50);
228 b = a / ui; VERIFY (b == 20);
229 b = a / sl; VERIFY (b == -100);
230 b = a / ul; VERIFY (b == 50);
231 b = a / sll; VERIFY (b == -40);
232 b = a / ull; VERIFY (b == 20);
233 b = a / d32; VERIFY (b == 200);
234 b = a / d64; VERIFY (b == -100);
235 b = (decimal64)(a / d128); VERIFY (b == 40);
237 a = 5;
238 b = si / a; VERIFY (b == -4);
239 b = ui / a; VERIFY (b == 10);
240 b = sl / a; VERIFY (b == -2);
241 b = ul / a; VERIFY (b == 4);
242 b = sll / a; VERIFY (b == -5);
243 b = ull / a; VERIFY (b == 10);
244 b = d32 / a; VERIFY (b == 1);
245 b = d64 / a; VERIFY (b == -2);
246 b = (decimal64)(d128 / a); VERIFY (b == 5);
249 void
250 binary_add_128 (void)
252 decimal128 a (1000), b;
254 b = a + si; VERIFY (b == 980);
255 b = a + ui; VERIFY (b == 1050);
256 b = a + sl; VERIFY (b == 990);
257 b = a + ul; VERIFY (b == 1020);
258 b = a + sll; VERIFY (b == 975);
259 b = a + ull; VERIFY (b == 1050);
260 b = a + d32; VERIFY (b == 1005);
261 b = a + d64; VERIFY (b == 990);
262 b = a + d128; VERIFY (b == 1025);
264 b = a + si; VERIFY (b == 980);
265 b = a + ui; VERIFY (b == 1050);
266 b = a + sl; VERIFY (b == 990);
267 b = a + ul; VERIFY (b == 1020);
268 b = a + sll; VERIFY (b == 975);
269 b = a + ull; VERIFY (b == 1050);
270 b = a + d32; VERIFY (b == 1005);
271 b = a + d64; VERIFY (b == 990);
272 b = a + d128; VERIFY (b == 1025);
275 void
276 binary_subtract_128 (void)
278 decimal128 a (1000), b;
280 b = a - si; VERIFY (b == 1020);
281 b = a - ui; VERIFY (b == 950);
282 b = a - sl; VERIFY (b == 1010);
283 b = a - ul; VERIFY (b == 980);
284 b = a - sll; VERIFY (b == 1025);
285 b = a - ull; VERIFY (b == 950);
286 b = a - d32; VERIFY (b == 995);
287 b = a - d64; VERIFY (b == 1010);
288 b = a - d128; VERIFY (b == 975);
290 a = -1000;
291 b = si - a; VERIFY (b == 980);
292 b = ui - a; VERIFY (b == 1050);
293 b = sl - a; VERIFY (b == 990);
294 b = ul - a; VERIFY (b == 1020);
295 b = sll - a; VERIFY (b == 975);
296 b = ull - a; VERIFY (b == 1050);
297 b = d32 - a; VERIFY (b == 1005);
298 b = d64 - a; VERIFY (b == 990);
299 b = d128 - a; VERIFY (b == 1025);
302 void
303 binary_multiply_128 (void)
305 decimal128 a (1000), b;
307 b = a * si; VERIFY (b == -20000);
308 b = a * ui; VERIFY (b == 50000);
309 b = a * sl; VERIFY (b == -10000);
310 b = a * ul; VERIFY (b == 20000);
311 b = a * sll; VERIFY (b == -25000);
312 b = a * ull; VERIFY (b == 50000);
313 b = a * d32; VERIFY (b == 5000);
314 b = a * d64; VERIFY (b == -10000);
315 b = a * d128; VERIFY (b == 25000);
317 b = si * a; VERIFY (b == -20000);
318 b = ui * a; VERIFY (b == 50000);
319 b = sl * a; VERIFY (b == -10000);
320 b = ul * a; VERIFY (b == 20000);
321 b = sll * a; VERIFY (b == -25000);
322 b = ull * a; VERIFY (b == 50000);
323 b = d32 * a; VERIFY (b == 5000);
324 b = d64 * a; VERIFY (b == -10000);
325 b = d128 * a; VERIFY (b == 25000);
328 void
329 binary_divide_128 (void)
331 decimal128 a (1000), b;
333 b = a / si; VERIFY (b == -50);
334 b = a / ui; VERIFY (b == 20);
335 b = a / sl; VERIFY (b == -100);
336 b = a / ul; VERIFY (b == 50);
337 b = a / sll; VERIFY (b == -40);
338 b = a / ull; VERIFY (b == 20);
339 b = a / d32; VERIFY (b == 200);
340 b = a / d64; VERIFY (b == -100);
341 b = a / d128; VERIFY (b == 40);
343 a = 5;
344 b = si / a; VERIFY (b == -4);
345 b = ui / a; VERIFY (b == 10);
346 b = sl / a; VERIFY (b == -2);
347 b = ul / a; VERIFY (b == 4);
348 b = sll / a; VERIFY (b == -5);
349 b = ull / a; VERIFY (b == 10);
350 b = d32 / a; VERIFY (b == 1);
351 b = d64 / a; VERIFY (b == -2);
352 b = d128 / a; VERIFY (b == 5);
356 main ()
358 binary_add_32 ();
359 binary_subtract_32 ();
360 binary_multiply_32 ();
361 binary_divide_32 ();
363 binary_add_64 ();
364 binary_subtract_64 ();
365 binary_multiply_64 ();
366 binary_divide_64 ();
368 binary_add_128 ();
369 binary_subtract_128 ();
370 binary_multiply_128 ();
371 binary_divide_128 ();