Mercurial > hg > octave-lyh
diff liboctave/oct-inttypes.h @ 8293:ad5bb02d267a
workaround missing std::abs(int64_t) in MSVC
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Thu, 30 Oct 2008 20:12:28 +0100 |
parents | cf59d542f33e |
children | c374691576f6 |
line wrap: on
line diff
--- a/liboctave/oct-inttypes.h +++ b/liboctave/oct-inttypes.h @@ -39,6 +39,12 @@ inline long double xround (long double x) { return roundl (x); } #endif +// FIXME: we define this by our own because some compilers, such as MSVC, +// do not provide std::abs (int64_t) and std::abs (uint64_t). In the future, +// it should go away in favor of std::abs. +template <class T> +inline T octave_int_abs (T x) { return x >= 0 ? x : -x; } + // Query for an integer type of certain sizeof, and signedness. template<int qsize, bool qsigned> struct query_integer_type @@ -694,7 +700,7 @@ else { z = x / y; - T w = -std::abs (x % y); // Can't overflow, but std::abs (x) can! + T w = -octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! if (w <= y - w) z -= 1 - (signbit (x) << 1); } @@ -702,7 +708,8 @@ else { z = x / y; - T w = std::abs (x % y); // Can't overflow, but std::abs (x) can! + // FIXME: this is a workaround due to MSVC's absence of std::abs (int64_t). + T w = octave_int_abs (x % y); // Can't overflow, but std::abs (x) can! if (w >= y - w) z += 1 - (signbit (x) << 1); }