diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1726dd4d147771c0155a8fe9150b0a32d4a20c6f --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +CC=g++ +LFLAGS=-lm +EXEC= r_gaussian \ + r_monte_carlo \ + r_PM + +all: $(EXEC) + +r_%: %.cpp + $(CC) $(LFLAGS) $< -o $@ diff --git a/fcts.h b/fcts.h index 2ed4d3fe10142c89749be77ae86e5f996ffb00a5..b8ffc16c672ebdf2efe25ffd211123bc57b17a28 100644 --- a/fcts.h +++ b/fcts.h @@ -20,8 +20,8 @@ long uniform() { return seed ; } void gaussian(double U0, double U1, double *res){ - res[0] = sqrt(-2 * log(U0));// * cos(2 * M_PI * U1); - res[1] = sqrt(-2 * log(U0));// * sin(2 * M_PI * U1); + res[0] = sqrt(-2 * log(U0)) * cos(2 * M_PI * U1); + res[1] = sqrt(-2 * log(U0)) * sin(2 * M_PI * U1); } void store_freqs(int freqs[], int nCuts){ diff --git a/gaussian.cpp b/gaussian.cpp index efe5a4ab33affcf26b872f25f0c062d7bc8cb2d5..35d5ed8623a556310377e28149dcc1ac5780afe3 100644 --- a/gaussian.cpp +++ b/gaussian.cpp @@ -22,12 +22,12 @@ int main(int argc, char **argv) { freqs[i] = 0; for (int i = 0; i < nRNG; i++){ - U0 = uniform(); - U1 = uniform(); + U0 = uniform()/(double)0x7FFFFFFF; + U1 = uniform()/(double)0x7FFFFFFF; gaussian(U0, U1, Y); - printf("%lf, %lf\n", Y[0], sqrt(2 * log(U1)) * cos(2 * M_PI * U1)); + printf("%lf, %lf\n", Y[0], Y[1]); } - // store_res_double(Y) + store_res_double(Y) rescsv.close(); return 0; }