1// Copyright (C) 2009 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
32using namespace std::decimal;
33
34void
35incdec32 (void)
36{
37  int ival;
38  std::decimal::decimal32 a(11), b, c;
39
40  // Verify that we get the expected value of b after assignment.
41  b = a;
42  ival = LONGLONG (b); VERIFY (ival == 11);
43
44  // Check that the increment and decrement operators change the value
45  // of the original class.
46  b = a;
47  b.operator++();
48  ival = LONGLONG (b); VERIFY (ival == 12);
49
50  b = a;
51  b.operator++(1);
52  ival = LONGLONG (b); VERIFY (ival == 12);
53
54  b = a;
55  b.operator--();
56  ival = LONGLONG (b); VERIFY (ival == 10);
57
58  b = a;
59  b.operator--(1);
60  ival = LONGLONG (b); VERIFY (ival == 10);
61
62  // Check that the increment and decrement operators return the
63  // correct value.
64  b = a;
65  c = b.operator++();
66  ival = LONGLONG (c); VERIFY (ival == 12);
67
68  b = a;
69  c = b.operator++(1);
70  ival = LONGLONG (c); VERIFY (ival == 11);
71
72  b = a;
73  c = b.operator--();
74  ival = LONGLONG (c); VERIFY (ival == 10);
75
76  b = a;
77  c = b.operator--(1);
78  ival = LONGLONG (c); VERIFY (ival == 11);
79}
80
81void
82incdec64 (void)
83{
84  int ival;
85  std::decimal::decimal64 a(11), b, c;
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.operator++();
95  ival = LONGLONG (b); VERIFY (ival == 12);
96
97  b = a;
98  b.operator++(1);
99  ival = LONGLONG (b); VERIFY (ival == 12);
100
101  b = a;
102  b.operator--();
103  ival = LONGLONG (b); VERIFY (ival == 10);
104
105  b = a;
106  b.operator--(1);
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.operator++();
113  ival = LONGLONG (c); VERIFY (ival == 12);
114
115  b = a;
116  c = b.operator++(1);
117  ival = LONGLONG (c); VERIFY (ival == 11);
118
119  b = a;
120  c = b.operator--();
121  ival = LONGLONG (c); VERIFY (ival == 10);
122
123  b = a;
124  c = b.operator--(1);
125  ival = LONGLONG (c); VERIFY (ival == 11);
126}
127
128void
129incdec128 (void)
130{
131  int ival;
132  std::decimal::decimal128 a(11), b, c;
133
134  // Verify that we get the expected value of b after assignment.
135  b = a;
136  ival = LONGLONG (b); VERIFY (ival == 11);
137
138  // Check that the increment and decrement operators change the value
139  // of the original class.
140  b = a;
141  b.operator++();
142  ival = LONGLONG (b); VERIFY (ival == 12);
143
144  b = a;
145  b.operator++(1);
146  ival = LONGLONG (b); VERIFY (ival == 12);
147
148  b = a;
149  b.operator--();
150  ival = LONGLONG (b); VERIFY (ival == 10);
151
152  b = a;
153  b.operator--(1);
154  ival = LONGLONG (b); VERIFY (ival == 10);
155
156  // Check that the increment and decrement operators return the
157  // correct value.
158  b = a;
159  c = b.operator++();
160  ival = LONGLONG (c); VERIFY (ival == 12);
161
162  b = a;
163  c = b.operator++(1);
164  ival = LONGLONG (c); VERIFY (ival == 11);
165
166  b = a;
167  c = b.operator--();
168  ival = LONGLONG (c); VERIFY (ival == 10);
169
170  b = a;
171  c = b.operator--(1);
172  ival = LONGLONG (c); VERIFY (ival == 11);
173}
174
175int
176main ()
177{
178  incdec32 ();
179  incdec64 ();
180  incdec128 ();
181}
182