changeset 11839:3497833c876c release-3-0-x

fix integer exponentiation with negative exponent
author Jaroslav Hajek <highegg@gmail.com>
date Mon, 15 Sep 2008 08:11:18 +0200
parents 8c69552f5906
children b160651f8a21
files liboctave/ChangeLog liboctave/oct-inttypes.h
diffstat 2 files changed, 12 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/ChangeLog	Mon Sep 15 08:10:42 2008 +0200
+++ b/liboctave/ChangeLog	Mon Sep 15 08:11:18 2008 +0200
@@ -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-14  Jaroslav Hajek <highegg@gmail.com>
 
 	Version 3.0.2 released.
--- a/liboctave/oct-inttypes.h	Mon Sep 15 08:10:42 2008 +0200
+++ b/liboctave/oct-inttypes.h	Mon Sep 15 08:11:18 2008 +0200
@@ -348,10 +348,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;