container_access.cc: Remove 'test' variables.
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / compound-assignment.cc
blobff70268200b1072464a04e0b913235577a8fdb46
1 // Copyright (C) 2009-2016 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.6 Compound assignment (decimal32).
21 // ISO/IEC TR 24733 3.2.3.6 Compound assignment (decimal64).
22 // ISO/IEC TR 24733 3.2.4.6 Compound assignment (decimal128).
24 #include <decimal/decimal>
25 #include <testsuite_hooks.h>
27 using namespace std::decimal;
29 decimal32 d32 (5);
30 decimal64 d64 (-10);
31 decimal128 d128 (25);
32 int si = -2;
33 unsigned int ui = 5;
34 long sl = -10;
35 unsigned long ul = 20;
36 long long sll = -25;
37 unsigned long long ull = 50;
39 void
40 compound_assignment_add_32 (void)
42 decimal32 a (1000), b;
44 b = a; b += d32; VERIFY (b == 1005);
45 b = a; b += d64; VERIFY (b == 990);
46 b = a; b += d128; VERIFY (b == 1025);
47 b = a; b += si; VERIFY (b == 998);
48 b = a; b += ui; VERIFY (b == 1005);
49 b = a; b += sl; VERIFY (b == 990);
50 b = a; b += ul; VERIFY (b == 1020);
51 b = a; b += sll; VERIFY (b == 975);
52 b = a; b += ull; VERIFY (b == 1050);
55 void
56 compound_assignment_subtract_32 (void)
58 decimal32 a (1000), b;
60 b = a; b -= d32; VERIFY (b == 995);
61 b = a; b -= d64; VERIFY (b == 1010);
62 b = a; b -= d128; VERIFY (b == 975);
63 b = a; b -= si; VERIFY (b == 1002);
64 b = a; b -= ui; VERIFY (b == 995);
65 b = a; b -= sl; VERIFY (b == 1010);
66 b = a; b -= ul; VERIFY (b == 980);
67 b = a; b -= sll; VERIFY (b == 1025);
68 b = a; b -= ull; VERIFY (b == 950);
71 void
72 compound_assignment_multiply_32 (void)
74 decimal32 a (1000), b;
76 b = a; b *= d32; VERIFY (b == 5000);
77 b = a; b *= d64; VERIFY (b == -10000);
78 b = a; b *= d128; VERIFY (b == 25000);
79 b = a; b *= si; VERIFY (b == -2000);
80 b = a; b *= ui; VERIFY (b == 5000);
81 b = a; b *= sl; VERIFY (b == -10000);
82 b = a; b *= ul; VERIFY (b == 20000);
83 b = a; b *= sll; VERIFY (b == -25000);
84 b = a; b *= ull; VERIFY (b == 50000);
87 void
88 compound_assignment_divide_32 (void)
90 decimal32 a (1000), b;
92 b = a; b /= d32; VERIFY (b == 200);
93 b = a; b /= d64; VERIFY (b == -100);
94 b = a; b /= d128; VERIFY (b == 40);
95 b = a; b /= si; VERIFY (b == -500);
96 b = a; b /= ui; VERIFY (b == 200);
97 b = a; b /= sl; VERIFY (b == -100);
98 b = a; b /= ul; VERIFY (b == 50);
99 b = a; b /= sll; VERIFY (b == -40);
100 b = a; b /= ull; VERIFY (b == 20);
103 void
104 compound_assignment_add_64 (void)
106 decimal64 a (1000), b;
108 b = a; b += d32; VERIFY (b == 1005);
109 b = a; b += d64; VERIFY (b == 990);
110 b = a; b += d128; VERIFY (b == 1025);
111 b = a; b += si; VERIFY (b == 998);
112 b = a; b += ui; VERIFY (b == 1005);
113 b = a; b += sl; VERIFY (b == 990);
114 b = a; b += ul; VERIFY (b == 1020);
115 b = a; b += sll; VERIFY (b == 975);
116 b = a; b += ull; VERIFY (b == 1050);
119 void
120 compound_assignment_subtract_64 (void)
122 decimal64 a (1000), b;
124 b = a; b -= d32; VERIFY (b == 995);
125 b = a; b -= d64; VERIFY (b == 1010);
126 b = a; b -= d128; VERIFY (b == 975);
127 b = a; b -= si; VERIFY (b == 1002);
128 b = a; b -= ui; VERIFY (b == 995);
129 b = a; b -= sl; VERIFY (b == 1010);
130 b = a; b -= ul; VERIFY (b == 980);
131 b = a; b -= sll; VERIFY (b == 1025);
132 b = a; b -= ull; VERIFY (b == 950);
135 void
136 compound_assignment_multiply_64 (void)
138 decimal64 a (1000), b;
140 b = a; b *= d32; VERIFY (b == 5000);
141 b = a; b *= d64; VERIFY (b == -10000);
142 b = a; b *= d128; VERIFY (b == 25000);
143 b = a; b *= si; VERIFY (b == -2000);
144 b = a; b *= ui; VERIFY (b == 5000);
145 b = a; b *= sl; VERIFY (b == -10000);
146 b = a; b *= ul; VERIFY (b == 20000);
147 b = a; b *= sll; VERIFY (b == -25000);
148 b = a; b *= ull; VERIFY (b == 50000);
151 void
152 compound_assignment_divide_64 (void)
154 decimal64 a (1000), b;
156 b = a; b /= d32; VERIFY (b == 200);
157 b = a; b /= d64; VERIFY (b == -100);
158 b = a; b /= d128; VERIFY (b == 40);
159 b = a; b /= si; VERIFY (b == -500);
160 b = a; b /= ui; VERIFY (b == 200);
161 b = a; b /= sl; VERIFY (b == -100);
162 b = a; b /= ul; VERIFY (b == 50);
163 b = a; b /= sll; VERIFY (b == -40);
164 b = a; b /= ull; VERIFY (b == 20);
167 void
168 compound_assignment_add_128 (void)
170 decimal128 a (1000), b;
172 b = a; b += d32; VERIFY (b == 1005);
173 b = a; b += d64; VERIFY (b == 990);
174 b = a; b += d128; VERIFY (b == 1025);
175 b = a; b += si; VERIFY (b == 998);
176 b = a; b += ui; VERIFY (b == 1005);
177 b = a; b += sl; VERIFY (b == 990);
178 b = a; b += ul; VERIFY (b == 1020);
179 b = a; b += sll; VERIFY (b == 975);
180 b = a; b += ull; VERIFY (b == 1050);
183 void
184 compound_assignment_subtract_128 (void)
186 decimal128 a (1000), b;
188 b = a; b -= d32; VERIFY (b == 995);
189 b = a; b -= d64; VERIFY (b == 1010);
190 b = a; b -= d128; VERIFY (b == 975);
191 b = a; b -= si; VERIFY (b == 1002);
192 b = a; b -= ui; VERIFY (b == 995);
193 b = a; b -= sl; VERIFY (b == 1010);
194 b = a; b -= ul; VERIFY (b == 980);
195 b = a; b -= sll; VERIFY (b == 1025);
196 b = a; b -= ull; VERIFY (b == 950);
199 void
200 compound_assignment_multiply_128 (void)
202 decimal128 a (1000), b;
204 b = a; b *= d32; VERIFY (b == 5000);
205 b = a; b *= d64; VERIFY (b == -10000);
206 b = a; b *= d128; VERIFY (b == 25000);
207 b = a; b *= si; VERIFY (b == -2000);
208 b = a; b *= ui; VERIFY (b == 5000);
209 b = a; b *= sl; VERIFY (b == -10000);
210 b = a; b *= ul; VERIFY (b == 20000);
211 b = a; b *= sll; VERIFY (b == -25000);
212 b = a; b *= ull; VERIFY (b == 50000);
215 void
216 compound_assignment_divide_128 (void)
218 decimal128 a (1000), b;
220 b = a; b /= d32; VERIFY (b == 200);
221 b = a; b /= d64; VERIFY (b == -100);
222 b = a; b /= d128; VERIFY (b == 40);
223 b = a; b /= si; VERIFY (b == -500);
224 b = a; b /= ui; VERIFY (b == 200);
225 b = a; b /= sl; VERIFY (b == -100);
226 b = a; b /= ul; VERIFY (b == 50);
227 b = a; b /= sll; VERIFY (b == -40);
228 b = a; b /= ull; VERIFY (b == 20);
232 main ()
234 compound_assignment_add_32 ();
235 compound_assignment_subtract_32 ();
236 compound_assignment_multiply_32 ();
237 compound_assignment_divide_32 ();
239 compound_assignment_add_64 ();
240 compound_assignment_subtract_64 ();
241 compound_assignment_multiply_64 ();
242 compound_assignment_divide_64 ();
244 compound_assignment_add_128 ();
245 compound_assignment_subtract_128 ();
246 compound_assignment_multiply_128 ();
247 compound_assignment_divide_128 ();