5072
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
7016
|
9 Free Software Foundation; either version 3 of the License, or (at your |
|
10 option) any later version. |
5072
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
7016
|
18 along with Octave; see the file COPYING. If not, see |
|
19 <http://www.gnu.org/licenses/>. |
5072
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "oct-inttypes.h" |
|
28 |
|
29 #define INSTANTIATE_INT_DOUBLE_BIN_OP(T, OP) \ |
6108
|
30 template OCTAVE_API octave_int<T> operator OP (const octave_int<T>&, double) |
5072
|
31 |
|
32 #define INSTANTIATE_INT_DOUBLE_BIN_OPS(T) \ |
|
33 INSTANTIATE_INT_DOUBLE_BIN_OP (T, +); \ |
|
34 INSTANTIATE_INT_DOUBLE_BIN_OP (T, -); \ |
|
35 INSTANTIATE_INT_DOUBLE_BIN_OP (T, *); \ |
|
36 INSTANTIATE_INT_DOUBLE_BIN_OP (T, /) |
|
37 |
|
38 #define INSTANTIATE_DOUBLE_INT_BIN_OP(T, OP) \ |
6108
|
39 template OCTAVE_API octave_int<T> operator OP (double, const octave_int<T>&) |
5072
|
40 |
|
41 #define INSTANTIATE_DOUBLE_INT_BIN_OPS(T) \ |
|
42 INSTANTIATE_DOUBLE_INT_BIN_OP (T, +); \ |
|
43 INSTANTIATE_DOUBLE_INT_BIN_OP (T, -); \ |
|
44 INSTANTIATE_DOUBLE_INT_BIN_OP (T, *); \ |
|
45 INSTANTIATE_DOUBLE_INT_BIN_OP (T, /) |
|
46 |
|
47 #define INSTANTIATE_INT_DOUBLE_CMP_OP(T, OP) \ |
6108
|
48 template OCTAVE_API bool operator OP (const octave_int<T>&, const double&) |
5072
|
49 |
|
50 #define INSTANTIATE_INT_DOUBLE_CMP_OPS(T) \ |
|
51 INSTANTIATE_INT_DOUBLE_CMP_OP (T, <); \ |
|
52 INSTANTIATE_INT_DOUBLE_CMP_OP (T, <=); \ |
|
53 INSTANTIATE_INT_DOUBLE_CMP_OP (T, >=); \ |
|
54 INSTANTIATE_INT_DOUBLE_CMP_OP (T, >); \ |
|
55 INSTANTIATE_INT_DOUBLE_CMP_OP (T, ==); \ |
|
56 INSTANTIATE_INT_DOUBLE_CMP_OP (T, !=) |
|
57 |
|
58 #define INSTANTIATE_DOUBLE_INT_CMP_OP(T, OP) \ |
6108
|
59 template OCTAVE_API bool operator OP (const double&, const octave_int<T>&) |
5072
|
60 |
|
61 #define INSTANTIATE_DOUBLE_INT_CMP_OPS(T) \ |
|
62 INSTANTIATE_DOUBLE_INT_CMP_OP (T, <); \ |
|
63 INSTANTIATE_DOUBLE_INT_CMP_OP (T, <=); \ |
|
64 INSTANTIATE_DOUBLE_INT_CMP_OP (T, >=); \ |
|
65 INSTANTIATE_DOUBLE_INT_CMP_OP (T, >); \ |
|
66 INSTANTIATE_DOUBLE_INT_CMP_OP (T, ==); \ |
|
67 INSTANTIATE_DOUBLE_INT_CMP_OP (T, !=) |
|
68 |
|
69 #define INSTANTIATE_INT_BITCMP_OP(T, OP) \ |
6108
|
70 template OCTAVE_API octave_int<T> \ |
5072
|
71 operator OP (const octave_int<T>&, const octave_int<T>&) |
|
72 |
|
73 #define INSTANTIATE_INT_BITCMP_OPS(T) \ |
|
74 INSTANTIATE_INT_BITCMP_OP (T, &); \ |
|
75 INSTANTIATE_INT_BITCMP_OP (T, |); \ |
|
76 INSTANTIATE_INT_BITCMP_OP (T, ^) |
|
77 |
|
78 #define INSTANTIATE_INTTYPE(T) \ |
6108
|
79 template class OCTAVE_API octave_int<T>; \ |
|
80 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \ |
|
81 template OCTAVE_API octave_int<T> pow (double, const octave_int<T>&); \ |
|
82 template OCTAVE_API octave_int<T> pow (const octave_int<T>&, double b); \ |
|
83 template OCTAVE_API std::ostream& operator << (std::ostream&, const octave_int<T>&); \ |
|
84 template OCTAVE_API std::istream& operator >> (std::istream&, octave_int<T>&); \ |
|
85 template OCTAVE_API octave_int<T> \ |
5072
|
86 bitshift (const octave_int<T>&, int, const octave_int<T>&); \ |
|
87 INSTANTIATE_INT_DOUBLE_BIN_OPS (T); \ |
|
88 INSTANTIATE_DOUBLE_INT_BIN_OPS (T); \ |
|
89 INSTANTIATE_INT_DOUBLE_CMP_OPS (T); \ |
|
90 INSTANTIATE_DOUBLE_INT_CMP_OPS (T); \ |
|
91 INSTANTIATE_INT_BITCMP_OPS (T) |
|
92 |
5828
|
93 INSTANTIATE_INTTYPE (int8_t); |
|
94 INSTANTIATE_INTTYPE (int16_t); |
|
95 INSTANTIATE_INTTYPE (int32_t); |
|
96 INSTANTIATE_INTTYPE (int64_t); |
5072
|
97 |
5828
|
98 INSTANTIATE_INTTYPE (uint8_t); |
|
99 INSTANTIATE_INTTYPE (uint16_t); |
|
100 INSTANTIATE_INTTYPE (uint32_t); |
|
101 INSTANTIATE_INTTYPE (uint64_t); |
5072
|
102 |
|
103 #define INSTANTIATE_INTTYPE_BIN_OP(T1, T2, OP) \ |
6105
|
104 template OCTAVE_API octave_int<octave_int_binop_traits<T1, T2>::TR> \ |
|
105 operator OP<T1, T2> (const octave_int<T1>&, const octave_int<T2>&) |
5072
|
106 |
|
107 #define INSTANTIATE_INTTYPE_BIN_OPS(T1, T2) \ |
|
108 INSTANTIATE_INTTYPE_BIN_OP (T1, T2, +); \ |
|
109 INSTANTIATE_INTTYPE_BIN_OP (T1, T2, -); \ |
|
110 INSTANTIATE_INTTYPE_BIN_OP (T1, T2, *); \ |
|
111 INSTANTIATE_INTTYPE_BIN_OP (T1, T2, /) |
|
112 |
5828
|
113 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int8_t); |
|
114 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int16_t); |
|
115 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int32_t); |
|
116 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int64_t); |
|
117 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint8_t); |
|
118 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint16_t); |
|
119 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint32_t); |
|
120 INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint64_t); |
5072
|
121 |
5828
|
122 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int8_t); |
|
123 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int16_t); |
|
124 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int32_t); |
|
125 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int64_t); |
|
126 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint8_t); |
|
127 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint16_t); |
|
128 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint32_t); |
|
129 INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint64_t); |
5072
|
130 |
5828
|
131 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int8_t); |
|
132 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int16_t); |
|
133 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int32_t); |
|
134 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int64_t); |
|
135 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint8_t); |
|
136 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint16_t); |
|
137 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint32_t); |
|
138 INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint64_t); |
5072
|
139 |
5828
|
140 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int8_t); |
|
141 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int16_t); |
|
142 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int32_t); |
|
143 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int64_t); |
|
144 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint8_t); |
|
145 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint16_t); |
|
146 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint32_t); |
|
147 INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint64_t); |
5072
|
148 |
5828
|
149 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int8_t); |
|
150 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int16_t); |
|
151 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int32_t); |
|
152 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int64_t); |
|
153 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint8_t); |
|
154 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint16_t); |
|
155 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint32_t); |
|
156 INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint64_t); |
5072
|
157 |
5828
|
158 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int8_t); |
|
159 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int16_t); |
|
160 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int32_t); |
|
161 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int64_t); |
|
162 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint8_t); |
|
163 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint16_t); |
|
164 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint32_t); |
|
165 INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint64_t); |
5072
|
166 |
5828
|
167 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int8_t); |
|
168 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int16_t); |
|
169 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int32_t); |
|
170 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int64_t); |
|
171 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint8_t); |
|
172 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint16_t); |
|
173 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint32_t); |
|
174 INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint64_t); |
5072
|
175 |
5828
|
176 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int8_t); |
|
177 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int16_t); |
|
178 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int32_t); |
|
179 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int64_t); |
|
180 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint8_t); |
|
181 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint16_t); |
|
182 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint32_t); |
|
183 INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint64_t); |
5072
|
184 |
|
185 #define INSTANTIATE_INTTYPE_SHIFT_OP(T, OP) \ |
6108
|
186 template OCTAVE_API octave_int<T> operator OP (const octave_int<T>&, const int&) |
5072
|
187 |
|
188 #define INSTANTIATE_INTTYPE_SHIFT_OPS(T) \ |
|
189 INSTANTIATE_INTTYPE_SHIFT_OP (T, <<); \ |
|
190 INSTANTIATE_INTTYPE_SHIFT_OP (T, >>) |
|
191 |
5828
|
192 INSTANTIATE_INTTYPE_SHIFT_OPS (int8_t); |
|
193 INSTANTIATE_INTTYPE_SHIFT_OPS (int16_t); |
|
194 INSTANTIATE_INTTYPE_SHIFT_OPS (int32_t); |
|
195 INSTANTIATE_INTTYPE_SHIFT_OPS (int64_t); |
|
196 INSTANTIATE_INTTYPE_SHIFT_OPS (uint8_t); |
|
197 INSTANTIATE_INTTYPE_SHIFT_OPS (uint16_t); |
|
198 INSTANTIATE_INTTYPE_SHIFT_OPS (uint32_t); |
|
199 INSTANTIATE_INTTYPE_SHIFT_OPS (uint64_t); |
5072
|
200 |
|
201 #define INSTANTIATE_OCTAVE_INT_CMP_OP(OP, T1, T2) \ |
6108
|
202 template OCTAVE_API bool operator OP (const octave_int<T1>&, const octave_int<T2>&) |
5072
|
203 |
|
204 #define INSTANTIATE_OCTAVE_INT_CMP_OPS(T1, T2) \ |
|
205 INSTANTIATE_OCTAVE_INT_CMP_OP (<, T1, T2); \ |
|
206 INSTANTIATE_OCTAVE_INT_CMP_OP (<=, T1, T2); \ |
|
207 INSTANTIATE_OCTAVE_INT_CMP_OP (>=, T1, T2); \ |
|
208 INSTANTIATE_OCTAVE_INT_CMP_OP (>, T1, T2); \ |
|
209 INSTANTIATE_OCTAVE_INT_CMP_OP (==, T1, T2); \ |
|
210 INSTANTIATE_OCTAVE_INT_CMP_OP (!=, T1, T2) |
|
211 |
5828
|
212 INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int8_t); |
|
213 INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int16_t); |
|
214 INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int32_t); |
|
215 INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int64_t); |
|
216 INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint8_t); |
|
217 INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint16_t); |
|
218 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint32_t); |
|
219 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint64_t); |
5072
|
220 |
5828
|
221 INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int8_t); |
|
222 INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int16_t); |
|
223 INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int32_t); |
|
224 INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int64_t); |
|
225 INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint8_t); |
|
226 INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint16_t); |
|
227 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint32_t); |
|
228 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint64_t); |
5072
|
229 |
5828
|
230 INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int8_t); |
|
231 INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int16_t); |
|
232 INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int32_t); |
|
233 INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int64_t); |
|
234 INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint8_t); |
|
235 INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint16_t); |
|
236 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint32_t); |
|
237 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint64_t); |
5072
|
238 |
5828
|
239 INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int8_t); |
|
240 INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int16_t); |
|
241 INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int32_t); |
|
242 INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int64_t); |
|
243 INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint8_t); |
|
244 INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint16_t); |
|
245 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint32_t); |
|
246 // INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint64_t); |
5072
|
247 |
5828
|
248 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int8_t); |
|
249 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int16_t); |
|
250 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int32_t); |
|
251 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int64_t); |
|
252 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint8_t); |
|
253 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint16_t); |
|
254 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint32_t); |
|
255 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint64_t); |
5072
|
256 |
5828
|
257 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int8_t); |
|
258 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int16_t); |
|
259 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int32_t); |
|
260 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int64_t); |
|
261 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint8_t); |
|
262 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint16_t); |
|
263 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint32_t); |
|
264 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint64_t); |
5072
|
265 |
5828
|
266 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int8_t); |
|
267 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int16_t); |
|
268 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int32_t); |
|
269 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int64_t); |
|
270 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint8_t); |
|
271 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint16_t); |
|
272 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint32_t); |
|
273 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint64_t); |
5072
|
274 |
5828
|
275 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int8_t); |
|
276 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int16_t); |
|
277 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int32_t); |
|
278 // INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int64_t); |
|
279 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint8_t); |
|
280 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint16_t); |
|
281 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint32_t); |
|
282 INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint64_t); |
5072
|
283 |
|
284 // The following apply if the unsigned type is at least as wide as the |
|
285 // signed type (then we can cast postive signed values to the unsigned |
|
286 // type and compare). |
|
287 |
|
288 #define OCTAVE_US_TYPE1_CMP_OP(OP, LTZ_VAL, UT, ST) \ |
|
289 bool \ |
|
290 operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs) \ |
|
291 { \ |
|
292 return rhs.value () < 0 ? LTZ_VAL \ |
|
293 : lhs.value () OP static_cast<UT> (rhs.value ()); \ |
|
294 } |
|
295 |
|
296 #define OCTAVE_US_TYPE1_CMP_OPS(UT, ST) \ |
|
297 OCTAVE_US_TYPE1_CMP_OP (<, false, UT, ST) \ |
|
298 OCTAVE_US_TYPE1_CMP_OP (<=, false, UT, ST) \ |
|
299 OCTAVE_US_TYPE1_CMP_OP (>=, true, UT, ST) \ |
|
300 OCTAVE_US_TYPE1_CMP_OP (>, true, UT, ST) \ |
|
301 OCTAVE_US_TYPE1_CMP_OP (==, false, UT, ST) \ |
|
302 OCTAVE_US_TYPE1_CMP_OP (!=, true, UT, ST) |
|
303 |
|
304 #define OCTAVE_SU_TYPE1_CMP_OP(OP, LTZ_VAL, ST, UT) \ |
|
305 bool \ |
|
306 operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs) \ |
|
307 { \ |
|
308 return lhs.value () < 0 ? LTZ_VAL \ |
|
309 : static_cast<UT> (lhs.value ()) OP rhs.value (); \ |
|
310 } |
|
311 |
|
312 #define OCTAVE_SU_TYPE1_CMP_OPS(ST, UT) \ |
|
313 OCTAVE_SU_TYPE1_CMP_OP (<, true, ST, UT) \ |
|
314 OCTAVE_SU_TYPE1_CMP_OP (<=, true, ST, UT) \ |
|
315 OCTAVE_SU_TYPE1_CMP_OP (>=, false, ST, UT) \ |
|
316 OCTAVE_SU_TYPE1_CMP_OP (>, false, ST, UT) \ |
|
317 OCTAVE_SU_TYPE1_CMP_OP (==, false, ST, UT) \ |
|
318 OCTAVE_SU_TYPE1_CMP_OP (!=, true, ST, UT) |
|
319 |
|
320 #define OCTAVE_TYPE1_CMP_OPS(UT, ST) \ |
|
321 OCTAVE_US_TYPE1_CMP_OPS (UT, ST) \ |
|
322 OCTAVE_SU_TYPE1_CMP_OPS (ST, UT) |
|
323 |
5828
|
324 OCTAVE_TYPE1_CMP_OPS (uint32_t, int8_t) |
|
325 OCTAVE_TYPE1_CMP_OPS (uint32_t, int16_t) |
|
326 OCTAVE_TYPE1_CMP_OPS (uint32_t, int32_t) |
5072
|
327 |
5828
|
328 OCTAVE_TYPE1_CMP_OPS (uint64_t, int8_t) |
|
329 OCTAVE_TYPE1_CMP_OPS (uint64_t, int16_t) |
|
330 OCTAVE_TYPE1_CMP_OPS (uint64_t, int32_t) |
|
331 OCTAVE_TYPE1_CMP_OPS (uint64_t, int64_t) |
5072
|
332 |
|
333 // The following apply if the signed type is wider than the unsigned |
|
334 // type (then we can cast unsigned values to the signed type and |
|
335 // compare if the signed value is positive). |
|
336 |
|
337 #define OCTAVE_US_TYPE2_CMP_OP(OP, LTZ_VAL, UT, ST) \ |
|
338 bool \ |
|
339 operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs) \ |
|
340 { \ |
|
341 return rhs.value () < 0 ? LTZ_VAL \ |
|
342 : static_cast<ST> (lhs.value ()) OP rhs.value (); \ |
|
343 } |
|
344 |
|
345 #define OCTAVE_US_TYPE2_CMP_OPS(ST, UT) \ |
|
346 OCTAVE_US_TYPE2_CMP_OP (<, false, ST, UT) \ |
|
347 OCTAVE_US_TYPE2_CMP_OP (<=, false, ST, UT) \ |
|
348 OCTAVE_US_TYPE2_CMP_OP (>=, true, ST, UT) \ |
|
349 OCTAVE_US_TYPE2_CMP_OP (>, true, ST, UT) \ |
|
350 OCTAVE_US_TYPE2_CMP_OP (==, false, ST, UT) \ |
|
351 OCTAVE_US_TYPE2_CMP_OP (!=, true, ST, UT) |
|
352 |
|
353 #define OCTAVE_SU_TYPE2_CMP_OP(OP, LTZ_VAL, ST, UT) \ |
|
354 bool \ |
|
355 operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs) \ |
|
356 { \ |
|
357 return lhs.value () < 0 ? LTZ_VAL \ |
|
358 : lhs.value () OP static_cast<ST> (rhs.value ()); \ |
|
359 } |
|
360 |
|
361 #define OCTAVE_SU_TYPE2_CMP_OPS(ST, UT) \ |
|
362 OCTAVE_SU_TYPE2_CMP_OP (<, true, ST, UT) \ |
|
363 OCTAVE_SU_TYPE2_CMP_OP (<=, true, ST, UT) \ |
|
364 OCTAVE_SU_TYPE2_CMP_OP (>=, false, ST, UT) \ |
|
365 OCTAVE_SU_TYPE2_CMP_OP (>, false, ST, UT) \ |
|
366 OCTAVE_SU_TYPE2_CMP_OP (==, false, ST, UT) \ |
|
367 OCTAVE_SU_TYPE2_CMP_OP (!=, true, ST, UT) |
|
368 |
|
369 #define OCTAVE_TYPE2_CMP_OPS(UT, ST) \ |
|
370 OCTAVE_US_TYPE2_CMP_OPS (UT, ST) \ |
|
371 OCTAVE_SU_TYPE2_CMP_OPS (ST, UT) |
|
372 |
5828
|
373 OCTAVE_TYPE2_CMP_OPS (uint32_t, int64_t) |
5072
|
374 |
|
375 |
|
376 |
|
377 /* |
|
378 ;;; Local Variables: *** |
|
379 ;;; mode: C++ *** |
|
380 ;;; End: *** |
|
381 */ |