octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in n


From: Dan Sebald
Subject: [Octave-bug-tracker] [bug #54572] int64 does not saturate correctly in negative direction
Date: Thu, 30 Aug 2018 15:14:46 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0

Follow-up Comment #41, bug #54572 (project octave):

BTW, since this is C++11 now, I wondered if the following would work since
there is now more support for all integer types

http://www.cplusplus.com/reference/cstdlib/abs/

:


--- a/liboctave/util/oct-inttypes.h
+++ b/liboctave/util/oct-inttypes.h
@@ -552,19 +552,8 @@ public:
       }
     return y;
 #else
-    // -INT_MAX is safe because C++ actually allows only three
implementations
-    // of integers: sign & magnitude, ones complement and twos complement.
-    // The first test will, with modest optimizations, evaluate at compile
-    // time, and maybe eliminate the branch completely.
-    T y;
-    if (octave_int_base<T>::min_val () < -octave_int_base<T>::max_val ()
-        && x == octave_int_base<T>::min_val ())
-      {
-        y = octave_int_base<T>::max_val ();
-      }
-    else
-      y = (x < 0) ? -x : x;
-    return y;
+    // C++11 has int, long int, and long long int versions of abs().
+    return abs (x);


However, this change causes Octave to hang on abs(intX(#)).

Nonetheless, it seems to me that testing


    if (octave_int_base<T>::min_val () < octave_int_base<T>::max_val ()


is redundant regardless of whether it gets optimized out because in 1's-comp,
2's-comp, sign/mag it seems that assigning


  y = octave_int_base<T>::max_val ();


is fine whenever y == min_val().  Not a critical observation.

    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?54572>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]