On Sun, Sep 26, 2010 at 05:39:41PM +0100, Brian Gough wrote:
> Thanks for the bug report, I agree that should be handled better.
Just been having a play and it looks as though it's because gsl_pow_int
assumes that "-n" will remove the sign when n < 0. This appears not to
be the case for n = 1<<31, where -n is the identity function.
I've changed the function to store the result in an unsigned variable
and the function terminates now.
--
Sam http://samason.me.uk/
--- sys/pow_int.c~ 2010-03-10 10:57:14.000000000 +0000
+++ sys/pow_int.c 2010-09-27 11:45:06.000000000 +0100
@@ -28,20 +28,23 @@
double gsl_pow_int(double x, int n)
{
double value = 1.0;
+ unsigned int un;
if(n < 0) {
x = 1.0/x;
- n = -n;
+ un = -n;
+ } else {
+ un = n;
}
/* repeated squaring method
* returns 0.0^0 = 1.0, so continuous in x
*/
do {
- if(n & 1) value *= x; /* for n odd */
- n >>= 1;
+ if(un & 1) value *= x; /* for n odd */
+ un >>= 1;
x *= x;
- } while (n);
+ } while (un);
return value;
}
_______________________________________________
Bug-gsl mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gsl