メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

oct-inttypes.h

解説を見る。
00001 /*
00002 
00003 Copyright (C) 2004 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #if !defined (octave_inttypes_h)
00024 #define octave_inttypes_h 1
00025 
00026 #include <limits>
00027 #include <iostream>
00028 
00029 #include "data-conv.h"
00030 #include "lo-ieee.h"
00031 #include "lo-mappers.h"
00032 
00033 typedef signed char octave_int8_t;
00034 typedef TWO_BYTE_INT octave_int16_t;
00035 typedef FOUR_BYTE_INT octave_int32_t;
00036 typedef EIGHT_BYTE_INT octave_int64_t;
00037 
00038 typedef unsigned char octave_uint8_t;
00039 typedef unsigned TWO_BYTE_INT octave_uint16_t;
00040 typedef unsigned FOUR_BYTE_INT octave_uint32_t;
00041 typedef unsigned EIGHT_BYTE_INT octave_uint64_t;
00042 
00043 template <class T1, class T2>
00044 class
00045 octave_int_binop_traits
00046 {
00047 public:
00048   // The return type for a T1 by T2 binary operation.
00049   typedef T1 TR;
00050 };
00051 
00052 #define OCTAVE_INT_BINOP_TRAIT(T1, T2, T3) \
00053   template<> \
00054   class octave_int_binop_traits <T1, T2> \
00055   { \
00056   public: \
00057     typedef T3 TR; \
00058   }
00059 
00060 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int8_t, octave_int8_t);
00061 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int16_t, octave_int8_t);
00062 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int32_t, octave_int8_t);
00063 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_int64_t, octave_int8_t);
00064 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint8_t, octave_int8_t);
00065 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint16_t, octave_int8_t);
00066 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint32_t, octave_int8_t);
00067 OCTAVE_INT_BINOP_TRAIT (octave_int8_t, octave_uint64_t, octave_int8_t);
00068 
00069 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int8_t, octave_int16_t);
00070 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int16_t, octave_int16_t);
00071 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int32_t, octave_int16_t);
00072 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_int64_t, octave_int16_t);
00073 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint8_t, octave_int16_t);
00074 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint16_t, octave_int16_t);
00075 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint32_t, octave_int16_t);
00076 OCTAVE_INT_BINOP_TRAIT (octave_int16_t, octave_uint64_t, octave_int16_t);
00077 
00078 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int8_t, octave_int32_t);
00079 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int16_t, octave_int32_t);
00080 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int32_t, octave_int32_t);
00081 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_int64_t, octave_int32_t);
00082 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint8_t, octave_int32_t);
00083 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint16_t, octave_int32_t);
00084 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint32_t, octave_int32_t);
00085 OCTAVE_INT_BINOP_TRAIT (octave_int32_t, octave_uint64_t, octave_int32_t);
00086 
00087 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int8_t, octave_int64_t);
00088 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int16_t, octave_int64_t);
00089 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int32_t, octave_int64_t);
00090 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_int64_t, octave_int64_t);
00091 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint8_t, octave_int64_t);
00092 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint16_t, octave_int64_t);
00093 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint32_t, octave_int64_t);
00094 OCTAVE_INT_BINOP_TRAIT (octave_int64_t, octave_uint64_t, octave_int64_t);
00095 
00096 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int8_t, octave_int8_t);
00097 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int16_t, octave_int8_t);
00098 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int32_t, octave_int8_t);
00099 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_int64_t, octave_int8_t);
00100 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint8_t, octave_uint8_t);
00101 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint16_t, octave_uint8_t);
00102 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint32_t, octave_uint8_t);
00103 OCTAVE_INT_BINOP_TRAIT (octave_uint8_t, octave_uint64_t, octave_uint8_t);
00104 
00105 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int8_t, octave_int16_t);
00106 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int16_t, octave_int16_t);
00107 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int32_t, octave_int16_t);
00108 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_int64_t, octave_int16_t);
00109 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint8_t, octave_uint16_t);
00110 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint16_t, octave_uint16_t);
00111 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint32_t, octave_uint16_t);
00112 OCTAVE_INT_BINOP_TRAIT (octave_uint16_t, octave_uint64_t, octave_uint16_t);
00113 
00114 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int8_t, octave_int32_t);
00115 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int16_t, octave_int32_t);
00116 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int32_t, octave_int32_t);
00117 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_int64_t, octave_int32_t);
00118 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint8_t, octave_uint32_t);
00119 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint16_t, octave_uint32_t);
00120 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint32_t, octave_uint32_t);
00121 OCTAVE_INT_BINOP_TRAIT (octave_uint32_t, octave_uint64_t, octave_uint32_t);
00122 
00123 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int8_t, octave_int64_t);
00124 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int16_t, octave_int64_t);
00125 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int32_t, octave_int64_t);
00126 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_int64_t, octave_int64_t);
00127 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint8_t, octave_uint64_t);
00128 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint16_t, octave_uint64_t);
00129 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint32_t, octave_uint64_t);
00130 OCTAVE_INT_BINOP_TRAIT (octave_uint64_t, octave_uint64_t, octave_uint64_t);
00131 
00132 template <class T1, class T2>
00133 inline T2
00134 octave_int_fit_to_range (const T1& x, const T2& mn, const T2& mx)
00135 {
00136   return (x > mx ? mx : (x < mn ? mn : T2 (x)));
00137 }
00138 
00139 // If X is unsigned and the new type is signed, then we only have to
00140 // check the upper limit, but we should cast the maximum value of the
00141 // new type to an unsigned type before performing the comparison.
00142 // This should always be OK because the maximum value should always be
00143 // positive.
00144 
00145 #define OCTAVE_US_S_FTR(T1, T2, TC) \
00146   template <> \
00147   inline T2 \
00148   octave_int_fit_to_range<T1, T2> (const T1& x, const T2&, const T2& mx) \
00149   { \
00150     return x > static_cast<TC> (mx) ? mx : x; \
00151   }
00152 
00153 #define OCTAVE_US_S_FTR_FCNS(T) \
00154   OCTAVE_US_S_FTR (T, char, unsigned char) \
00155   OCTAVE_US_S_FTR (T, signed char, unsigned char) \
00156   OCTAVE_US_S_FTR (T, short, unsigned short) \
00157   OCTAVE_US_S_FTR (T, int, unsigned int) \
00158   OCTAVE_US_S_FTR (T, long, unsigned long) \
00159   OCTAVE_US_S_FTR (T, long long, unsigned long long)
00160 
00161 OCTAVE_US_S_FTR_FCNS (unsigned char)
00162 OCTAVE_US_S_FTR_FCNS (unsigned short)
00163 OCTAVE_US_S_FTR_FCNS (unsigned int)
00164 OCTAVE_US_S_FTR_FCNS (unsigned long)
00165 OCTAVE_US_S_FTR_FCNS (unsigned long long)
00166 
00167 // If X is signed and the new type is unsigned, then we only have to
00168 // check the lower limit (which will always be 0 for an unsigned
00169 // type).  The upper limit will be enforced correctly by converting to
00170 // the new type, even if the type of X is wider than the new type.
00171 
00172 #define OCTAVE_S_US_FTR(T1, T2) \
00173   template <> \
00174   inline T2 \
00175   octave_int_fit_to_range<T1, T2> (const T1& x, const T2&, const T2&) \
00176   { \
00177     return x < 0 ? 0 : x; \
00178   }
00179 
00180 #define OCTAVE_S_US_FTR_FCNS(T) \
00181   OCTAVE_S_US_FTR (T, unsigned char) \
00182   OCTAVE_S_US_FTR (T, unsigned short) \
00183   OCTAVE_S_US_FTR (T, unsigned int) \
00184   OCTAVE_S_US_FTR (T, unsigned long) \
00185   OCTAVE_S_US_FTR (T, unsigned long long)
00186 
00187 OCTAVE_S_US_FTR_FCNS (char)
00188 OCTAVE_S_US_FTR_FCNS (signed char)
00189 OCTAVE_S_US_FTR_FCNS (short)
00190 OCTAVE_S_US_FTR_FCNS (int)
00191 OCTAVE_S_US_FTR_FCNS (long)
00192 OCTAVE_S_US_FTR_FCNS (long long)
00193 
00194 #define OCTAVE_INT_FIT_TO_RANGE(r, T) \
00195   octave_int_fit_to_range (r, \
00196                            std::numeric_limits<T>::min (), \
00197                            std::numeric_limits<T>::max ())
00198 
00199 #define OCTAVE_INT_MIN_VAL2(T1, T2) \
00200   std::numeric_limits<typename octave_int_binop_traits<T1, T2>::TR>::min ()
00201 
00202 #define OCTAVE_INT_MAX_VAL2(T1, T2) \
00203   std::numeric_limits<typename octave_int_binop_traits<T1, T2>::TR>::max ()
00204 
00205 #define OCTAVE_INT_FIT_TO_RANGE2(r, T1, T2) \
00206   octave_int_fit_to_range (r, \
00207                            OCTAVE_INT_MIN_VAL2 (T1, T2), \
00208                            OCTAVE_INT_MAX_VAL2 (T1, T2))
00209 
00210 template <class T>
00211 class
00212 octave_int
00213 {
00214 public:
00215 
00216   typedef T val_type;
00217 
00218   octave_int (void) : ival () { }
00219 
00220   template <class U>
00221   octave_int (U i) : ival (OCTAVE_INT_FIT_TO_RANGE (i, T)) { }
00222 
00223   octave_int (bool b) : ival (b) { }
00224 
00225   template <class U>
00226   octave_int (const octave_int<U>& i)
00227     : ival (OCTAVE_INT_FIT_TO_RANGE (i.value (), T)) { }
00228 
00229   octave_int (const octave_int<T>& i) : ival (i.ival) { }
00230 
00231   octave_int& operator = (const octave_int<T>& i)
00232   {
00233     ival = i.ival;
00234     return *this;
00235   }
00236 
00237   ~octave_int (void) { }
00238   
00239   T value (void) const { return ival; }
00240 
00241   const unsigned char * iptr (void) const
00242   { return reinterpret_cast<const unsigned char *> (& ival); }
00243 
00244   bool operator ! (void) const { return ! ival; }
00245 
00246   octave_int<T> operator + (void) const { return *this; }
00247 
00248   octave_int<T> operator - (void) const
00249   {
00250     // Can't just return -ival because signed types are not
00251     // symmetric, which causes things like -intmin("int32") to be the
00252     // same as intmin("int32") instead of intmax("int32") (which is
00253     // what we should get with saturation semantics).
00254 
00255     return std::numeric_limits<T>::is_signed ?
00256       OCTAVE_INT_FIT_TO_RANGE (- static_cast<double> (ival), T) : 0;
00257   }
00258 
00259   operator double (void) const { return static_cast<double> (value ()); }
00260 
00261   operator float (void) const { return static_cast<float> (value ()); }
00262 
00263   octave_int<T>& operator += (const octave_int<T>& x)
00264   {
00265     double t = static_cast<double> (value ());
00266     double tx = static_cast<double> (x.value ());
00267     ival = OCTAVE_INT_FIT_TO_RANGE (t + tx, T);
00268     return *this;
00269   }
00270 
00271   octave_int<T>& operator -= (const octave_int<T>& x)
00272   {
00273     double t = static_cast<double> (value ());
00274     double tx = static_cast<double> (x.value ());
00275     ival = OCTAVE_INT_FIT_TO_RANGE (t - tx, T);
00276     return *this;
00277   }
00278 
00279   octave_int<T>& operator *= (const octave_int<T>& x)
00280   {
00281     double t = static_cast<double> (value ());
00282     double tx = static_cast<double> (x.value ());
00283     ival = OCTAVE_INT_FIT_TO_RANGE (t * tx, T);
00284     return *this;
00285   }
00286 
00287   octave_int<T>& operator /= (const octave_int<T>& x)
00288   {
00289     double t = static_cast<double> (value ());
00290     double tx = static_cast<double> (x.value ());
00291     double r = (t == 0 && tx == 0) ? 0 : xround (t / tx);
00292     ival = OCTAVE_INT_FIT_TO_RANGE (r, T);
00293     return *this;
00294   }
00295 
00296   template <class T2>
00297   octave_int<T>& operator <<= (const T2& x)
00298   {
00299     ival = ((ival << x) > std::numeric_limits<T>::max ()) ? 0 : (ival << x);
00300     return *this;
00301   }
00302 
00303   template <class T2>
00304   octave_int<T>& operator >>= (const T2& x)
00305   {
00306     ival >>= x;
00307     return *this;
00308   }
00309 
00310   octave_int<T> min (void) const { return std::numeric_limits<T>::min (); }
00311   octave_int<T> max (void) const { return std::numeric_limits<T>::max (); }
00312 
00313   static int nbits (void) { return sizeof (T) * CHAR_BIT; }
00314 
00315   static int byte_size (void) { return sizeof(T); }
00316 
00317 private:
00318 
00319   T ival;
00320 };
00321 
00322 template <class T>
00323 octave_int<T>
00324 pow (const octave_int<T>& a, const octave_int<T>& b)
00325 {
00326   octave_int<T> retval;
00327 
00328   octave_int<T> zero = octave_int<T> (0);
00329   octave_int<T> one = octave_int<T> (1);
00330 
00331   if (b == zero)
00332     retval = one;
00333   else if (b < zero)
00334     retval = zero;
00335   else
00336     {
00337       octave_int<T> a_val = a;
00338       octave_int<T> b_val = b;
00339 
00340       retval = a;
00341 
00342       b_val -= 1;
00343 
00344       while (b_val != zero)
00345         {
00346           if ((b_val & one) != zero)
00347             retval = retval * a_val;
00348 
00349           b_val = b_val >> 1;
00350 
00351           if (b_val > zero)
00352             a_val = a_val * a_val;
00353         }
00354     }
00355 
00356   return retval;
00357 }
00358 
00359 template <class T>
00360 octave_int<T>
00361 pow (double a, const octave_int<T>& b)
00362 {
00363   double tb = static_cast<double> (b.value ());
00364   double r = pow (a, tb);
00365   r = lo_ieee_isnan (r) ? 0 : xround (r);
00366   return OCTAVE_INT_FIT_TO_RANGE (r, T);
00367 }
00368 
00369 template <class T>
00370 octave_int<T>
00371 pow (const octave_int<T>& a, double b)
00372 {
00373   double ta = static_cast<double> (a.value ());
00374   double r = pow (ta, b);
00375   r = lo_ieee_isnan (r) ? 0 : xround (r);
00376   return OCTAVE_INT_FIT_TO_RANGE (r, T);
00377 }
00378 
00379 template <class T>
00380 std::ostream&
00381 operator << (std::ostream& os, const octave_int<T>& ival)
00382 {
00383   os << ival.value ();
00384   return os;
00385 }
00386 
00387 template <class T>
00388 std::istream&
00389 operator >> (std::istream& is, octave_int<T>& ival)
00390 {
00391   T tmp = 0;
00392   is >> tmp;
00393   ival = tmp;
00394   return is;
00395 }
00396 
00397 typedef octave_int<octave_int8_t> octave_int8;
00398 typedef octave_int<octave_int16_t> octave_int16;
00399 typedef octave_int<octave_int32_t> octave_int32;
00400 typedef octave_int<octave_int64_t> octave_int64;
00401 
00402 typedef octave_int<octave_uint8_t> octave_uint8;
00403 typedef octave_int<octave_uint16_t> octave_uint16;
00404 typedef octave_int<octave_uint32_t> octave_uint32;
00405 typedef octave_int<octave_uint64_t> octave_uint64;
00406 
00407 #define OCTAVE_INT_BIN_OP(OP) \
00408   template <class T1, class T2> \
00409   octave_int<typename octave_int_binop_traits<T1, T2>::TR> \
00410   operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \
00411   { \
00412     double tx = static_cast<double> (x.value ()); \
00413     double ty = static_cast<double> (y.value ()); \
00414     double r = tx OP ty; \
00415     return OCTAVE_INT_FIT_TO_RANGE2 (r, T1, T2); \
00416   }
00417 
00418 OCTAVE_INT_BIN_OP(+)
00419 OCTAVE_INT_BIN_OP(-)
00420 OCTAVE_INT_BIN_OP(*)
00421 
00422 template <class T1, class T2>
00423 octave_int<typename octave_int_binop_traits<T1, T2>::TR>
00424 operator / (const octave_int<T1>& x, const octave_int<T2>& y)
00425 {
00426   double tx = static_cast<double> (x.value ());
00427   double ty = static_cast<double> (y.value ());
00428   double r = (tx == 0 && ty == 0) ? 0 : tx / ty;
00429   return OCTAVE_INT_FIT_TO_RANGE2 (r, T1, T2);
00430 }
00431 
00432 #define OCTAVE_INT_DOUBLE_BIN_OP(OP) \
00433   template <class T> \
00434   octave_int<T> \
00435   operator OP (const octave_int<T>& x, double y) \
00436   { \
00437     double tx = static_cast<double> (x.value ()); \
00438     double r = xround (tx OP y); \
00439     r = lo_ieee_isnan (r) ? 0 : xround (r); \
00440     return OCTAVE_INT_FIT_TO_RANGE (r, T); \
00441   }
00442 
00443 OCTAVE_INT_DOUBLE_BIN_OP(+)
00444 OCTAVE_INT_DOUBLE_BIN_OP(-)
00445 OCTAVE_INT_DOUBLE_BIN_OP(*)
00446 OCTAVE_INT_DOUBLE_BIN_OP(/)
00447 
00448 #define OCTAVE_DOUBLE_INT_BIN_OP(OP) \
00449   template <class T> \
00450   octave_int<T> \
00451   operator OP (double x, const octave_int<T>& y) \
00452   { \
00453     double ty = static_cast<double> (y.value ()); \
00454     double r = x OP ty; \
00455     r = lo_ieee_isnan (r) ? 0 : xround (r); \
00456     return OCTAVE_INT_FIT_TO_RANGE (r, T); \
00457   }
00458 
00459 OCTAVE_DOUBLE_INT_BIN_OP(+)
00460 OCTAVE_DOUBLE_INT_BIN_OP(-)
00461 OCTAVE_DOUBLE_INT_BIN_OP(*)
00462 OCTAVE_DOUBLE_INT_BIN_OP(/)
00463 
00464 #define OCTAVE_INT_DOUBLE_CMP_OP(OP) \
00465   template <class T> \
00466   bool \
00467   operator OP (const octave_int<T>& x, const double& y) \
00468   { \
00469     double tx = static_cast<double> (x.value ()); \
00470     return tx OP y; \
00471   }
00472 
00473 OCTAVE_INT_DOUBLE_CMP_OP (<)
00474 OCTAVE_INT_DOUBLE_CMP_OP (<=)
00475 OCTAVE_INT_DOUBLE_CMP_OP (>=)
00476 OCTAVE_INT_DOUBLE_CMP_OP (>)
00477 OCTAVE_INT_DOUBLE_CMP_OP (==)
00478 OCTAVE_INT_DOUBLE_CMP_OP (!=)
00479 
00480 #define OCTAVE_DOUBLE_INT_CMP_OP(OP) \
00481   template <class T> \
00482   bool \
00483   operator OP (const double& x, const octave_int<T>& y) \
00484   { \
00485     double ty = static_cast<double> (y.value ()); \
00486     return x OP ty; \
00487   }
00488 
00489 OCTAVE_DOUBLE_INT_CMP_OP (<)
00490 OCTAVE_DOUBLE_INT_CMP_OP (<=)
00491 OCTAVE_DOUBLE_INT_CMP_OP (>=)
00492 OCTAVE_DOUBLE_INT_CMP_OP (>)
00493 OCTAVE_DOUBLE_INT_CMP_OP (==)
00494 OCTAVE_DOUBLE_INT_CMP_OP (!=)
00495 
00496 #define OCTAVE_INT_BITCMP_OP(OP) \
00497   template <class T> \
00498   octave_int<T> \
00499   operator OP (const octave_int<T>& x, const octave_int<T>& y) \
00500   { \
00501     return x.value () OP y.value (); \
00502   }
00503 
00504 OCTAVE_INT_BITCMP_OP (&)
00505 OCTAVE_INT_BITCMP_OP (|)
00506 OCTAVE_INT_BITCMP_OP (^)
00507 
00508 template <class T1, class T2>
00509 octave_int<T1>
00510 operator << (const octave_int<T1>& x, const T2& y)
00511 {
00512   octave_int<T1> retval = x;
00513   return retval <<= y;
00514 }
00515 
00516 template <class T1, class T2>
00517 octave_int<T1>
00518 operator >> (const octave_int<T1>& x, const T2& y)
00519 {
00520   octave_int<T1> retval = x;
00521   return retval >>= y;
00522 }
00523 
00524 template <class T>
00525 octave_int<T>
00526 bitshift (const octave_int<T>& a, int n,
00527           const octave_int<T>& mask = std::numeric_limits<T>::max ())
00528 {
00529   if (n > 0)
00530     return (a << n) & mask;
00531   else if (n < 0)
00532     return (a >> -n) & mask;
00533   else
00534     return a;
00535 }
00536 
00537 #define OCTAVE_INT_CMP_OP(OP) \
00538   template <class T1, class T2> \
00539   bool \
00540   operator OP (const octave_int<T1>& x, const octave_int<T2>& y) \
00541   { \
00542     return x.value () OP y.value (); \
00543   }
00544 
00545 OCTAVE_INT_CMP_OP (<)
00546 OCTAVE_INT_CMP_OP (<=)
00547 OCTAVE_INT_CMP_OP (>=)
00548 OCTAVE_INT_CMP_OP (>)
00549 OCTAVE_INT_CMP_OP (==)
00550 OCTAVE_INT_CMP_OP (!=)
00551 
00552 // The following apply if the unsigned type is at least as wide as the
00553 // signed type (then we can cast postive signed values to the unsigned
00554 // type and compare).
00555 
00556 #define OCTAVE_US_TYPE1_CMP_OP_DECL(OP, LTZ_VAL, UT, ST) \
00557   bool operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs);
00558 
00559 #define OCTAVE_US_TYPE1_CMP_OP_DECLS(UT, ST) \
00560   OCTAVE_US_TYPE1_CMP_OP_DECL (<, false, UT, ST) \
00561   OCTAVE_US_TYPE1_CMP_OP_DECL (<=, false, UT, ST) \
00562   OCTAVE_US_TYPE1_CMP_OP_DECL (>=, true, UT, ST) \
00563   OCTAVE_US_TYPE1_CMP_OP_DECL (>, true, UT, ST) \
00564   OCTAVE_US_TYPE1_CMP_OP_DECL (==, false, UT, ST) \
00565   OCTAVE_US_TYPE1_CMP_OP_DECL (!=, true, UT, ST)
00566 
00567 #define OCTAVE_SU_TYPE1_CMP_OP_DECL(OP, LTZ_VAL, ST, UT) \
00568   bool operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs);
00569 
00570 #define OCTAVE_SU_TYPE1_CMP_OP_DECLS(ST, UT) \
00571   OCTAVE_SU_TYPE1_CMP_OP_DECL (<, true, ST, UT) \
00572   OCTAVE_SU_TYPE1_CMP_OP_DECL (<=, true, ST, UT) \
00573   OCTAVE_SU_TYPE1_CMP_OP_DECL (>=, false, ST, UT) \
00574   OCTAVE_SU_TYPE1_CMP_OP_DECL (>, false, ST, UT) \
00575   OCTAVE_SU_TYPE1_CMP_OP_DECL (==, false, ST, UT) \
00576   OCTAVE_SU_TYPE1_CMP_OP_DECL (!=, true, ST, UT)
00577 
00578 #define OCTAVE_TYPE1_CMP_OP_DECLS(UT, ST) \
00579   OCTAVE_US_TYPE1_CMP_OP_DECLS (UT, ST) \
00580   OCTAVE_SU_TYPE1_CMP_OP_DECLS (ST, UT)
00581 
00582 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint32_t, octave_int8_t)
00583 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint32_t, octave_int16_t)
00584 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint32_t, octave_int32_t)
00585 
00586 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int8_t)
00587 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int16_t)
00588 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int32_t)
00589 OCTAVE_TYPE1_CMP_OP_DECLS (octave_uint64_t, octave_int64_t)
00590 
00591 // The following apply if the signed type is wider than the unsigned
00592 // type (then we can cast unsigned values to the signed type and
00593 // compare if the signed value is positive).
00594 
00595 #define OCTAVE_US_TYPE2_CMP_OP_DECL(OP, LTZ_VAL, UT, ST) \
00596   bool operator OP (const octave_int<UT>& lhs, const octave_int<ST>& rhs);
00597 
00598 #define OCTAVE_US_TYPE2_CMP_OP_DECLS(ST, UT) \
00599   OCTAVE_US_TYPE2_CMP_OP_DECL (<, false, ST, UT) \
00600   OCTAVE_US_TYPE2_CMP_OP_DECL (<=, false, ST, UT) \
00601   OCTAVE_US_TYPE2_CMP_OP_DECL (>=, true, ST, UT) \
00602   OCTAVE_US_TYPE2_CMP_OP_DECL (>, true, ST, UT) \
00603   OCTAVE_US_TYPE2_CMP_OP_DECL (==, false, ST, UT) \
00604   OCTAVE_US_TYPE2_CMP_OP_DECL (!=, true, ST, UT)
00605 
00606 #define OCTAVE_SU_TYPE2_CMP_OP_DECL(OP, LTZ_VAL, ST, UT) \
00607   bool operator OP (const octave_int<ST>& lhs, const octave_int<UT>& rhs);
00608 
00609 #define OCTAVE_SU_TYPE2_CMP_OP_DECLS(ST, UT) \
00610   OCTAVE_SU_TYPE2_CMP_OP_DECL (<, true, ST, UT) \
00611   OCTAVE_SU_TYPE2_CMP_OP_DECL (<=, true, ST, UT) \
00612   OCTAVE_SU_TYPE2_CMP_OP_DECL (>=, false, ST, UT) \
00613   OCTAVE_SU_TYPE2_CMP_OP_DECL (>, false, ST, UT) \
00614   OCTAVE_SU_TYPE2_CMP_OP_DECL (==, false, ST, UT) \
00615   OCTAVE_SU_TYPE2_CMP_OP_DECL (!=, true, ST, UT)
00616 
00617 #define OCTAVE_TYPE2_CMP_OP_DECLS(UT, ST) \
00618   OCTAVE_US_TYPE2_CMP_OP_DECLS (UT, ST) \
00619   OCTAVE_SU_TYPE2_CMP_OP_DECLS (ST, UT)
00620 
00621 OCTAVE_TYPE2_CMP_OP_DECLS (octave_uint32_t, octave_int64_t)
00622 
00623 #undef OCTAVE_INT_BINOP_TRAIT
00624 #undef OCTAVE_US_S_FTR
00625 #undef OCTAVE_US_S_FTR_FCNS
00626 #undef OCTAVE_S_US_FTR
00627 #undef OCTAVE_S_US_FTR_FCNS
00628 #undef OCTAVE_INT_FIT_TO_RANGE
00629 #undef OCTAVE_INT_MIN_VAL2
00630 #undef OCTAVE_INT_MAX_VAL2
00631 #undef OCTAVE_INT_FIT_TO_RANGE2
00632 #undef OCTAVE_INT_BIN_OP
00633 #undef OCTAVE_INT_DOUBLE_BIN_OP
00634 #undef OCTAVE_DOUBLE_INT_BIN_OP
00635 #undef OCTAVE_INT_DOUBLE_CMP_OP
00636 #undef OCTAVE_DOUBLE_INT_CMP_OP
00637 #undef OCTAVE_INT_BITCMP_OP
00638 #undef OCTAVE_INT_CMP_OP
00639 #undef OCTAVE_US_TYPE1_CMP_OP_DECL
00640 #undef OCTAVE_US_TYPE1_CMP_OP_DECLS
00641 #undef OCTAVE_SU_TYPE1_CMP_OP_DECL
00642 #undef OCTAVE_SU_TYPE1_CMP_OP_DECLS
00643 #undef OCTAVE_TYPE1_CMP_OP_DECLS
00644 #undef OCTAVE_US_TYPE2_CMP_OP_DECL
00645 #undef OCTAVE_US_TYPE2_CMP_OP_DECLS
00646 #undef OCTAVE_SU_TYPE2_CMP_OP_DECL
00647 #undef OCTAVE_SU_TYPE2_CMP_OP_DECLS
00648 #undef OCTAVE_TYPE2_CMP_OP_DECLS
00649 
00650 #endif
00651 
00652 /*
00653 ;;; Local Variables: ***
00654 ;;; mode: C++ ***
00655 ;;; End: ***
00656 */

Wed Dec 29 11:52:09 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送