Mercurial > hg > octave-nkf
changeset 4909:5c9e36402f17
[project @ 2004-07-12 17:08:24 by jwe]
author | jwe |
---|---|
date | Mon, 12 Jul 2004 17:10:29 +0000 |
parents | 66af4b9f451e |
children | 1242acab4246 |
files | liboctave/ChangeLog liboctave/oct-inttypes.h |
diffstat | 2 files changed, 83 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2004-07-12 John W. Eaton <jwe@octave.org> + + * oct-inttypes.h (octave_int<T>::nbits): New function. + (bitshift (const octave_int<T>&, int)): New function. + 2004-06-14 John W. Eaton <jwe@octave.org> * mx-base.h: Include headers for new int types.
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -56,77 +56,77 @@ typedef T3 TR; \ } -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int8_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int16_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int32_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_int64_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint8_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint16_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint32_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int8_t, octave_uint64_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int8_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int16_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int32_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int64_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint8_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint16_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint32_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint64_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int8_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int16_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int32_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_int64_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint8_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint16_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint32_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int16_t, octave_uint64_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int8_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int16_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int32_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int64_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint8_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint16_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint32_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint64_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int8_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int16_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int32_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_int64_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint8_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint16_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint32_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int32_t, octave_uint64_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int8_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int16_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int32_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int64_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint8_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint16_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint32_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint64_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int8_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int16_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int32_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_int64_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint8_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint16_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint32_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_int64_t, octave_uint64_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int8_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int16_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int32_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int64_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint8_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint16_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint32_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint64_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int8_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int16_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int32_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_int64_t, octave_int8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint8_t, octave_uint8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint16_t, octave_uint8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint32_t, octave_uint8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint8_t, octave_uint64_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int8_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int16_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int32_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int64_t, octave_int8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint8_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint16_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint32_t, octave_uint8_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint64_t, octave_uint8_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int8_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int16_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int32_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_int64_t, octave_int16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint8_t, octave_uint16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint16_t, octave_uint16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint32_t, octave_uint16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint16_t, octave_uint64_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int8_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int16_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int32_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int64_t, octave_int16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint8_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint16_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint32_t, octave_uint16_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint64_t, octave_uint16_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int8_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int16_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int32_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_int64_t, octave_int32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint8_t, octave_uint32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint16_t, octave_uint32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint32_t, octave_uint32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint32_t, octave_uint64_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int8_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int16_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int32_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int64_t, octave_int32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint8_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint16_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint32_t, octave_uint32_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint64_t, octave_uint32_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int8_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int16_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int32_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_int64_t, octave_int64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint8_t, octave_uint64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint16_t, octave_uint64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint32_t, octave_uint64_t); -OCTAVE_INT_BINOP_TRAIT(octave_uint64_t, octave_uint64_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int8_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int16_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int32_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int64_t, octave_int64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint8_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint16_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint32_t, octave_uint64_t); +OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint64_t, octave_uint64_t); template <class T1, class T2> inline T2 @@ -208,6 +208,8 @@ octave_int<T> min (void) const { return std::numeric_limits<T>::min (); } octave_int<T> max (void) const { return std::numeric_limits<T>::max (); } + int nbits (void) const { return sizeof (T) * CHAR_BIT; } + private: T ival; @@ -283,6 +285,18 @@ OCTAVE_INT_BITSHIFT_OP (<<) OCTAVE_INT_BITSHIFT_OP (>>) +template <class T> +octave_int<T> +bitshift (const octave_int<T>& a, int n) +{ + if (n > 0) + return a << n; + else if (n < 0) + return a >> -n; + else + return a; +} + #define OCTAVE_INT_CMP_OP(OP) \ \ template <class T1, class T2> \