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