Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
precision.hpp
Go to the documentation of this file.
1 
9 #pragma once
10 
11 #ifndef PRECISION
12 #define PRECISION 2 // default double precision
13 #endif
14 
15 #if PRECISION == 1
16 typedef float FTYPE_t;
17 #define MAKE_FFTW_NAME(FUNC_NAME) fftwf_ ## FUNC_NAME
18 #elif PRECISION == 2
19 typedef double FTYPE_t;
20 #define MAKE_FFTW_NAME(FUNC_NAME) fftw_ ## FUNC_NAME
21 #elif PRECISION == 3
22 typedef long double FTYPE_t;
23 #define MAKE_FFTW_NAME(FUNC_NAME) fftwl_ ## FUNC_NAME
24 #endif
25 
26 #define FFTW_PLAN_TYPE MAKE_FFTW_NAME(plan)
27 #define FFTW_DEST_PLAN MAKE_FFTW_NAME(destroy_plan)
28 #define FFTW_COMPLEX_TYPE MAKE_FFTW_NAME(complex)
29 #define FFTW_PLAN_R2C MAKE_FFTW_NAME(plan_dft_r2c_3d)
30 #define FFTW_PLAN_C2R MAKE_FFTW_NAME(plan_dft_c2r_3d)
31 #define FFTW_PLAN_OMP MAKE_FFTW_NAME(plan_with_nthreads)
32 #define FFTW_PLAN_OMP_INIT MAKE_FFTW_NAME(init_threads)
33 #define FFTW_PLAN_OMP_CLEAN MAKE_FFTW_NAME(cleanup_threads)
34 #define FFTW_EXEC_R2C MAKE_FFTW_NAME(execute_dft_r2c)
35 #define FFTW_EXEC_C2R MAKE_FFTW_NAME(execute_dft_c2r)
36 
37 constexpr FTYPE_t PI = FTYPE_t(3.14159265358979323846); // 20 digits
38 
39 inline float pow(float base, unsigned long int exp)
40 {
41  float result = 1.f;
42  while (exp)
43  {
44  if (exp & 1)
45  result *= base;
46  exp >>= 1;
47  base *= base;
48  }
49  return result;
50 }
51 
52 template <typename T> inline T pow2(T base){ return base*base; } //< most often used
T pow2(T base)
Definition: precision.hpp:52
constexpr double PI
Definition: precision.hpp:37
float pow(float base, unsigned long int exp)
Definition: precision.hpp:39