Mercurial > hg > octave-nkf
diff liboctave/oct-inttypes.h @ 11586:12df7854fa7c
strip trailing whitespace from source files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 20 Jan 2011 17:24:59 -0500 |
parents | fd0a3ac60b0e |
children | 15eefbd9d4e8 |
line wrap: on
line diff
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -51,7 +51,7 @@ { public: static const bool registered = false; - typedef void type; // Void shall result in a compile-time error if we + typedef void type; // Void shall result in a compile-time error if we // attempt to use it in computations. }; @@ -76,7 +76,7 @@ // Rationale: Comparators have a single static method, rel(), that returns the // result of the binary relation. They also have two static boolean fields: -// ltval, gtval determine the value of x OP y if x < y, x > y, respectively. +// ltval, gtval determine the value of x OP y if x < y, x > y, respectively. #define REGISTER_OCTAVE_CMP_OP(NM,OP) \ class NM \ { \ @@ -109,14 +109,14 @@ class prom { // Promote to int? - static const bool pint = (sizeof (T1) < sizeof (int) + static const bool pint = (sizeof (T1) < sizeof (int) && sizeof (T2) < sizeof (int)); static const bool t1sig = std::numeric_limits<T1>::is_signed; static const bool t2sig = std::numeric_limits<T2>::is_signed; - static const bool psig = + static const bool psig = (pint || (sizeof (T2) > sizeof (T1) && t2sig) || t1sig); static const int psize = - (pint ? sizeof (int) : (sizeof (T2) > sizeof (T1) + (pint ? sizeof (int) : (sizeof (T2) > sizeof (T1) ? sizeof (T2) : sizeof (T1))); public: typedef typename query_integer_type<psize, psig>::type type; @@ -130,13 +130,13 @@ typedef typename query_integer_type<size, false>::type utype; typedef typename query_integer_type<size, true>::type stype; public: - static bool op (utype x, utype y) + static bool op (utype x, utype y) { return xop::op (x, y); } - static bool op (stype x, stype y) + static bool op (stype x, stype y) { return xop::op (x, y); } - static bool op (stype x, utype y) + static bool op (stype x, utype y) { return (x < 0) ? xop::ltval : xop::op (static_cast<utype> (x), y); } - static bool op (utype x, stype y) + static bool op (utype x, stype y) { return (y < 0) ? xop::gtval : xop::op (x, static_cast<utype> (y)); } }; @@ -157,10 +157,10 @@ { typedef typename prom<T1, T2>::type PT1; typedef typename prom<T2, T1>::type PT2; - return uiop<xop, sizeof (PT1)>::op (static_cast<PT1> (x), + return uiop<xop, sizeof (PT1)>::op (static_cast<PT1> (x), static_cast<PT2> (y)); } - + public: // Mixed comparisons @@ -185,7 +185,7 @@ return xop::op (static_cast<long double> (x), \ static_cast<long double> (y)); \ } -#else +#else // ... otherwise, use external handlers // FIXME: We could declare directly the mop methods as external, @@ -211,7 +211,7 @@ }; // Base integer class. No data, just conversion methods and exception flags. -template <class T> +template <class T> class octave_int_base { protected: @@ -223,17 +223,17 @@ // Convert integer value. template <class S> - static T + static T truncate_int (const S& value) - { + { // An exhaustive test whether the max and/or min check can be omitted. static const bool t_is_signed = std::numeric_limits<T>::is_signed; static const bool s_is_signed = std::numeric_limits<S>::is_signed; static const int t_size = sizeof (T), s_size = sizeof (S); - static const bool omit_chk_min = + static const bool omit_chk_min = (! s_is_signed || (t_is_signed && t_size >= s_size)); - static const bool omit_chk_max = - (t_size > s_size || (t_size == s_size + static const bool omit_chk_max = + (t_size > s_size || (t_size == s_size && (! t_is_signed || s_is_signed))); // If the check can be omitted, substitute constant false relation. typedef octave_int_cmp_op::cf cf; @@ -258,23 +258,23 @@ private: - // Computes a real-valued threshold for a max/min check. + // Computes a real-valued threshold for a max/min check. template <class S> - static S + static S compute_threshold (S val, T orig_val) - { + { val = xround (val); // Fool optimizations (maybe redundant) // If val is even, but orig_val is odd, we're one unit off. if (orig_val % 2 && val / 2 == xround (val / 2)) // FIXME -- is this always correct? - val *= (static_cast<S>(1) - (std::numeric_limits<S>::epsilon () / 2)); + val *= (static_cast<S>(1) - (std::numeric_limits<S>::epsilon () / 2)); return val; } - + public: // Convert a real number (check NaN and non-int). template <class S> - static T + static T convert_real (const S& value) { // Compute proper thresholds. @@ -337,7 +337,7 @@ // the overflow behaviour for unsigned integers is guaranteed by C/C++, // so the following should always work. - static T + static T add (T x, T y) { T u = x + y; @@ -348,7 +348,7 @@ return u; } - static T + static T sub (T x, T y) { T u = x - y; @@ -360,19 +360,19 @@ } // Multiplication is done using promotion to wider integer type. If there is - // no suitable promotion type, this operation *MUST* be specialized. - static T + // no suitable promotion type, this operation *MUST* be specialized. + static T mul (T x, T y) { // Promotion type for multiplication (if exists). typedef typename query_integer_type<2*sizeof (T), false>::type mptype; - return truncate_int (static_cast<mptype> (x) + return truncate_int (static_cast<mptype> (x) * static_cast<mptype> (y)); } // Division with rounding to nearest. Note that / and % are probably // computed by a single instruction. - static T + static T div (T x, T y) { if (y != 0) @@ -419,7 +419,7 @@ #else // Special handler for 64-bit integer multiply. template <> -OCTAVE_API uint64_t +OCTAVE_API uint64_t octave_int_arith_base<uint64_t, false>::mul (uint64_t, uint64_t); #endif @@ -440,7 +440,7 @@ // HAVE_FAST_INT_OPS is defined, bit tricks and wraparound arithmetics are used // to avoid conditional jumps as much as possible, thus being friendly to modern // pipeline processor architectures. -// Otherwise, we fall back to a bullet-proof code that only uses assumptions +// Otherwise, we fall back to a bullet-proof code that only uses assumptions // guaranteed by the standard. template <class T> @@ -452,12 +452,12 @@ // Returns 1 for negative number, 0 otherwise. static T - signbit (T x) - { + signbit (T x) + { #ifdef HAVE_FAST_INT_OPS return static_cast<UT> (x) >> std::numeric_limits<T>::digits; #else - return (x < 0) ? 1 : 0; + return (x < 0) ? 1 : 0; #endif } @@ -470,7 +470,7 @@ // discard the following test. T m = x >> std::numeric_limits<T>::digits; T y = (x ^ m) - m; - if (y < 0) + if (y < 0) { y = octave_int_base<T>::max_val (); } @@ -493,10 +493,10 @@ } static T - signum (T x) - { + signum (T x) + { // With modest optimizations, this will compile without a jump. - return ((x > 0) ? 1 : 0) - signbit (x); + return ((x > 0) ? 1 : 0) - signbit (x); } // FIXME -- we do not have an authority what signed shifts should @@ -533,7 +533,7 @@ #endif } - static T + static T add (T x, T y) { #ifdef HAVE_FAST_INT_OPS @@ -541,8 +541,8 @@ // compiler from interfering. Also, the signed operations on small types // actually return int. T u = static_cast<UT> (x) + static_cast<UT> (y); - T ux = u ^ x, uy = u ^ y; - if ((ux & uy) < 0) + T ux = u ^ x, uy = u ^ y; + if ((ux & uy) < 0) { u = octave_int_base<T>::max_val () + signbit (~u); } @@ -574,7 +574,7 @@ } // This is very similar to addition. - static T + static T sub (T x, T y) { #ifdef HAVE_FAST_INT_OPS @@ -582,8 +582,8 @@ // compiler from interfering. Also, the signed operations on small types // actually return int. T u = static_cast<UT> (x) - static_cast<UT> (y); - T ux = u ^ x, uy = u ^ ~y; - if ((ux & uy) < 0) + T ux = u ^ x, uy = u ^ ~y; + if ((ux & uy) < 0) { u = octave_int_base<T>::max_val () + signbit (~u); } @@ -615,18 +615,18 @@ } // Multiplication is done using promotion to wider integer type. If there is - // no suitable promotion type, this operation *MUST* be specialized. - static T + // no suitable promotion type, this operation *MUST* be specialized. + static T mul (T x, T y) { // Promotion type for multiplication (if exists). typedef typename query_integer_type<2*sizeof (T), true>::type mptype; - return truncate_int (static_cast<mptype> (x) + return truncate_int (static_cast<mptype> (x) * static_cast<mptype> (y)); } // Division. - static T + static T div (T x, T y) { T z; @@ -650,7 +650,7 @@ { z = x / y; T w = -octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! - if (w <= y - w) + if (w <= y - w) z -= 1 - (signbit (x) << 1); } } @@ -662,7 +662,7 @@ // overflow, but std::abs (x) can! T w = octave_int_abs (x % y); - if (w >= y - w) + if (w >= y - w) z += 1 - (signbit (x) << 1); } return z; @@ -713,13 +713,13 @@ #else // Special handler for 64-bit integer multiply. template <> -OCTAVE_API int64_t +OCTAVE_API int64_t octave_int_arith_base<int64_t, true>::mul (int64_t, int64_t); #endif // This class simply selects the proper arithmetics. template<class T> -class octave_int_arith +class octave_int_arith : public octave_int_arith_base<T, std::numeric_limits<T>::is_signed> {}; @@ -734,12 +734,12 @@ octave_int (T i) : ival (i) { } - octave_int (double d) : ival (octave_int_base<T>::convert_real (d)) { } + octave_int (double d) : ival (octave_int_base<T>::convert_real (d)) { } - octave_int (float d) : ival (octave_int_base<T>::convert_real (d)) { } + octave_int (float d) : ival (octave_int_base<T>::convert_real (d)) { } #ifdef OCTAVE_INT_USE_LONG_DOUBLE - octave_int (long double d) : ival (octave_int_base<T>::convert_real (d)) { } + octave_int (long double d) : ival (octave_int_base<T>::convert_real (d)) { } #endif octave_int (bool b) : ival (b) { } @@ -831,7 +831,7 @@ // The following are provided for convenience. static const octave_int zero, one; - + // Unsafe. This function exists to support the MEX interface. // You should not use it anywhere else. void *mex_get_data (void) const { return const_cast<T *> (&ival); } @@ -1074,7 +1074,7 @@ xmax (const octave_int<T>& x, const octave_int<T>& y) { const T xv = x.value (), yv = y.value (); - return octave_int<T> (xv >= yv ? xv : yv); + return octave_int<T> (xv >= yv ? xv : yv); } template <class T> @@ -1082,7 +1082,7 @@ xmin (const octave_int<T>& x, const octave_int<T>& y) { const T xv = x.value (), yv = y.value (); - return octave_int<T> (xv <= yv ? xv : yv); + return octave_int<T> (xv <= yv ? xv : yv); } #endif