Skip to content

Commit f75f8f6

Browse files
author
jkuipers
committed
made NCOPY point to while-loop instead of memcpy
small changes to make the code of poly multiplication/division a bit cleaner, so that valgrind doesn't complain
1 parent bc382f1 commit f75f8f6

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

sources/declare.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@
6464
if ( *(s)++ == '-' ) sgn ^= 1;}}
6565
#define ParseSignedNumber(x,s) { int sgn; ParseSign(sgn,s)\
6666
ParseNumber(x,s) if ( sgn ) x = -x; }
67-
/*
67+
6868
#define NCOPY(s,t,n) while ( --n >= 0 ) *s++ = *t++;
69-
*/
70-
#define NCOPY(s,t,n) { memcpy(s,t,n*sizeof(WORD)); s+=n; t+=n; n = -1; }
69+
70+
//#define NCOPY(s,t,n) { memcpy(s,t,n*sizeof(WORD)); s+=n; t+=n; n = -1; }
7171
#define NCOPYI(s,t,n) while ( --n >= 0 ) *s++ = *t++;
7272
#define NCOPYB(s,t,n) while ( --n >= 0 ) *s++ = *t++;
7373
#define NCOPYI32(s,t,n) while ( --n >= 0 ) *s++ = *t++;

sources/poly.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,21 +811,22 @@ void poly::mul_univar (const poly &a, const poly &b, poly &c, int var) {
811811
// if both polynomials are modulo p^1, use integer calculus
812812
if (both_mod_small) {
813813
c[ci+1+AN.poly_num_vars] =
814-
((LONG)c[ci+1+AN.poly_num_vars] * nc +
814+
((nc==0 ? 0 : (LONG)c[ci+1+AN.poly_num_vars] * nc) +
815815
(LONG)a[ai+1+AN.poly_num_vars] * a[ai+2+AN.poly_num_vars] *
816816
b[bi+1+AN.poly_num_vars] * b[bi+2+AN.poly_num_vars]) % c.modp;
817817
nc = (c[ci+1+AN.poly_num_vars]==0 ? 0 : 1);
818818
}
819819
else {
820820
// otherwise, use form long calculus
821+
821822
MulLong((UWORD *)&a[ai+1+AN.poly_num_vars], a[ai+a[ai]-1],
822823
(UWORD *)&b[bi+1+AN.poly_num_vars], b[bi+b[bi]-1],
823824
(UWORD *)&t[0], &nt);
824825

825826
AddLong ((UWORD *)&t[0], nt,
826827
(UWORD *)&c[ci+1+AN.poly_num_vars], nc,
827828
(UWORD *)&c[ci+1+AN.poly_num_vars], &nc);
828-
829+
829830
if (c.modp!=0) TakeNormalModulus((UWORD *)&c[ci+1+AN.poly_num_vars], &nc,
830831
modq, nmodq, NOUNPACK);
831832
}
@@ -1339,7 +1340,8 @@ void poly::divmod_univar (const poly &a, const poly &b, poly &q, poly &r, int va
13391340
WORD nt;
13401341
UWORD *s = NumberMalloc("poly::div_univar");
13411342
UWORD *t = NumberMalloc("poly::div_univar");
1342-
1343+
s[0]=0;
1344+
13431345
int bpow = b[2+var];
13441346

13451347
int ai=1, qi=1, ri=1;
@@ -2296,7 +2298,6 @@ int poly::is_dense_univariate () const {
22962298
// returns the simple polynomial (x-a)^b mod p^n with a small
22972299
const poly poly::simple_poly (PHEAD int x, int a, int b, int p, int n) {
22982300

2299-
poly res(BHEAD 1,p,n);
23002301
poly tmp(BHEAD 0,p,n);
23012302

23022303
int idx=1;
@@ -2315,6 +2316,10 @@ const poly poly::simple_poly (PHEAD int x, int a, int b, int p, int n) {
23152316

23162317
tmp[0] = idx; // length
23172318

2319+
if (b == 1) return tmp;
2320+
2321+
poly res(BHEAD 1,p,n);
2322+
23182323
while (b!=0) {
23192324
if (b&1) res*=tmp;
23202325
tmp*=tmp;

0 commit comments

Comments
 (0)