]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/decimal/incdec.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / decimal / incdec.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.5 Increment and decrement operators (decimal32).
21// ISO/IEC TR 24733 3.2.3.5 Increment and decrement operators (decimal64).
22// ISO/IEC TR 24733 3.2.4.5 Increment and decrement operators (decimal128).
23
24#include <decimal/decimal>
25#include <testsuite_hooks.h>
26
27// Use extension to replace implicit long long conversion with function call.
28#define LONGLONG(X) decimal_to_long_long(X)
29
30using namespace std::decimal;
31
32void
33incdec32 (void)
34{
0b42d8d9 35 bool test __attribute__((unused)) = true;
a9c001cb 36 int ival;
0b42d8d9 37 decimal32 a(11), b, c;
a9c001cb 38
39 // Verify that we get the expected value of b after assignment.
40 b = a;
41 ival = LONGLONG (b); VERIFY (ival == 11);
42
43 // Check that the increment and decrement operators change the value
44 // of the original class.
45 b = a;
46 ++b;
47 ival = LONGLONG (b); VERIFY (ival == 12);
48
49 b = a;
50 b++;
51 ival = LONGLONG (b); VERIFY (ival == 12);
52
53 b = a;
54 --b;
55 ival = LONGLONG (b); VERIFY (ival == 10);
56
57 b = a;
58 b--;
59 ival = LONGLONG (b); VERIFY (ival == 10);
60
61 // Check that the increment and decrement operators return the
62 // correct value.
63 b = a;
64 c = ++b;
65 ival = LONGLONG (c); VERIFY (ival == 12);
66
67 b = a;
68 c = b++;
69 ival = LONGLONG (c); VERIFY (ival == 11);
70
71 b = a;
72 c = --b;
73 ival = LONGLONG (c); VERIFY (ival == 10);
74
75 b = a;
76 c = b--;
77 ival = LONGLONG (c); VERIFY (ival == 11);
78}
79
80void
81incdec64 (void)
82{
0b42d8d9 83 bool test __attribute__((unused)) = true;
a9c001cb 84 int ival;
0b42d8d9 85 decimal64 a(11), b, c;
a9c001cb 86
87 // Verify that we get the expected value of b after assignment.
88 b = a;
89 ival = LONGLONG (b); VERIFY (ival == 11);
90
91 // Check that the increment and decrement operators change the value
92 // of the original class.
93 b = a;
94 ++b;
95 ival = LONGLONG (b); VERIFY (ival == 12);
96
97 b = a;
98 b++;
99 ival = LONGLONG (b); VERIFY (ival == 12);
100
101 b = a;
102 --b;
103 ival = LONGLONG (b); VERIFY (ival == 10);
104
105 b = a;
106 b--;
107 ival = LONGLONG (b); VERIFY (ival == 10);
108
109 // Check that the increment and decrement operators return the
110 // correct value.
111 b = a;
112 c = ++b;
113 ival = LONGLONG (c); VERIFY (ival == 12);
114
115 b = a;
116 c = b++;
117 ival = LONGLONG (c); VERIFY (ival == 11);
118
119 b = a;
120 c = --b;
121 ival = LONGLONG (c); VERIFY (ival == 10);
122
123 b = a;
124 c = b--;
125 ival = LONGLONG (c); VERIFY (ival == 11);
126}
127
128void
129incdec128 (void)
130{
0b42d8d9 131 bool test __attribute__((unused)) = true;
a9c001cb 132 int ival;
0b42d8d9 133 decimal128 a(11), b, c;
a9c001cb 134
135 // Verify that we get the expected value of b after assignment.
136 b = a;
137 ival = LONGLONG (b); VERIFY (ival == 11);
138
139 // Check that the increment and decrement operators change the value
140 // of the original class.
141 b = a;
142 ++b;
143 ival = LONGLONG (b); VERIFY (ival == 12);
144
145 b = a;
146 b++;
147 ival = LONGLONG (b); VERIFY (ival == 12);
148
149 b = a;
150 --b;
151 ival = LONGLONG (b); VERIFY (ival == 10);
152
153 b = a;
154 b--;
155 ival = LONGLONG (b); VERIFY (ival == 10);
156
157 // Check that the increment and decrement operators return the
158 // correct value.
159 b = a;
160 c = ++b;
161 ival = LONGLONG (c); VERIFY (ival == 12);
162
163 b = a;
164 c = b++;
165 ival = LONGLONG (c); VERIFY (ival == 11);
166
167 b = a;
168 c = --b;
169 ival = LONGLONG (c); VERIFY (ival == 10);
170
171 b = a;
172 c = b--;
173 ival = LONGLONG (c); VERIFY (ival == 11);
174}
175
176int
177main ()
178{
179 incdec32 ();
180 incdec64 ();
181 incdec128 ();
182}