/* Copyright 2002 Colin Percival and the University of Oxford Copyright in this software is held by the University of Oxford and Colin Percival. Both the University of Oxford and Colin Percival have agreed that this software may be distributed free of charge and in accordance with the attached licence. The above notwithstanding, in order that the University as a charitable foundation protects its assets for the benefit of its educational and research purposes, the University makes clear that no condition is made or to be implied, nor is any warranty given or to be implied, as to the proper functioning of this work, or that it will be suitable for any particular purpose or for use under any specific conditions. Furthermore, the University disclaims all responsibility for any use which is made of this work. For the terms under which this work may be distributed, please see the adjoining file "LICENSE". */ #ifdef RCSID static const char rcsid[] = "$Id: smpa.c,v 1.8 2002/04/25 06:13:52 cperciva Exp $"; #endif #include "ptypes.h" #include "fft.h" #define MAGIC 6755399441055744. #define MAGIC1 32767.5 #define MAGIC2 MAGIC*65536. #define SCARRY(c,x) {x+=c;c=x+MAGIC2;c-=MAGIC2;x-=c;c/=65536;} #define UCARRY(c,x) {x+=c;c=(x-MAGIC1)+MAGIC2;c-=MAGIC2;x-=c;c/=65536;} #define EVEN(c,x) (c=x+MAGIC*2,c-=MAGIC*2,x==c) void smpa_half(double * A1,uint32 len) { uint32 i; double c; for(i=0;i0;i-=2) { c=*(A1+i); *(A1+i)+=MAGIC; *(A1+i)-=MAGIC; *(A1+i-2)+=(c-*(A1+i))*65536; }; c=0; for(i=0;i0) { for(j=0;j0)||(c2<1)); fft_racw(K1,len/2,1,LUT+len/2); fft_fft(K1,len/2,LUT); } void smpa_mulmod(double * A1,double * B1,double * C1, double * M1,double * M2,double * K1, double * T1,uint32 len,double * LUT) { uint32 i,j; double c,c1,c2; fft_mulpw(A1,B1,C1,len/2); fft_ifft(C1,len/2,LUT); fft_iracw(C1,len/2,1,LUT+len/2); fft_normalize(C1,len/2); c=0; for(j=0;j=0) c-=1; for(j=0;j=0) c-=1; for(j=0;j=0) { for(i=0;i=0)) { smpa_half(T1+len*2,len); if((!EVEN(c,*(T1+len*3)))||(!EVEN(c,*(T1+len*4)))) { for(i=0;i=0); if(!(smpa_positive(A1,len)>=0)) { for(i=0;i0;g--) { for(i=0;i