changeset 8104:fc45357bf50c

fix integer exponentiation with negative exponent
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 12 Sep 2008 15:34:13 -0400
parents 3b2346046d32
children cd0d53b55f79
files liboctave/ChangeLog liboctave/oct-inttypes.h
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Thu Sep 11 17:03:26 2008 -0400
+++ b/liboctave/ChangeLog	Fri Sep 12 15:34:13 2008 -0400
@@ -1,3 +1,8 @@
+2008-09-12  Jaroslav Hajek  <highegg@gmail.com>
+
+	* oct-inttypes.h (pow (const octave_int<T>&, const octave_int<T>&)): 
+	Handle negative exponent correctly.
+
 2008-08-19  David Bateman  <dbateman@free.fr>
 
 	* oct-inttypes.h (template <class T1, class T2> inline T2
--- a/liboctave/oct-inttypes.h	Thu Sep 11 17:03:26 2008 -0400
+++ b/liboctave/oct-inttypes.h	Fri Sep 12 15:34:13 2008 -0400
@@ -481,10 +481,15 @@
   octave_int<T> zero = octave_int<T> (0);
   octave_int<T> one = octave_int<T> (1);
 
-  if (b == zero)
+  if (b == zero || a == one)
     retval = one;
   else if (b < zero)
-    retval = zero;
+    {
+      if (std::numeric_limits<T>::is_signed && a.value () == -1)
+        retval = (b.value () % 2) ? a : one;
+      else
+        retval = zero;
+    }
   else
     {
       octave_int<T> a_val = a;