From: Martin Mares Date: Sat, 25 Oct 2008 22:43:51 +0000 (+0200) Subject: Drobnicky. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=4b0dfce7e0526346df2daa268d787bb7e80f4036;p=misc.git Drobnicky. --- diff --git a/Makefile b/Makefile index c806aa2..781c602 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,9 @@ xclipcat: xclipcat.c xclipsend: xclipsend.c prefork: prefork.c +fft: fft.c +fft: LDFLAGS+=-lm + batt: CFLAGS+=$(shell xosd-config --cflags) batt: LDFLAGS+=$(shell xosd-config --libs) diff --git a/fft.c b/fft.c new file mode 100644 index 0000000..973c8a8 --- /dev/null +++ b/fft.c @@ -0,0 +1,53 @@ +#define _GNU_SOURCE +#include +#include +#include + +static int rev(int i, int n) +{ + int j = 0; + n--; + while (n) + { + j = (j << 1) | (i & 1); + i >>= 1; + n >>= 1; + } + return j; +} + +static complex omega(int k, int n) +{ + return cos(2*M_PI*k/n) + I*sin(2*M_PI*k/n); +} + +static void fft(double *x, double *y, int n) +{ + complex omegas[n]; + for (int i=0; i +#include + +int main(void) +{ + double delta = 1e30; + + for (unsigned y=1; y < ~0U/M_PI; y++) + { + unsigned x = y*M_PI + 0.5; + double a = (double)x / y; + double d = fabs(a-M_PI); + if (d < delta) + { + delta = d; + printf("%u/%u = %.20f (%.20f)\n", x, y, a, d); + } + } + + return 0; +}