Update copyright in libstdc++-v3.
[official-gcc.git] / libstdc++-v3 / testsuite / decimal / incdec-memfunc.cc
blob384aef9eadbb71e1dd79c24922abe94b14cfe462
1 // Copyright (C) 2009-2013 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.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).
24 // Access member functions directly.
26 #include <decimal/decimal>
27 #include <testsuite_hooks.h>
29 // Use extension to replace implicit long long conversion with function call.
30 #define LONGLONG(X) decimal_to_long_long(X)
32 using namespace std::decimal;
34 void
35 incdec32 (void)
37 bool test __attribute__((unused)) = true;
38 int ival;
39 decimal32 a(11), b, c;
41 // Verify that we get the expected value of b after assignment.
42 b = a;
43 ival = LONGLONG (b); VERIFY (ival == 11);
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);
51 b = a;
52 b.operator++(1);
53 ival = LONGLONG (b); VERIFY (ival == 12);
55 b = a;
56 b.operator--();
57 ival = LONGLONG (b); VERIFY (ival == 10);
59 b = a;
60 b.operator--(1);
61 ival = LONGLONG (b); VERIFY (ival == 10);
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);
69 b = a;
70 c = b.operator++(1);
71 ival = LONGLONG (c); VERIFY (ival == 11);
73 b = a;
74 c = b.operator--();
75 ival = LONGLONG (c); VERIFY (ival == 10);
77 b = a;
78 c = b.operator--(1);
79 ival = LONGLONG (c); VERIFY (ival == 11);
82 void
83 incdec64 (void)
85 bool test __attribute__((unused)) = true;
86 int ival;
87 decimal64 a(11), b, c;
89 // Verify that we get the expected value of b after assignment.
90 b = a;
91 ival = LONGLONG (b); VERIFY (ival == 11);
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);
99 b = a;
100 b.operator++(1);
101 ival = LONGLONG (b); VERIFY (ival == 12);
103 b = a;
104 b.operator--();
105 ival = LONGLONG (b); VERIFY (ival == 10);
107 b = a;
108 b.operator--(1);
109 ival = LONGLONG (b); VERIFY (ival == 10);
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);
117 b = a;
118 c = b.operator++(1);
119 ival = LONGLONG (c); VERIFY (ival == 11);
121 b = a;
122 c = b.operator--();
123 ival = LONGLONG (c); VERIFY (ival == 10);
125 b = a;
126 c = b.operator--(1);
127 ival = LONGLONG (c); VERIFY (ival == 11);
130 void
131 incdec128 (void)
133 bool test __attribute__((unused)) = true;
134 int ival;
135 decimal128 a(11), b, c;
137 // Verify that we get the expected value of b after assignment.
138 b = a;
139 ival = LONGLONG (b); VERIFY (ival == 11);
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);
147 b = a;
148 b.operator++(1);
149 ival = LONGLONG (b); VERIFY (ival == 12);
151 b = a;
152 b.operator--();
153 ival = LONGLONG (b); VERIFY (ival == 10);
155 b = a;
156 b.operator--(1);
157 ival = LONGLONG (b); VERIFY (ival == 10);
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);
165 b = a;
166 c = b.operator++(1);
167 ival = LONGLONG (c); VERIFY (ival == 11);
169 b = a;
170 c = b.operator--();
171 ival = LONGLONG (c); VERIFY (ival == 10);
173 b = a;
174 c = b.operator--(1);
175 ival = LONGLONG (c); VERIFY (ival == 11);
179 main ()
181 incdec32 ();
182 incdec64 ();
183 incdec128 ();