| Bill Allombert on Thu, 25 Sep 2003 17:38:42 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| sqrtint(-N) is broken |
Hello PARI-dev,
It's look like sqrtint(-N) is broken.
? sqrtint(-18891990361510463883)
%1 = -180277404801467*I
? sqrtint(18891990361510463883)
%2 = 4346491730
The GMP kernel does not have this bug.
I would prefer sqrtint to fail on negative integers by the way. The
current behavior just hide wrong input for a not really meaningful
output, like
? sqrtint(-3)
%1 = I
Here a not very good patch.
--- ../src/pari/src/kernel/none/mp.c Fri Jul 4 23:26:55 2003
+++ src/kernel/none/mp.c Tue Sep 23 17:56:50 2003
@@ -2221,7 +2221,7 @@
x = shifti(x, (l - s)*(BITS_IN_LONG/2));
do
{ /* one or two iterations should do the trick */
- z = shifti(addii(x,divii(a,x)), -1);
+ z = shifti(addii(x,divii(absi(a),x)), -1);
y = x; x = z;
}
while (cmpii(x,y) < 0);
Cheers,
Bill.