# HG changeset patch # User Jaroslav Hajek # Date 1225393948 -3600 # Node ID ad5bb02d267aa32d5d762be488562503ba69dde5 # Parent 242756f065f08bc846ae1399b0163721c1acf76b workaround missing std::abs(int64_t) in MSVC diff -r 242756f065f0 -r ad5bb02d267a liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Oct 30 15:08:50 2008 +0100 +++ b/liboctave/ChangeLog Thu Oct 30 20:12:28 2008 +0100 @@ -1,3 +1,10 @@ +2008-10-30 Jaroslav Hajek + + * oct-inttypes.h (octave_int_abs): New function. + (octave_int_arith_base::div): Use octave_int_abs instead of + std::abs. + * oct-inttypes.cc (octave_int_arith_base): Dtto. + 2008-10-28 Jaroslav Hajek * Array-C.cc Array-d.cc Array-f.cc Array-fC.cc Array-i.cc Array-s.cc: diff -r 242756f065f0 -r ad5bb02d267a liboctave/oct-inttypes.cc --- a/liboctave/oct-inttypes.cc Thu Oct 30 15:08:50 2008 +0100 +++ b/liboctave/oct-inttypes.cc Thu Oct 30 20:12:28 2008 +0100 @@ -196,7 +196,7 @@ // (as above) and impose the sign. // FIXME: Can we do something faster if we HAVE_FAST_INT_OPS? - uint64_t usx = std::abs (x), usy = std::abs (y); + uint64_t usx = octave_int_abs (x), usy = octave_int_abs (y); bool positive = (x < 0) == (y < 0); // Get upper words @@ -454,7 +454,7 @@ dblesplit (y, sign, my, e); uint32_t w[4]; sign = (sign != (x.value () < 0)); - umul128 (std::abs (x.value ()), my, w); + umul128 (octave_int_abs (x.value ()), my, w); octave_int64 res = octave_int64::zero; for (short i = 0; i < 4; i++) { diff -r 242756f065f0 -r ad5bb02d267a liboctave/oct-inttypes.h --- a/liboctave/oct-inttypes.h Thu Oct 30 15:08:50 2008 +0100 +++ b/liboctave/oct-inttypes.h Thu Oct 30 20:12:28 2008 +0100 @@ -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 +inline T octave_int_abs (T x) { return x >= 0 ? x : -x; } + // Query for an integer type of certain sizeof, and signedness. template 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); }