Mercurial > hg > octave-lyh
diff liboctave/oct-inttypes.cc @ 8169:66bc6f9b4f72
rewrite integer arithmetics and conversions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 01 Oct 2008 11:05:13 -0400 |
parents | 6f10bbb2854a |
children | 69c5cce38c29 |
line wrap: on
line diff
--- a/liboctave/oct-inttypes.cc +++ b/liboctave/oct-inttypes.cc @@ -24,71 +24,164 @@ #include <config.h> #endif +#include "lo-error.h" + #include "oct-inttypes.h" -#define INSTANTIATE_INT_DOUBLE_BIN_OP(T, OP) \ - template OCTAVE_API octave_int<T> operator OP (const octave_int<T>&, double) +// define type names. +#define DECLARE_OCTAVE_INT_TYPENAME(TYPE, TYPENAME) \ + template <> \ + const char * \ + octave_int<TYPE>::type_name () { return TYPENAME; } -#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, /) +DECLARE_OCTAVE_INT_TYPENAME (int8_t, "int8") +DECLARE_OCTAVE_INT_TYPENAME (int16_t, "int16") +DECLARE_OCTAVE_INT_TYPENAME (int32_t, "int32") +DECLARE_OCTAVE_INT_TYPENAME (int64_t, "int64") +DECLARE_OCTAVE_INT_TYPENAME (uint8_t, "uint8") +DECLARE_OCTAVE_INT_TYPENAME (uint16_t, "uint16") +DECLARE_OCTAVE_INT_TYPENAME (uint32_t, "uint32") +DECLARE_OCTAVE_INT_TYPENAME (uint64_t, "uint64") + +static void +gripe_64bit_mul() +{ + (*current_liboctave_error_handler) + ("64-bit integer multiplication is not implemented"); +} -#define INSTANTIATE_DOUBLE_INT_BIN_OP(T, OP) \ - template OCTAVE_API octave_int<T> operator OP (double, const octave_int<T>&) +template <> +uint64_t +octave_int_arith_base<uint64_t, false>::mul (uint64_t, uint64_t) +{ + gripe_64bit_mul (); + return static_cast<uint64_t> (0); +} +template <> +int64_t +octave_int_arith_base<int64_t, true>::mul (int64_t, int64_t) +{ + gripe_64bit_mul (); + return static_cast<int64_t> (0); +} + +static void +gripe_64bit_mixed() +{ + (*current_liboctave_error_handler) + ("mixed double - 64-bit integer operations are not implemented"); +} -#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 DEFINE_DOUBLE_INT64_OP0(OP,ARGT,RETT) \ + template <> \ + OCTAVE_API RETT \ + operator OP (const double&, const ARGT&) \ + { gripe_64bit_mixed (); return 0.0; } \ + template <> \ + OCTAVE_API RETT \ + operator OP (const ARGT&, const double&) \ + { gripe_64bit_mixed (); return 0.0; } \ -#define INSTANTIATE_INT_DOUBLE_CMP_OP(T, OP) \ - template OCTAVE_API bool operator OP (const octave_int<T>&, const double&) +#define DEFINE_DOUBLE_INT64_BIN_OP(OP) \ + DEFINE_DOUBLE_INT64_OP0(OP,octave_int64,octave_int64) \ + DEFINE_DOUBLE_INT64_OP0(OP,octave_uint64,octave_uint64) + +DEFINE_DOUBLE_INT64_BIN_OP(+) +DEFINE_DOUBLE_INT64_BIN_OP(-) +DEFINE_DOUBLE_INT64_BIN_OP(*) +DEFINE_DOUBLE_INT64_BIN_OP(/) + +#define DEFINE_DOUBLE_INT64_CMP_OP(OP) \ + DEFINE_DOUBLE_INT64_OP0(OP,octave_int64,bool) \ + DEFINE_DOUBLE_INT64_OP0(OP,octave_uint64,bool) -#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_DOUBLE_INT64_CMP_OP(<) +DEFINE_DOUBLE_INT64_CMP_OP(<=) +DEFINE_DOUBLE_INT64_CMP_OP(>) +DEFINE_DOUBLE_INT64_CMP_OP(>=) +DEFINE_DOUBLE_INT64_CMP_OP(==) +DEFINE_DOUBLE_INT64_CMP_OP(!=) + +//template <class T> +//bool +//xisnan (const octave_int<T>&) +//{ +// return false; +//} -#define INSTANTIATE_DOUBLE_INT_CMP_OP(T, OP) \ - template OCTAVE_API bool operator OP (const double&, const octave_int<T>&) +template <class T> +octave_int<T> +pow (const octave_int<T>& a, const octave_int<T>& b) +{ + octave_int<T> retval; + + octave_int<T> zero = octave_int<T> (0); + octave_int<T> one = octave_int<T> (1); + + if (b == zero || a == one) + retval = one; + else if (b < zero) + { + if (std::numeric_limits<T>::is_signed && a.value () == -1) + retval = (b.value () % 2) ? a : one; + else + retval = zero; + } + else + { + octave_int<T> a_val = a; + T b_val = b; // no need to do saturation on b -#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, !=) + retval = a; + + b_val -= 1; + + while (b_val != 0) + { + if (b_val & 1) + retval = retval * a_val; + + b_val = b_val >> 1; + + if (b_val) + a_val = a_val * a_val; + } + } + + return retval; +} -#define INSTANTIATE_INT_BITCMP_OP(T, OP) \ - template OCTAVE_API octave_int<T> \ - operator OP (const octave_int<T>&, const octave_int<T>&) +template <class T> +octave_int<T> +pow (const double& a, const octave_int<T>& b) +{ return octave_int<T> (pow (a, b.double_value ())); } + +template <class T> +octave_int<T> +pow (const octave_int<T>& a, const double& b) +{ return octave_int<T> (pow (a.double_value (), b)); } -#define INSTANTIATE_INT_BITCMP_OPS(T) \ - INSTANTIATE_INT_BITCMP_OP (T, &); \ - INSTANTIATE_INT_BITCMP_OP (T, |); \ - INSTANTIATE_INT_BITCMP_OP (T, ^) +template <class T> +octave_int<T> +powf (const float& a, const octave_int<T>& b) +{ return octave_int<T> (pow (a, b.float_value ())); } + +template <class T> +octave_int<T> +powf (const octave_int<T>& a, const float& b) +{ return octave_int<T> (pow (a.float_value (), b)); } #define INSTANTIATE_INTTYPE(T) \ template class OCTAVE_API octave_int<T>; \ template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const octave_int<T>&); \ - template OCTAVE_API octave_int<T> pow (double, const octave_int<T>&); \ - template OCTAVE_API octave_int<T> pow (const octave_int<T>&, double b); \ + template OCTAVE_API octave_int<T> pow (const double&, const octave_int<T>&); \ + template OCTAVE_API octave_int<T> pow (const octave_int<T>&, const double&); \ + template OCTAVE_API octave_int<T> powf (const float&, const octave_int<T>&); \ + template OCTAVE_API octave_int<T> powf (const octave_int<T>&, const float&); \ template OCTAVE_API std::ostream& operator << (std::ostream&, const octave_int<T>&); \ template OCTAVE_API std::istream& operator >> (std::istream&, octave_int<T>&); \ template OCTAVE_API 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 (int8_t); INSTANTIATE_INTTYPE (int16_t); @@ -100,283 +193,6 @@ INSTANTIATE_INTTYPE (uint32_t); INSTANTIATE_INTTYPE (uint64_t); -#define INSTANTIATE_INTTYPE_BIN_OP(T1, T2, OP) \ - template OCTAVE_API octave_int<octave_int_binop_traits<T1, T2>::TR> \ - operator OP<T1, T2> (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 (int8_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int8_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int16_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int32_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (int64_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint8_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint16_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint32_t, uint64_t); - -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, int64_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint8_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint16_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint32_t); -INSTANTIATE_INTTYPE_BIN_OPS (uint64_t, uint64_t); - -#define INSTANTIATE_INTTYPE_SHIFT_OP(T, OP) \ - template OCTAVE_API 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 (int8_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (int16_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (int32_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (int64_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (uint8_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (uint16_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (uint32_t); -INSTANTIATE_INTTYPE_SHIFT_OPS (uint64_t); - -#define INSTANTIATE_OCTAVE_INT_CMP_OP(OP, T1, T2) \ - template OCTAVE_API 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 (int8_t, int8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint16_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint32_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int8_t, uint64_t); - -INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint16_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint32_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int16_t, uint64_t); - -INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint16_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint32_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int32_t, uint64_t); - -INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint16_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint32_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (int64_t, uint64_t); - -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint8_t, uint64_t); - -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint16_t, uint64_t); - -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int8_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int16_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int32_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint32_t, uint64_t); - -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int8_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int16_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int32_t); -// INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, int64_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint8_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint16_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, uint32_t); -INSTANTIATE_OCTAVE_INT_CMP_OPS (uint64_t, 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) \ - template <> \ - 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) \ - template <> \ - 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 (uint32_t, int8_t) -OCTAVE_TYPE1_CMP_OPS (uint32_t, int16_t) -OCTAVE_TYPE1_CMP_OPS (uint32_t, int32_t) - -OCTAVE_TYPE1_CMP_OPS (uint64_t, int8_t) -OCTAVE_TYPE1_CMP_OPS (uint64_t, int16_t) -OCTAVE_TYPE1_CMP_OPS (uint64_t, int32_t) -OCTAVE_TYPE1_CMP_OPS (uint64_t, 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) \ - template <> \ - 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) \ - template <> \ - 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 (uint32_t, int64_t) - - /* ;;; Local Variables: ***