]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/decimal/compound-assignment-memfunc.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / decimal / compound-assignment-memfunc.cc
CommitLineData
f1717362 1// Copyright (C) 2009-2016 Free Software Foundation, Inc.
a9c001cb 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.
8
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.
13
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/>.
17
5adf1dac 18// { dg-require-effective-target dfp }
a9c001cb 19
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).
23
24// Access member functions directly.
25
26#include <decimal/decimal>
27#include <testsuite_hooks.h>
28
29using namespace std::decimal;
30
31decimal32 d32 (5);
32decimal64 d64 (-10);
33decimal128 d128 (25);
34int si = -2;
35unsigned int ui = 5;
36long sl = -10;
37unsigned long ul = 20;
38long long sll = -25;
39unsigned long long ull = 50;
40
41void
42compound_assignment_add_32 (void)
43{
0b42d8d9 44 bool test __attribute__((unused)) = true;
a9c001cb 45 decimal32 a (1000), b;
46
47 b = a; b.operator+=(d32); VERIFY (b == 1005);
48 b = a; b.operator+=(d64); VERIFY (b == 990);
49 b = a; b.operator+=(d128); VERIFY (b == 1025);
50 b = a; b.operator+=(si); VERIFY (b == 998);
51 b = a; b.operator+=(ui); VERIFY (b == 1005);
52 b = a; b.operator+=(sl); VERIFY (b == 990);
53 b = a; b.operator+=(ul); VERIFY (b == 1020);
54 b = a; b.operator+=(sll); VERIFY (b == 975);
55 b = a; b.operator+=(ull); VERIFY (b == 1050);
56}
57
58void
59compound_assignment_subtract_32 (void)
60{
0b42d8d9 61 bool test __attribute__((unused)) = true;
a9c001cb 62 decimal32 a (1000), b;
63
64 b = a; b.operator-=(d32); VERIFY (b == 995);
65 b = a; b.operator-=(d64); VERIFY (b == 1010);
66 b = a; b.operator-=(d128); VERIFY (b == 975);
67 b = a; b.operator-=(si); VERIFY (b == 1002);
68 b = a; b.operator-=(ui); VERIFY (b == 995);
69 b = a; b.operator-=(sl); VERIFY (b == 1010);
70 b = a; b.operator-=(ul); VERIFY (b == 980);
71 b = a; b.operator-=(sll); VERIFY (b == 1025);
72 b = a; b.operator-=(ull); VERIFY (b == 950);
73}
74
75void
76compound_assignment_multiply_32 (void)
77{
0b42d8d9 78 bool test __attribute__((unused)) = true;
a9c001cb 79 decimal32 a (1000), b;
80
81 b = a; b.operator*=(d32); VERIFY (b == 5000);
82 b = a; b.operator*=(d64); VERIFY (b == -10000);
83 b = a; b.operator*=(d128); VERIFY (b == 25000);
84 b = a; b.operator*=(si); VERIFY (b == -2000);
85 b = a; b.operator*=(ui); VERIFY (b == 5000);
86 b = a; b.operator*=(sl); VERIFY (b == -10000);
87 b = a; b.operator*=(ul); VERIFY (b == 20000);
88 b = a; b.operator*=(sll); VERIFY (b == -25000);
89 b = a; b.operator*=(ull); VERIFY (b == 50000);
90}
91
92void
93compound_assignment_divide_32 (void)
94{
0b42d8d9 95 bool test __attribute__((unused)) = true;
a9c001cb 96 decimal32 a (1000), b;
97
98 b = a; b.operator/=(d32); VERIFY (b == 200);
99 b = a; b.operator/=(d64); VERIFY (b == -100);
100 b = a; b.operator/=(d128); VERIFY (b == 40);
101 b = a; b.operator/=(si); VERIFY (b == -500);
102 b = a; b.operator/=(ui); VERIFY (b == 200);
103 b = a; b.operator/=(sl); VERIFY (b == -100);
104 b = a; b.operator/=(ul); VERIFY (b == 50);
105 b = a; b.operator/=(sll); VERIFY (b == -40);
106 b = a; b.operator/=(ull); VERIFY (b == 20);
107}
108
109void
110compound_assignment_add_64 (void)
111{
0b42d8d9 112 bool test __attribute__((unused)) = true;
a9c001cb 113 decimal64 a (1000), b;
114
115 b = a; b.operator+=(d32); VERIFY (b == 1005);
116 b = a; b.operator+=(d64); VERIFY (b == 990);
117 b = a; b.operator+=(d128); VERIFY (b == 1025);
118 b = a; b.operator+=(si); VERIFY (b == 998);
119 b = a; b.operator+=(ui); VERIFY (b == 1005);
120 b = a; b.operator+=(sl); VERIFY (b == 990);
121 b = a; b.operator+=(ul); VERIFY (b == 1020);
122 b = a; b.operator+=(sll); VERIFY (b == 975);
123 b = a; b.operator+=(ull); VERIFY (b == 1050);
124}
125
126void
127compound_assignment_subtract_64 (void)
128{
0b42d8d9 129 bool test __attribute__((unused)) = true;
a9c001cb 130 decimal64 a (1000), b;
131
132 b = a; b.operator-=(d32); VERIFY (b == 995);
133 b = a; b.operator-=(d64); VERIFY (b == 1010);
134 b = a; b.operator-=(d128); VERIFY (b == 975);
135 b = a; b.operator-=(si); VERIFY (b == 1002);
136 b = a; b.operator-=(ui); VERIFY (b == 995);
137 b = a; b.operator-=(sl); VERIFY (b == 1010);
138 b = a; b.operator-=(ul); VERIFY (b == 980);
139 b = a; b.operator-=(sll); VERIFY (b == 1025);
140 b = a; b.operator-=(ull); VERIFY (b == 950);
141}
142
143void
144compound_assignment_multiply_64 (void)
145{
0b42d8d9 146 bool test __attribute__((unused)) = true;
a9c001cb 147 decimal64 a (1000), b;
148
149 b = a; b.operator*=(d32); VERIFY (b == 5000);
150 b = a; b.operator*=(d64); VERIFY (b == -10000);
151 b = a; b.operator*=(d128); VERIFY (b == 25000);
152 b = a; b.operator*=(si); VERIFY (b == -2000);
153 b = a; b.operator*=(ui); VERIFY (b == 5000);
154 b = a; b.operator*=(sl); VERIFY (b == -10000);
155 b = a; b.operator*=(ul); VERIFY (b == 20000);
156 b = a; b.operator*=(sll); VERIFY (b == -25000);
157 b = a; b.operator*=(ull); VERIFY (b == 50000);
158}
159
160void
161compound_assignment_divide_64 (void)
162{
0b42d8d9 163 bool test __attribute__((unused)) = true;
a9c001cb 164 decimal64 a (1000), b;
165
166 b = a; b.operator/=(d32); VERIFY (b == 200);
167 b = a; b.operator/=(d64); VERIFY (b == -100);
168 b = a; b.operator/=(d128); VERIFY (b == 40);
169 b = a; b.operator/=(si); VERIFY (b == -500);
170 b = a; b.operator/=(ui); VERIFY (b == 200);
171 b = a; b.operator/=(sl); VERIFY (b == -100);
172 b = a; b.operator/=(ul); VERIFY (b == 50);
173 b = a; b.operator/=(sll); VERIFY (b == -40);
174 b = a; b.operator/=(ull); VERIFY (b == 20);
175}
176
177void
178compound_assignment_add_128 (void)
179{
0b42d8d9 180 bool test __attribute__((unused)) = true;
a9c001cb 181 decimal128 a (1000), b;
182
183 b = a; b.operator+=(d32); VERIFY (b == 1005);
184 b = a; b.operator+=(d64); VERIFY (b == 990);
185 b = a; b.operator+=(d128); VERIFY (b == 1025);
186 b = a; b.operator+=(si); VERIFY (b == 998);
187 b = a; b.operator+=(ui); VERIFY (b == 1005);
188 b = a; b.operator+=(sl); VERIFY (b == 990);
189 b = a; b.operator+=(ul); VERIFY (b == 1020);
190 b = a; b.operator+=(sll); VERIFY (b == 975);
191 b = a; b.operator+=(ull); VERIFY (b == 1050);
192}
193
194void
195compound_assignment_subtract_128 (void)
196{
0b42d8d9 197 bool test __attribute__((unused)) = true;
a9c001cb 198 decimal128 a (1000), b;
199
200 b = a; b.operator-=(d32); VERIFY (b == 995);
201 b = a; b.operator-=(d64); VERIFY (b == 1010);
202 b = a; b.operator-=(d128); VERIFY (b == 975);
203 b = a; b.operator-=(si); VERIFY (b == 1002);
204 b = a; b.operator-=(ui); VERIFY (b == 995);
205 b = a; b.operator-=(sl); VERIFY (b == 1010);
206 b = a; b.operator-=(ul); VERIFY (b == 980);
207 b = a; b.operator-=(sll); VERIFY (b == 1025);
208 b = a; b.operator-=(ull); VERIFY (b == 950);
209}
210
211void
212compound_assignment_multiply_128 (void)
213{
0b42d8d9 214 bool test __attribute__((unused)) = true;
a9c001cb 215 decimal128 a (1000), b;
216
217 b = a; b.operator*=(d32); VERIFY (b == 5000);
218 b = a; b.operator*=(d64); VERIFY (b == -10000);
219 b = a; b.operator*=(d128); VERIFY (b == 25000);
220 b = a; b.operator*=(si); VERIFY (b == -2000);
221 b = a; b.operator*=(ui); VERIFY (b == 5000);
222 b = a; b.operator*=(sl); VERIFY (b == -10000);
223 b = a; b.operator*=(ul); VERIFY (b == 20000);
224 b = a; b.operator*=(sll); VERIFY (b == -25000);
225 b = a; b.operator*=(ull); VERIFY (b == 50000);
226}
227
228void
229compound_assignment_divide_128 (void)
230{
0b42d8d9 231 bool test __attribute__((unused)) = true;
a9c001cb 232 decimal128 a (1000), b;
233
234 b = a; b.operator/=(d32); VERIFY (b == 200);
235 b = a; b.operator/=(d64); VERIFY (b == -100);
236 b = a; b.operator/=(d128); VERIFY (b == 40);
237 b = a; b.operator/=(si); VERIFY (b == -500);
238 b = a; b.operator/=(ui); VERIFY (b == 200);
239 b = a; b.operator/=(sl); VERIFY (b == -100);
240 b = a; b.operator/=(ul); VERIFY (b == 50);
241 b = a; b.operator/=(sll); VERIFY (b == -40);
242 b = a; b.operator/=(ull); VERIFY (b == 20);
243}
244
245int
246main ()
247{
248 compound_assignment_add_32 ();
249 compound_assignment_subtract_32 ();
250 compound_assignment_multiply_32 ();
251 compound_assignment_divide_32 ();
252
253 compound_assignment_add_64 ();
254 compound_assignment_subtract_64 ();
255 compound_assignment_multiply_64 ();
256 compound_assignment_divide_64 ();
257
258 compound_assignment_add_128 ();
259 compound_assignment_subtract_128 ();
260 compound_assignment_multiply_128 ();
261 compound_assignment_divide_128 ();
262}