# HG changeset patch # User Jaroslav Hajek # Date 1223469333 -7200 # Node ID ec3a55bd876bfc212580ed8f065b9a6880f9f0f5 # Parent aea271e60434557d06cb6f2a8c331b130f376585 fix integer exponentiation diff --git a/liboctave/oct-inttypes.cc b/liboctave/oct-inttypes.cc --- a/liboctave/oct-inttypes.cc +++ b/liboctave/oct-inttypes.cc @@ -535,7 +535,8 @@ if (b == zero || a == one) retval = one; - else if (b < zero) + // the is_signed check is inserted twice to avoid compiler warnings + else if (std::numeric_limits::is_signed && b < zero) { if (std::numeric_limits::is_signed && a.value () == -1) retval = (b.value () % 2) ? a : one; @@ -574,7 +575,11 @@ template octave_int pow (const octave_int& a, const double& b) -{ return octave_int (pow (a.double_value (), b)); } +{ + return ((b >= 0 && b < std::numeric_limits::digits && b == xround (b)) + ? pow (a, octave_int (static_cast (b))) + : octave_int (pow (a.double_value (), b))); +} template octave_int @@ -584,7 +589,11 @@ template octave_int powf (const octave_int& a, const float& b) -{ return octave_int (pow (a.float_value (), b)); } +{ + return ((b >= 0 && b < std::numeric_limits::digits && b == xround (b)) + ? pow (a, octave_int (static_cast (b))) + : octave_int (pow (a.double_value (), b))); +} #define INSTANTIATE_INTTYPE(T) \ template class OCTAVE_API octave_int; \ @@ -640,6 +649,8 @@ %! warning("on", "Octave:int-convert-overflow"); %! fail("int32(-2**31-0.5)","warning",".*") %! warning(wstate.state, "Octave:int-convert-overflow"); +%!assert((int64(2**62)+1)**1, int64(2**62)+1) +%!assert((int64(2**30)+1)**2, int64(2**60+2**31) + 1) */ /*