| Ilya Zakharevich on Thu, 17 Jan 2002 04:47:52 -0500 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [PATCH CVS] 2-adic shift |
On Sat, Sep 29, 2001 at 11:51:05AM -0400, Ilya Zakharevich wrote:
> This adds a flag to shift() which changes the behaviour for
> right-shift of negative numbers: instead of preserving-but-ignoring the
> sign, the shift is performed as if modulo big power of 2.
>
> This enables compatibility of shift() with 2-complement semantic of
> negative numbers.
Well, it turned out that this worked wrongly for positive numbers. A
more complete test suite and a patch follow.
Sorry,
Ilya
shiftr(x,n)=if(x<0&&n<0,shift(x+1,n)-1,shift(x,n))
{
test(lim,s1=1,s2=1) =
for(s=0,lim, print1(".");
forvec(X = [[0,lim],[0,lim]],
n=2^X[2]-2^X[1];
r=shift(s1*n,s2*s,1);
r1=shiftr(s1*n,s2*s);
if(r==r1,,
print("shift("s1*n","s2*s",1) = "r" != "r1)
),
1))
}
test(90)
test(90,-1,1)
test(90,1,-1)
test(90,-1,-1)
--- ./src/kernel/none/mp.c-pre Thu Jan 10 08:25:28 2002
+++ ./src/kernel/none/mp.c Thu Jan 17 01:40:12 2002
@@ -296,6 +296,8 @@ shifti3(GEN x, long n, long flag)
{
long lyorig;
+ if (s > 0)
+ flag = 0;
n = -n;
ly = lyorig = lx - (n>>TWOPOTBITS_IN_LONG);
if (ly<3)