void down(int i) { int vetsi, j; while(1){ j = i << 1; if(j > sn) return; if(j+1 > sn) vetsi=1; else vetsi = isGE(j,j+1); if(vetsi) if isGE(i,j) return; else { swapx(j,i); i=j; } else if(isGE(i,j+1)) return; else { swapx(j+1,i); i=j+1; }
void fft1x(Complex a[], int n, int iter, int flag) { int i, it, j, j1, j2, k, xp, xp2; double arg, sign, w; Complex d1, d2, *p, *q, t, ww; if(n < 2) { fprintf(stderr, "Error : n < 2 in fft1()\n"); return; } if(iter <= 0) { iter = 0; i = n; while((i /= 2) != 0) iter++; } j = 1; for(i = 0; i < iter; i++) j *= 2; if(n != j) { fprintf(stderr, "Error : n != 2 ^ k in fft1()\n"); return; } sign = (flag == 1)? 1.: -1.; xp2 = n; for(it = 0; it < iter; it++) { xp = xp2; xp2 = xp / 2; w = M_PI / xp2; for(k = 0; k < xp2; k++) { arg = k * w; ww = tocomplex(cos(arg), sign * sin(arg)); i = k - xp; for(j = xp, p = a + i + xp, q = a + i + xp + xp2; j <= n; j += xp, p += xp, q += xp) { t = csub(*p, *q); *p = cadd(*p, *q); *q = cmul(t, ww); } } } j1 = n / 2; j2 = n - 1; j = 1; for(i = 1, p = a; i <= j2; i++, p++) { if(i < j) swapx(p, a + j - 1); k = j1; while(k < j) { j -= k; k /= 2; } j += k; } if(flag == 0) return; w = n; for(i = 0, p = a; i < n; i++, p++) *p = cdiv1(*p, w); return; }