Mercurial > hg > octave-nkf
changeset 5072:97b62f0c1bee
[project @ 2004-11-09 05:51:30 by jwe]
author | jwe |
---|---|
date | Tue, 09 Nov 2004 05:53:11 +0000 |
parents | 7b24fd17c263 |
children | e71be9c548f2 |
files | liboctave/ChangeLog liboctave/Makefile.in liboctave/oct-inttypes.cc liboctave/oct-inttypes.h scripts/ChangeLog scripts/plot/__plt2vm__.m |
diffstat | 6 files changed, 518 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,16 @@ +2004-11-08 John W. Eaton <jwe@octave.org> + + * oct-inttypes.cc: New file. + * Makefile.in (TI_SRC): Add it to the list. + * oct-inttypes.h (OCTAVE_US_TYPE1_CMP_OP, OCTAVE_US_TYPE1_CMP_OPS, + OCTAVE_SU_TYPE1_CMP_OP, OCTAVE_SU_TYPE1_CMP_OPS, + OCTAVE_TYPE1_CMP_OPS, OCTAVE_US_TYPE2_CMP_OP, + OCTAVE_US_TYPE2_CMP_OPS, OCTAVE_SU_TYPE2_CMP_OP, + OCTAVE_SU_TYPE2_CMP_OPS, OCTAVE_TYPE2_CMP_OPS): + New macros for comparison operations. Avoid potential + problems with default conversions when comparing signed and + unsigned values. + 2004-11-03 John W. Eaton <jwe@octave.org> * dMatrix.cc (Matrix::inverse): Return info == -1 for any failure.
--- a/liboctave/Makefile.in +++ b/liboctave/Makefile.in @@ -72,7 +72,8 @@ TI_SRC := Array-C.cc Array-b.cc Array-ch.cc Array-i.cc Array-d.cc \ Array-s.cc Array-so.cc Array-str.cc Array-idx-vec.cc \ - MArray-C.cc MArray-ch.cc MArray-i.cc MArray-d.cc MArray-s.cc + MArray-C.cc MArray-ch.cc MArray-i.cc MArray-d.cc MArray-s.cc \ + oct-inttypes.cc MATRIX_SRC := Array-flags.cc Array-util.cc CColVector.cc \ CDiagMatrix.cc CMatrix.cc CNDArray.cc CRowVector.cc \
new file mode 100644 --- /dev/null +++ b/liboctave/oct-inttypes.cc @@ -0,0 +1,381 @@ +/* + +Copyright (C) 2004 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "oct-inttypes.h" + +#define INSTANTIATE_INT_DOUBLE_BIN_OP(T, OP) \ + template octave_int<T> operator OP (const octave_int<T>&, double) + +#define INSTANTIATE_INT_DOUBLE_BIN_OPS(T) \ + INSTANTIATE_INT_DOUBLE_BIN_OP (T, +); \ + INSTANTIATE_INT_DOUBLE_BIN_OP (T, -); \ + INSTANTIATE_INT_DOUBLE_BIN_OP (T, *); \ + INSTANTIATE_INT_DOUBLE_BIN_OP (T, /) + +#define INSTANTIATE_DOUBLE_INT_BIN_OP(T, OP) \ + template octave_int<T> operator OP (double, const octave_int<T>&) + +#define INSTANTIATE_DOUBLE_INT_BIN_OPS(T) \ + INSTANTIATE_DOUBLE_INT_BIN_OP (T, +); \ + INSTANTIATE_DOUBLE_INT_BIN_OP (T, -); \ + INSTANTIATE_DOUBLE_INT_BIN_OP (T, *); \ + INSTANTIATE_DOUBLE_INT_BIN_OP (T, /) + +#define INSTANTIATE_INT_DOUBLE_CMP_OP(T, OP) \ + template bool operator OP (const octave_int<T>&, const double&) + +#define INSTANTIATE_INT_DOUBLE_CMP_OPS(T) \ + INSTANTIATE_INT_DOUBLE_CMP_OP (T, <); \ + INSTANTIATE_INT_DOUBLE_CMP_OP (T, <=); \ + INSTANTIATE_INT_DOUBLE_CMP_OP (T, >=); \ + INSTANTIATE_INT_DOUBLE_CMP_OP (T, >); \ + INSTANTIATE_INT_DOUBLE_CMP_OP (T, ==); \ + INSTANTIATE_INT_DOUBLE_CMP_OP (T, !=) + +#define INSTANTIATE_DOUBLE_INT_CMP_OP(T, OP) \ + template bool operator OP (const double&, const octave_int<T>&) + +#define INSTANTIATE_DOUBLE_INT_CMP_OPS(T) \ + INSTANTIATE_DOUBLE_INT_CMP_OP (T, <); \ + INSTANTIATE_DOUBLE_INT_CMP_OP (T, <=); \ + INSTANTIATE_DOUBLE_INT_CMP_OP (T, >=); \ + INSTANTIATE_DOUBLE_INT_CMP_OP (T, >); \ + INSTANTIATE_DOUBLE_INT_CMP_OP (T, ==); \ + INSTANTIATE_DOUBLE_INT_CMP_OP (T, !=) + +#define INSTANTIATE_INT_BITCMP_OP(T, OP) \ + template octave_int<T> \ + operator OP (const octave_int<T>&, const octave_int<T>&) + +#define INSTANTIATE_INT_BITCMP_OPS(T) \ + INSTANTIATE_INT_BITCMP_OP (T, &); \ + INSTANTIATE_INT_BITCMP_OP (T, |); \ + INSTANTIATE_INT_BITCMP_OP (T, ^) + +#define INSTANTIATE_INTTYPE(T) \ + template class octave_int<T>; \ + template octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \ + template octave_int<T> pow (double, const octave_int<T>&); \ + template octave_int<T> pow (const octave_int<T>&, double b); \ + template std::ostream& operator << (std::ostream&, const octave_int<T>&); \ + template std::istream& operator >> (std::istream&, octave_int<T>&); \ + template octave_int<T> \ + bitshift (const octave_int<T>&, int, const octave_int<T>&); \ + INSTANTIATE_INT_DOUBLE_BIN_OPS (T); \ + INSTANTIATE_DOUBLE_INT_BIN_OPS (T); \ + INSTANTIATE_INT_DOUBLE_CMP_OPS (T); \ + INSTANTIATE_DOUBLE_INT_CMP_OPS (T); \ + INSTANTIATE_INT_BITCMP_OPS (T) + +INSTANTIATE_INTTYPE (octave_int8_t); +INSTANTIATE_INTTYPE (octave_int16_t); +INSTANTIATE_INTTYPE (octave_int32_t); +INSTANTIATE_INTTYPE (octave_int64_t); + +INSTANTIATE_INTTYPE (octave_uint8_t); +INSTANTIATE_INTTYPE (octave_uint16_t); +INSTANTIATE_INTTYPE (octave_uint32_t); +INSTANTIATE_INTTYPE (octave_uint64_t); + +#define INSTANTIATE_INTTYPE_BIN_OP(T1, T2, OP) \ + template octave_int<octave_int_binop_traits<T1, T2>::TR> \ + operator OP (const octave_int<T1>&, const octave_int<T2>&) + +#define INSTANTIATE_INTTYPE_BIN_OPS(T1, T2) \ + INSTANTIATE_INTTYPE_BIN_OP (T1, T2, +); \ + INSTANTIATE_INTTYPE_BIN_OP (T1, T2, -); \ + INSTANTIATE_INTTYPE_BIN_OP (T1, T2, *); \ + INSTANTIATE_INTTYPE_BIN_OP (T1, T2, /) + +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int8_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int16_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int32_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_int64_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint8_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint16_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint32_t, octave_uint64_t); + +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_int8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_int16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_int32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_int64_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_uint8_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_uint16_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_uint32_t); +INSTANTIATE_INTTYPE_BIN_OPS (octave_uint64_t, octave_uint64_t); + +#define INSTANTIATE_INTTYPE_SHIFT_OP(T, OP) \ + template octave_int<T> operator OP (const octave_int<T>&, const int&) + +#define INSTANTIATE_INTTYPE_SHIFT_OPS(T) \ + INSTANTIATE_INTTYPE_SHIFT_OP (T, <<); \ + INSTANTIATE_INTTYPE_SHIFT_OP (T, >>) + +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_int8_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_int16_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_int32_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_int64_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_uint8_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_uint16_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_uint32_t); +INSTANTIATE_INTTYPE_SHIFT_OPS (octave_uint64_t); + +#define INSTANTIATE_OCTAVE_INT_CMP_OP(OP, T1, T2) \ + template bool operator OP (const octave_int<T1>&, const octave_int<T2>&) + +#define INSTANTIATE_OCTAVE_INT_CMP_OPS(T1, T2) \ + INSTANTIATE_OCTAVE_INT_CMP_OP (<, T1, T2); \ + INSTANTIATE_OCTAVE_INT_CMP_OP (<=, T1, T2); \ + INSTANTIATE_OCTAVE_INT_CMP_OP (>=, T1, T2); \ + INSTANTIATE_OCTAVE_INT_CMP_OP (>, T1, T2); \ + INSTANTIATE_OCTAVE_INT_CMP_OP (==, T1, T2); \ + INSTANTIATE_OCTAVE_INT_CMP_OP (!=, T1, T2) + +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_int8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_int16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_int32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_uint16_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_uint32_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int8_t, octave_uint64_t); + +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_int8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_int16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_int32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_uint16_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_uint32_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int16_t, octave_uint64_t); + +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_int8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_int16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_int32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_uint16_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_uint32_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int32_t, octave_uint64_t); + +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_int8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_int16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_int32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_uint16_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_uint32_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_int64_t, octave_uint64_t); + +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_int8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_int16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_int32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_uint16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_uint32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint8_t, octave_uint64_t); + +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_int8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_int16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_int32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_uint16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_uint32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint16_t, octave_uint64_t); + +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_int8_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_int16_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_int32_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_uint16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_uint32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint32_t, octave_uint64_t); + +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_int8_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_int16_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_int32_t); +// INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_int64_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_uint8_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_uint16_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_uint32_t); +INSTANTIATE_OCTAVE_INT_CMP_OPS (octave_uint64_t, octave_uint64_t); + +// The following apply if the unsigned type is at least as wide as the +// signed type (then we can cast postive signed values to the unsigned +// type and compare). + +#define OCTAVE_US_TYPE1_CMP_OP(OP, LTZ_VAL, UT, ST) \ + bool \ + operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs) \ + { \ + return rhs.value () < 0 ? LTZ_VAL \ + : lhs.value () OP static_cast<UT> (rhs.value ()); \ + } + +#define OCTAVE_US_TYPE1_CMP_OPS(UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP (<, false, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP (<=, false, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP (>=, true, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP (>, true, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP (==, false, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP (!=, true, UT, ST) + +#define OCTAVE_SU_TYPE1_CMP_OP(OP, LTZ_VAL, ST, UT) \ + bool \ + operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs) \ + { \ + return lhs.value () < 0 ? LTZ_VAL \ + : static_cast<UT> (lhs.value ()) OP rhs.value (); \ + } + +#define OCTAVE_SU_TYPE1_CMP_OPS(ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP (<, true, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP (<=, true, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP (>=, false, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP (>, false, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP (==, false, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP (!=, true, ST, UT) + +#define OCTAVE_TYPE1_CMP_OPS(UT, ST) \ + OCTAVE_US_TYPE1_CMP_OPS (UT, ST) \ + OCTAVE_SU_TYPE1_CMP_OPS (ST, UT) + +OCTAVE_TYPE1_CMP_OPS (octave_uint32_t, octave_int8_t) +OCTAVE_TYPE1_CMP_OPS (octave_uint32_t, octave_int16_t) +OCTAVE_TYPE1_CMP_OPS (octave_uint32_t, octave_int32_t) + +OCTAVE_TYPE1_CMP_OPS (octave_uint64_t, octave_int8_t) +OCTAVE_TYPE1_CMP_OPS (octave_uint64_t, octave_int16_t) +OCTAVE_TYPE1_CMP_OPS (octave_uint64_t, octave_int32_t) +OCTAVE_TYPE1_CMP_OPS (octave_uint64_t, octave_int64_t) + +// The following apply if the signed type is wider than the unsigned +// type (then we can cast unsigned values to the signed type and +// compare if the signed value is positive). + +#define OCTAVE_US_TYPE2_CMP_OP(OP, LTZ_VAL, UT, ST) \ + bool \ + operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs) \ + { \ + return rhs.value () < 0 ? LTZ_VAL \ + : static_cast<ST> (lhs.value ()) OP rhs.value (); \ + } + +#define OCTAVE_US_TYPE2_CMP_OPS(ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP (<, false, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP (<=, false, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP (>=, true, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP (>, true, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP (==, false, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP (!=, true, ST, UT) + +#define OCTAVE_SU_TYPE2_CMP_OP(OP, LTZ_VAL, ST, UT) \ + bool \ + operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs) \ + { \ + return lhs.value () < 0 ? LTZ_VAL \ + : lhs.value () OP static_cast<ST> (rhs.value ()); \ + } + +#define OCTAVE_SU_TYPE2_CMP_OPS(ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP (<, true, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP (<=, true, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP (>=, false, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP (>, false, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP (==, false, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP (!=, true, ST, UT) + +#define OCTAVE_TYPE2_CMP_OPS(UT, ST) \ + OCTAVE_US_TYPE2_CMP_OPS (UT, ST) \ + OCTAVE_SU_TYPE2_CMP_OPS (ST, UT) + +OCTAVE_TYPE2_CMP_OPS (octave_uint32_t, octave_int64_t) + + + +/* +;;; Local Variables: *** +;;; mode: C++ *** +;;; End: *** +*/
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -142,7 +142,7 @@ // This should always be OK because the maximum value should always be // positive. -#define US_S_FTR(T1, T2, TC) \ +#define OCTAVE_US_S_FTR(T1, T2, TC) \ template <> \ inline T2 \ octave_int_fit_to_range<T1, T2> (const T1& x, const T2&, const T2& mx) \ @@ -150,26 +150,26 @@ return x > static_cast<TC> (mx) ? mx : x; \ } -#define US_S_FTR_FCNS(T) \ - US_S_FTR(T, char, unsigned char) \ - US_S_FTR(T, signed char, unsigned char) \ - US_S_FTR(T, short, unsigned short) \ - US_S_FTR(T, int, unsigned int) \ - US_S_FTR(T, long, unsigned long) \ - US_S_FTR(T, long long, unsigned long long) +#define OCTAVE_US_S_FTR_FCNS(T) \ + OCTAVE_US_S_FTR (T, char, unsigned char) \ + OCTAVE_US_S_FTR (T, signed char, unsigned char) \ + OCTAVE_US_S_FTR (T, short, unsigned short) \ + OCTAVE_US_S_FTR (T, int, unsigned int) \ + OCTAVE_US_S_FTR (T, long, unsigned long) \ + OCTAVE_US_S_FTR (T, long long, unsigned long long) -US_S_FTR_FCNS (unsigned char) -US_S_FTR_FCNS (unsigned short) -US_S_FTR_FCNS (unsigned int) -US_S_FTR_FCNS (unsigned long) -US_S_FTR_FCNS (unsigned long long) +OCTAVE_US_S_FTR_FCNS (unsigned char) +OCTAVE_US_S_FTR_FCNS (unsigned short) +OCTAVE_US_S_FTR_FCNS (unsigned int) +OCTAVE_US_S_FTR_FCNS (unsigned long) +OCTAVE_US_S_FTR_FCNS (unsigned long long) // If X is signed and the new type is unsigned, then we only have to // check the lower limit (which will always be 0 for an unsigned // type). The upper limit will be enforced correctly by converting to // the new type, even if the type of X is wider than the new type. -#define S_US_FTR(T1, T2) \ +#define OCTAVE_S_US_FTR(T1, T2) \ template <> \ inline T2 \ octave_int_fit_to_range<T1, T2> (const T1& x, const T2&, const T2&) \ @@ -177,19 +177,19 @@ return x < 0 ? 0 : x; \ } -#define S_US_FTR_FCNS(T) \ - S_US_FTR(T, unsigned char) \ - S_US_FTR(T, unsigned short) \ - S_US_FTR(T, unsigned int) \ - S_US_FTR(T, unsigned long) \ - S_US_FTR(T, unsigned long long) +#define OCTAVE_S_US_FTR_FCNS(T) \ + OCTAVE_S_US_FTR (T, unsigned char) \ + OCTAVE_S_US_FTR (T, unsigned short) \ + OCTAVE_S_US_FTR (T, unsigned int) \ + OCTAVE_S_US_FTR (T, unsigned long) \ + OCTAVE_S_US_FTR (T, unsigned long long) -S_US_FTR_FCNS (char) -S_US_FTR_FCNS (signed char) -S_US_FTR_FCNS (short) -S_US_FTR_FCNS (int) -S_US_FTR_FCNS (long) -S_US_FTR_FCNS (long long) +OCTAVE_S_US_FTR_FCNS (char) +OCTAVE_S_US_FTR_FCNS (signed char) +OCTAVE_S_US_FTR_FCNS (short) +OCTAVE_S_US_FTR_FCNS (int) +OCTAVE_S_US_FTR_FCNS (long) +OCTAVE_S_US_FTR_FCNS (long long) #define OCTAVE_INT_FIT_TO_RANGE(r, T) \ octave_int_fit_to_range (r, \ @@ -405,7 +405,6 @@ typedef octave_int<octave_uint64_t> octave_uint64; #define OCTAVE_INT_BIN_OP(OP) \ - \ template <class T1, class T2> \ octave_int<typename octave_int_binop_traits<T1, T2>::TR> \ operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \ @@ -431,7 +430,6 @@ } #define OCTAVE_INT_DOUBLE_BIN_OP(OP) \ - \ template <class T> \ octave_int<T> \ operator OP (const octave_int<T>& x, double y) \ @@ -448,7 +446,6 @@ OCTAVE_INT_DOUBLE_BIN_OP(/) #define OCTAVE_DOUBLE_INT_BIN_OP(OP) \ - \ template <class T> \ octave_int<T> \ operator OP (double x, const octave_int<T>& y) \ @@ -497,7 +494,6 @@ OCTAVE_DOUBLE_INT_CMP_OP (!=) #define OCTAVE_INT_BITCMP_OP(OP) \ - \ template <class T> \ octave_int<T> \ operator OP (const octave_int<T>& x, const octave_int<T>& y) \ @@ -538,18 +534,12 @@ return a; } -// XXX FIXME XXX -- need partial specializations for int64 and uint64 -// types. - #define OCTAVE_INT_CMP_OP(OP) \ - \ template <class T1, class T2> \ bool \ operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \ { \ - double tx = static_cast<double> (x.value ()); \ - double ty = static_cast<double> (y.value ()); \ - return tx OP ty; \ + return x.value () OP y.value (); \ } OCTAVE_INT_CMP_OP (<) @@ -559,6 +549,77 @@ OCTAVE_INT_CMP_OP (==) OCTAVE_INT_CMP_OP (!=) +// The following apply if the unsigned type is at least as wide as the +// signed type (then we can cast postive signed values to the unsigned +// type and compare). + +#define OCTAVE_US_TYPE1_CMP_OP_DECL(OP, LTZ_VAL, UT, ST) \ + bool operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs); + +#define OCTAVE_US_TYPE1_CMP_OP_DECLS(UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECL (<, false, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECL (<=, false, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECL (>=, true, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECL (>, true, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECL (==, false, UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECL (!=, true, UT, ST) + +#define OCTAVE_SU_TYPE1_CMP_OP_DECL(OP, LTZ_VAL, ST, UT) \ + bool operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs); + +#define OCTAVE_SU_TYPE1_CMP_OP_DECLS(ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP_DECL (<, true, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP_DECL (<=, true, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP_DECL (>=, false, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP_DECL (>, false, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP_DECL (==, false, ST, UT) \ + OCTAVE_SU_TYPE1_CMP_OP_DECL (!=, true, ST, UT) + +#define OCTAVE_TYPE1_CMP_OP_DECLS(UT, ST) \ + OCTAVE_US_TYPE1_CMP_OP_DECLS (UT, ST) \ + OCTAVE_SU_TYPE1_CMP_OP_DECLS (ST, UT) + +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint32_t, octave_int8_t) +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint32_t, octave_int16_t) +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint32_t, octave_int32_t) + +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int8_t) +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int16_t) +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int32_t) +OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int64_t) + +// The following apply if the signed type is wider than the unsigned +// type (then we can cast unsigned values to the signed type and +// compare if the signed value is positive). + +#define OCTAVE_US_TYPE2_CMP_OP_DECL(OP, LTZ_VAL, UT, ST) \ + bool operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs); + +#define OCTAVE_US_TYPE2_CMP_OP_DECLS(ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP_DECL (<, false, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP_DECL (<=, false, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP_DECL (>=, true, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP_DECL (>, true, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP_DECL (==, false, ST, UT) \ + OCTAVE_US_TYPE2_CMP_OP_DECL (!=, true, ST, UT) + +#define OCTAVE_SU_TYPE2_CMP_OP_DECL(OP, LTZ_VAL, ST, UT) \ + bool operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs); + +#define OCTAVE_SU_TYPE2_CMP_OP_DECLS(ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP_DECL (<, true, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP_DECL (<=, true, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP_DECL (>=, false, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP_DECL (>, false, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP_DECL (==, false, ST, UT) \ + OCTAVE_SU_TYPE2_CMP_OP_DECL (!=, true, ST, UT) + +#define OCTAVE_TYPE2_CMP_OP_DECLS(UT, ST) \ + OCTAVE_US_TYPE2_CMP_OP_DECLS (UT, ST) \ + OCTAVE_SU_TYPE2_CMP_OP_DECLS (ST, UT) + +OCTAVE_TYPE2_CMP_OP_DECLS (octave_uint32_t, octave_int64_t) + #define OCTAVE_INT_CONCAT_FN(TYPE) \ intNDArray< TYPE > \ concat (const intNDArray< TYPE >& ra, const intNDArray< TYPE >& rb, \ @@ -574,16 +635,32 @@ concat (const intNDArray< TYPE >& ra, const intNDArray< TYPE >& rb, \ const Array<int>& ra_idx); -#undef OCTAVE_INT_TRAIT #undef OCTAVE_INT_BINOP_TRAIT -#undef OCTAVE_INT_MIN_VAL -#undef OCTAVE_INT_MAX_VAL +#undef OCTAVE_US_S_FTR +#undef OCTAVE_US_S_FTR_FCNS +#undef OCTAVE_S_US_FTR +#undef OCTAVE_S_US_FTR_FCNS #undef OCTAVE_INT_FIT_TO_RANGE #undef OCTAVE_INT_MIN_VAL2 #undef OCTAVE_INT_MAX_VAL2 #undef OCTAVE_INT_FIT_TO_RANGE2 #undef OCTAVE_INT_BIN_OP +#undef OCTAVE_INT_DOUBLE_BIN_OP +#undef OCTAVE_DOUBLE_INT_BIN_OP +#undef OCTAVE_INT_DOUBLE_CMP_OP +#undef OCTAVE_DOUBLE_INT_CMP_OP +#undef OCTAVE_INT_BITCMP_OP #undef OCTAVE_INT_CMP_OP +#undef OCTAVE_US_TYPE1_CMP_OP_DECL +#undef OCTAVE_US_TYPE1_CMP_OP_DECLS +#undef OCTAVE_SU_TYPE1_CMP_OP_DECL +#undef OCTAVE_SU_TYPE1_CMP_OP_DECLS +#undef OCTAVE_TYPE1_CMP_OP_DECLS +#undef OCTAVE_US_TYPE2_CMP_OP_DECL +#undef OCTAVE_US_TYPE2_CMP_OP_DECLS +#undef OCTAVE_SU_TYPE2_CMP_OP_DECL +#undef OCTAVE_SU_TYPE2_CMP_OP_DECLS +#undef OCTAVE_TYPE2__DECLS #endif
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2004-11-08 John W. Eaton <jwe@octave.org> + + * plot/__plt2vm__.m: Delete debugging statement. + From Dmitri A. Sergatskov <dmitri@unm.edu>. + 2004-11-04 John W. Eaton <jwe@octave.org> * plot/hist.m: Always return row vectors for vector args.