]> 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
83ffe9cd 1// Copyright (C) 2009-2023 Free Software Foundation, Inc.
4cdc8761
BK
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
02ebbe2f 18// { dg-require-effective-target dfp }
4cdc8761
BK
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{
44 decimal32 a (1000), b;
45
46 b = a; b.operator+=(d32); VERIFY (b == 1005);
47 b = a; b.operator+=(d64); VERIFY (b == 990);
48 b = a; b.operator+=(d128); VERIFY (b == 1025);
49 b = a; b.operator+=(si); VERIFY (b == 998);
50 b = a; b.operator+=(ui); VERIFY (b == 1005);
51 b = a; b.operator+=(sl); VERIFY (b == 990);
52 b = a; b.operator+=(ul); VERIFY (b == 1020);
53 b = a; b.operator+=(sll); VERIFY (b == 975);
54 b = a; b.operator+=(ull); VERIFY (b == 1050);
55}
56
57void
58compound_assignment_subtract_32 (void)
59{
60 decimal32 a (1000), b;
61
62 b = a; b.operator-=(d32); VERIFY (b == 995);
63 b = a; b.operator-=(d64); VERIFY (b == 1010);
64 b = a; b.operator-=(d128); VERIFY (b == 975);
65 b = a; b.operator-=(si); VERIFY (b == 1002);
66 b = a; b.operator-=(ui); VERIFY (b == 995);
67 b = a; b.operator-=(sl); VERIFY (b == 1010);
68 b = a; b.operator-=(ul); VERIFY (b == 980);
69 b = a; b.operator-=(sll); VERIFY (b == 1025);
70 b = a; b.operator-=(ull); VERIFY (b == 950);
71}
72
73void
74compound_assignment_multiply_32 (void)
75{
76 decimal32 a (1000), b;
77
78 b = a; b.operator*=(d32); VERIFY (b == 5000);
79 b = a; b.operator*=(d64); VERIFY (b == -10000);
80 b = a; b.operator*=(d128); VERIFY (b == 25000);
81 b = a; b.operator*=(si); VERIFY (b == -2000);
82 b = a; b.operator*=(ui); VERIFY (b == 5000);
83 b = a; b.operator*=(sl); VERIFY (b == -10000);
84 b = a; b.operator*=(ul); VERIFY (b == 20000);
85 b = a; b.operator*=(sll); VERIFY (b == -25000);
86 b = a; b.operator*=(ull); VERIFY (b == 50000);
87}
88
89void
90compound_assignment_divide_32 (void)
91{
92 decimal32 a (1000), b;
93
94 b = a; b.operator/=(d32); VERIFY (b == 200);
95 b = a; b.operator/=(d64); VERIFY (b == -100);
96 b = a; b.operator/=(d128); VERIFY (b == 40);
97 b = a; b.operator/=(si); VERIFY (b == -500);
98 b = a; b.operator/=(ui); VERIFY (b == 200);
99 b = a; b.operator/=(sl); VERIFY (b == -100);
100 b = a; b.operator/=(ul); VERIFY (b == 50);
101 b = a; b.operator/=(sll); VERIFY (b == -40);
102 b = a; b.operator/=(ull); VERIFY (b == 20);
103}
104
105void
106compound_assignment_add_64 (void)
107{
108 decimal64 a (1000), b;
109
110 b = a; b.operator+=(d32); VERIFY (b == 1005);
111 b = a; b.operator+=(d64); VERIFY (b == 990);
112 b = a; b.operator+=(d128); VERIFY (b == 1025);
113 b = a; b.operator+=(si); VERIFY (b == 998);
114 b = a; b.operator+=(ui); VERIFY (b == 1005);
115 b = a; b.operator+=(sl); VERIFY (b == 990);
116 b = a; b.operator+=(ul); VERIFY (b == 1020);
117 b = a; b.operator+=(sll); VERIFY (b == 975);
118 b = a; b.operator+=(ull); VERIFY (b == 1050);
119}
120
121void
122compound_assignment_subtract_64 (void)
123{
124 decimal64 a (1000), b;
125
126 b = a; b.operator-=(d32); VERIFY (b == 995);
127 b = a; b.operator-=(d64); VERIFY (b == 1010);
128 b = a; b.operator-=(d128); VERIFY (b == 975);
129 b = a; b.operator-=(si); VERIFY (b == 1002);
130 b = a; b.operator-=(ui); VERIFY (b == 995);
131 b = a; b.operator-=(sl); VERIFY (b == 1010);
132 b = a; b.operator-=(ul); VERIFY (b == 980);
133 b = a; b.operator-=(sll); VERIFY (b == 1025);
134 b = a; b.operator-=(ull); VERIFY (b == 950);
135}
136
137void
138compound_assignment_multiply_64 (void)
139{
140 decimal64 a (1000), b;
141
142 b = a; b.operator*=(d32); VERIFY (b == 5000);
143 b = a; b.operator*=(d64); VERIFY (b == -10000);
144 b = a; b.operator*=(d128); VERIFY (b == 25000);
145 b = a; b.operator*=(si); VERIFY (b == -2000);
146 b = a; b.operator*=(ui); VERIFY (b == 5000);
147 b = a; b.operator*=(sl); VERIFY (b == -10000);
148 b = a; b.operator*=(ul); VERIFY (b == 20000);
149 b = a; b.operator*=(sll); VERIFY (b == -25000);
150 b = a; b.operator*=(ull); VERIFY (b == 50000);
151}
152
153void
154compound_assignment_divide_64 (void)
155{
156 decimal64 a (1000), b;
157
158 b = a; b.operator/=(d32); VERIFY (b == 200);
159 b = a; b.operator/=(d64); VERIFY (b == -100);
160 b = a; b.operator/=(d128); VERIFY (b == 40);
161 b = a; b.operator/=(si); VERIFY (b == -500);
162 b = a; b.operator/=(ui); VERIFY (b == 200);
163 b = a; b.operator/=(sl); VERIFY (b == -100);
164 b = a; b.operator/=(ul); VERIFY (b == 50);
165 b = a; b.operator/=(sll); VERIFY (b == -40);
166 b = a; b.operator/=(ull); VERIFY (b == 20);
167}
168
169void
170compound_assignment_add_128 (void)
171{
172 decimal128 a (1000), b;
173
174 b = a; b.operator+=(d32); VERIFY (b == 1005);
175 b = a; b.operator+=(d64); VERIFY (b == 990);
176 b = a; b.operator+=(d128); VERIFY (b == 1025);
177 b = a; b.operator+=(si); VERIFY (b == 998);
178 b = a; b.operator+=(ui); VERIFY (b == 1005);
179 b = a; b.operator+=(sl); VERIFY (b == 990);
180 b = a; b.operator+=(ul); VERIFY (b == 1020);
181 b = a; b.operator+=(sll); VERIFY (b == 975);
182 b = a; b.operator+=(ull); VERIFY (b == 1050);
183}
184
185void
186compound_assignment_subtract_128 (void)
187{
188 decimal128 a (1000), b;
189
190 b = a; b.operator-=(d32); VERIFY (b == 995);
191 b = a; b.operator-=(d64); VERIFY (b == 1010);
192 b = a; b.operator-=(d128); VERIFY (b == 975);
193 b = a; b.operator-=(si); VERIFY (b == 1002);
194 b = a; b.operator-=(ui); VERIFY (b == 995);
195 b = a; b.operator-=(sl); VERIFY (b == 1010);
196 b = a; b.operator-=(ul); VERIFY (b == 980);
197 b = a; b.operator-=(sll); VERIFY (b == 1025);
198 b = a; b.operator-=(ull); VERIFY (b == 950);
199}
200
201void
202compound_assignment_multiply_128 (void)
203{
204 decimal128 a (1000), b;
205
206 b = a; b.operator*=(d32); VERIFY (b == 5000);
207 b = a; b.operator*=(d64); VERIFY (b == -10000);
208 b = a; b.operator*=(d128); VERIFY (b == 25000);
209 b = a; b.operator*=(si); VERIFY (b == -2000);
210 b = a; b.operator*=(ui); VERIFY (b == 5000);
211 b = a; b.operator*=(sl); VERIFY (b == -10000);
212 b = a; b.operator*=(ul); VERIFY (b == 20000);
213 b = a; b.operator*=(sll); VERIFY (b == -25000);
214 b = a; b.operator*=(ull); VERIFY (b == 50000);
215}
216
217void
218compound_assignment_divide_128 (void)
219{
220 decimal128 a (1000), b;
221
222 b = a; b.operator/=(d32); VERIFY (b == 200);
223 b = a; b.operator/=(d64); VERIFY (b == -100);
224 b = a; b.operator/=(d128); VERIFY (b == 40);
225 b = a; b.operator/=(si); VERIFY (b == -500);
226 b = a; b.operator/=(ui); VERIFY (b == 200);
227 b = a; b.operator/=(sl); VERIFY (b == -100);
228 b = a; b.operator/=(ul); VERIFY (b == 50);
229 b = a; b.operator/=(sll); VERIFY (b == -40);
230 b = a; b.operator/=(ull); VERIFY (b == 20);
231}
232
233int
234main ()
235{
236 compound_assignment_add_32 ();
237 compound_assignment_subtract_32 ();
238 compound_assignment_multiply_32 ();
239 compound_assignment_divide_32 ();
240
241 compound_assignment_add_64 ();
242 compound_assignment_subtract_64 ();
243 compound_assignment_multiply_64 ();
244 compound_assignment_divide_64 ();
245
246 compound_assignment_add_128 ();
247 compound_assignment_subtract_128 ();
248 compound_assignment_multiply_128 ();
249 compound_assignment_divide_128 ();
250}