comparison liboctave/util/oct-inttypes.h @ 18084:8e056300994b

Follow coding convention of defining and initializing only 1 variable per line in liboctave. * liboctave/array/Array-b.cc, liboctave/array/Array-util.cc, liboctave/array/Array.cc, liboctave/array/CDiagMatrix.cc, liboctave/array/CMatrix.cc, liboctave/array/CSparse.cc, liboctave/array/MDiagArray2.cc, liboctave/array/MatrixType.cc, liboctave/array/PermMatrix.cc, liboctave/array/Sparse.cc, liboctave/array/Sparse.h, liboctave/array/boolSparse.cc, liboctave/array/dDiagMatrix.cc, liboctave/array/dMatrix.cc, liboctave/array/dSparse.cc, liboctave/array/dim-vector.cc, liboctave/array/fCDiagMatrix.cc, liboctave/array/fCMatrix.cc, liboctave/array/fDiagMatrix.cc, liboctave/array/fMatrix.cc, liboctave/array/idx-vector.cc, liboctave/array/idx-vector.h, liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxQR.cc, liboctave/numeric/base-qr.cc, liboctave/numeric/bsxfun-defs.cc, liboctave/numeric/bsxfun.h, liboctave/numeric/dbleLU.cc, liboctave/numeric/dbleQR.cc, liboctave/numeric/fCmplxLU.cc, liboctave/numeric/fCmplxQR.cc, liboctave/numeric/floatLU.cc, liboctave/numeric/floatQR.cc, liboctave/numeric/lo-specfun.cc, liboctave/numeric/oct-convn.cc, liboctave/numeric/oct-norm.cc, liboctave/numeric/sparse-dmsolve.cc, liboctave/operators/mx-inlines.cc, liboctave/operators/mx-op-defs.h, liboctave/util/caseless-str.h, liboctave/util/kpse.cc, liboctave/util/lo-utils.cc, liboctave/util/oct-binmap.h, liboctave/util/oct-cmplx.h, liboctave/util/oct-inttypes.cc, liboctave/util/oct-inttypes.h, liboctave/util/oct-sort.cc: Follow coding convention of defining and initializing only 1 variable per line in liboctave.
author Rik <rik@octave.org>
date Wed, 04 Dec 2013 22:13:18 -0800
parents 0cd39f7f2409
children 545a77c3206e
comparison
equal deleted inserted replaced
18083:938f01339043 18084:8e056300994b
79 // ltval, gtval determine the value of x OP y if x < y, x > y, respectively. 79 // ltval, gtval determine the value of x OP y if x < y, x > y, respectively.
80 #define REGISTER_OCTAVE_CMP_OP(NM,OP) \ 80 #define REGISTER_OCTAVE_CMP_OP(NM,OP) \
81 class NM \ 81 class NM \
82 { \ 82 { \
83 public: \ 83 public: \
84 static const bool ltval = (0 OP 1), gtval = (1 OP 0); \ 84 static const bool ltval = (0 OP 1); \
85 static const bool gtval = (1 OP 0); \
85 template <class T> \ 86 template <class T> \
86 static bool op (T x, T y) { return x OP y; } \ 87 static bool op (T x, T y) { return x OP y; } \
87 } 88 }
88 89
89 // We also provide two special relations: ct, yielding always true, and cf, 90 // We also provide two special relations: ct, yielding always true, and cf,
90 // yielding always false. 91 // yielding always false.
91 #define REGISTER_OCTAVE_CONST_OP(NM,value) \ 92 #define REGISTER_OCTAVE_CONST_OP(NM,value) \
92 class NM \ 93 class NM \
93 { \ 94 { \
94 public: \ 95 public: \
95 static const bool ltval = value, gtval = value; \ 96 static const bool ltval = value; \
97 static const bool gtval = value; \
96 template <class T> \ 98 template <class T> \
97 static bool op (T, T) { return value; } \ 99 static bool op (T, T) { return value; } \
98 } 100 }
99 101
100 // Handles non-homogeneous integer comparisons. Avoids doing useless tests. 102 // Handles non-homogeneous integer comparisons. Avoids doing useless tests.
266 truncate_int (const S& value) 268 truncate_int (const S& value)
267 { 269 {
268 // An exhaustive test whether the max and/or min check can be omitted. 270 // An exhaustive test whether the max and/or min check can be omitted.
269 static const bool t_is_signed = std::numeric_limits<T>::is_signed; 271 static const bool t_is_signed = std::numeric_limits<T>::is_signed;
270 static const bool s_is_signed = std::numeric_limits<S>::is_signed; 272 static const bool s_is_signed = std::numeric_limits<S>::is_signed;
271 static const int t_size = sizeof (T), s_size = sizeof (S); 273 static const int t_size = sizeof (T);
274 static const int s_size = sizeof (S);
275
272 static const bool omit_chk_min = 276 static const bool omit_chk_min =
273 (! s_is_signed || (t_is_signed && t_size >= s_size)); 277 (! s_is_signed || (t_is_signed && t_size >= s_size));
274 static const bool omit_chk_max = 278 static const bool omit_chk_max =
275 (t_size > s_size || (t_size == s_size 279 (t_size > s_size || (t_size == s_size
276 && (! t_is_signed || s_is_signed))); 280 && (! t_is_signed || s_is_signed)));
418 static T 422 static T
419 div (T x, T y) 423 div (T x, T y)
420 { 424 {
421 if (y != 0) 425 if (y != 0)
422 { 426 {
423 T z = x / y, w = x % y; 427 T z = x / y;
428 T w = x % y;
424 if (w >= y-w) z += 1; 429 if (w >= y-w) z += 1;
425 return z; 430 return z;
426 } 431 }
427 else 432 else
428 { 433 {
608 #ifdef HAVE_FAST_INT_OPS 613 #ifdef HAVE_FAST_INT_OPS
609 // The typecasts do nothing, but they are here to prevent an optimizing 614 // The typecasts do nothing, but they are here to prevent an optimizing
610 // compiler from interfering. Also, the signed operations on small types 615 // compiler from interfering. Also, the signed operations on small types
611 // actually return int. 616 // actually return int.
612 T u = static_cast<UT> (x) + static_cast<UT> (y); 617 T u = static_cast<UT> (x) + static_cast<UT> (y);
613 T ux = u ^ x, uy = u ^ y; 618 T ux = u ^ x;
619 T uy = u ^ y;
614 if ((ux & uy) < 0) 620 if ((ux & uy) < 0)
615 { 621 {
616 u = octave_int_base<T>::max_val () + __signbit (~u); 622 u = octave_int_base<T>::max_val () + __signbit (~u);
617 } 623 }
618 return u; 624 return u;
649 #ifdef HAVE_FAST_INT_OPS 655 #ifdef HAVE_FAST_INT_OPS
650 // The typecasts do nothing, but they are here to prevent an optimizing 656 // The typecasts do nothing, but they are here to prevent an optimizing
651 // compiler from interfering. Also, the signed operations on small types 657 // compiler from interfering. Also, the signed operations on small types
652 // actually return int. 658 // actually return int.
653 T u = static_cast<UT> (x) - static_cast<UT> (y); 659 T u = static_cast<UT> (x) - static_cast<UT> (y);
654 T ux = u ^ x, uy = u ^ ~y; 660 T ux = u ^ x;
661 T uy = u ^ ~y;
655 if ((ux & uy) < 0) 662 if ((ux & uy) < 0)
656 { 663 {
657 u = octave_int_base<T>::max_val () + __signbit (~u); 664 u = octave_int_base<T>::max_val () + __signbit (~u);
658 } 665 }
659 return u; 666 return u;
1235 1242
1236 template <class T> 1243 template <class T>
1237 octave_int<T> 1244 octave_int<T>
1238 xmax (const octave_int<T>& x, const octave_int<T>& y) 1245 xmax (const octave_int<T>& x, const octave_int<T>& y)
1239 { 1246 {
1240 const T xv = x.value (), yv = y.value (); 1247 const T xv = x.value ();
1248 const T yv = y.value ();
1241 return octave_int<T> (xv >= yv ? xv : yv); 1249 return octave_int<T> (xv >= yv ? xv : yv);
1242 } 1250 }
1243 1251
1244 template <class T> 1252 template <class T>
1245 octave_int<T> 1253 octave_int<T>
1246 xmin (const octave_int<T>& x, const octave_int<T>& y) 1254 xmin (const octave_int<T>& x, const octave_int<T>& y)
1247 { 1255 {
1248 const T xv = x.value (), yv = y.value (); 1256 const T xv = x.value ();
1257 const T yv = y.value ();
1249 return octave_int<T> (xv <= yv ? xv : yv); 1258 return octave_int<T> (xv <= yv ? xv : yv);
1250 } 1259 }
1251 1260
1252 #endif 1261 #endif