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