From 7e9a3cf5e5b0a4c5d78212aea2f7016d0868be7b Mon Sep 17 00:00:00 2001 From: Hugo TRACHINO <hugo.trachino@pedago-ext.ensiie.fr> Date: Fri, 4 Oct 2019 09:34:57 +0200 Subject: [PATCH] makefile + gaissoa --- Makefile | 10 ++++++++++ fcts.h | 4 ++-- gaussian.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1726dd4 --- /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 2ed4d3f..b8ffc16 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 efe5a4a..35d5ed8 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; } -- GitLab