Karim Belabas on Thu, 17 Dec 1998 18:50:55 +0100 (MET)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

2.0.13 - patch 1


This patch corrects a nasty hidden bug in Karatsuba integer multiplication
(could occur when both operands have more than 155 digits and one of them
contains many consecutive 0 words...)

   Karim.

*** src/kernel/none/mp.c.orig   Tue Dec 15 16:30:00 1998
--- src/kernel/none/mp.c        Thu Dec 17 17:12:20 1998
***************
*** 1833,1853 ****
    GEN z,z0,y0,yd, zd = (GEN)avma;
    long a,lz,ly = lgefint(y);
  
!   (void)new_chunk(d);
!   if (ly!=2) /* y != 0 */
    {
!     yd = y+ly; y0 = yd-d;
!     while (yd > y0) *--zd = *--yd; /* copy last d words of y */
    }
!   a = ly-2 - d;
!   if (a <= 0)
    {
!     if (a) { z0 = (GEN)avma; while (zd >= z0) *--zd = 0; }
      z = icopy(x);
    }
!   else
!     z = addiispec(x+2, y+2, lgefint(x)-2, a);
!   lz=lgefint(z)+d;
    z[1] = evalsigne(1) | evallgefint(lz);
    z[0] = evaltyp(t_INT) | evallg(lz); return z;
  }
--- 1833,1856 ----
    GEN z,z0,y0,yd, zd = (GEN)avma;
    long a,lz,ly = lgefint(y);
  
!   z0 = new_chunk(d);
!   a = ly-2; yd = y+ly; 
!   if (a >= d)
    {
!     y0 = yd-d; while (yd > y0) *--zd = *--yd; /* copy last d words of y */
!     a -= d;
!     if (a)
!       z = addiispec(x+2, y+2, lgefint(x)-2, a);
!     else
!       z = icopy(x);
    }
!   else
    {
!     y0 = yd-a; while (yd > y0) *--zd = *--yd; /* copy last a words of y */
!     while (zd >= z0) *--zd = 0;    /* complete with 0s */
      z = icopy(x);
    }
!   lz = lgefint(z)+d;
    z[1] = evalsigne(1) | evallgefint(lz);
    z[0] = evaltyp(t_INT) | evallg(lz); return z;
  }
--
Karim Belabas                    email: Karim.Belabas@math.u-psud.fr
Dep. de Mathematiques, Bat. 425
Universite Paris-Sud             Tel: (33 1) 01 69 15 57 48
F-91405 Orsay (France)           Fax: (33 1) 01 69 15 60 19
--
PARI/GP Home Page: http://pari.home.ml.org