Block-Structured AMR Software Framework
AMReX_REAL.H
Go to the documentation of this file.
1 #ifndef AMREX_REAL_H_
2 #define AMREX_REAL_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_Extension.H>
6 
7 #ifdef BL_USE_FLOAT
8 # undef BL_USE_DOUBLE
9 # undef BL_USE_FLOAT
10 /*
11  The macro BL_USE_FLOAT indicates that C++ floating-point calculations should
12  use "float" variables and Fortran floating-point calculations should use
13  "real*4" variables. One of BL_USE_FLOAT or BL_USE_DOUBLE must always be
14  defined when compiling and using AMReX.
15 */
16 # define BL_USE_FLOAT 1
17 #else
18 # undef BL_USE_FLOAT
19 # undef BL_USE_DOUBLE
20 /*
21  The macro BL_USE_DOUBLE indicates that C++ floating-point calculations
22  should use "double" variables and Fortran floating-point calculations
23  should use "real*8" variables. One of BL_USE_FLOAT or BL_USE_DOUBLE must
24  always be defined when compiling and using AMReX.
25 */
26 # define BL_USE_DOUBLE 1
27 #endif
28 
29 #if !defined(BL_LANG_FORT)
30 #ifdef __cplusplus
31 #include <cfloat>
32 #else
33 #include <float.h>
34 #endif
35 
36 /*
37  Real is a typedef specifying the precision of the floating-point
38  calculations in C++ code. It will be either float or double
39  depending upon which of the macros BL_USE_FLOAT or
40  BL_USE_DOUBLE, respectively, is defined during compilations. For
41  portability, you should write floating-point code in terms of this
42  typedef, instead of using float or double directly.
43 
44  Note that exactly one of these macros must be defined
45  when compiling any module that uses floating-point.
46 */
47 
48 #ifdef BL_USE_FLOAT
49 typedef float amrex_real; // NOLINT(modernize-use-using)
50 // We need to define these to get around a CUDA 9.2 bug that breaks std::numeric_limits
51 #define AMREX_REAL_MIN FLT_MIN
52 #define AMREX_REAL_MAX FLT_MAX
53 #define AMREX_REAL_LOWEST (-FLT_MAX)
54 #else
55 typedef double amrex_real; // NOLINT(modernize-use-using)
56 #define AMREX_REAL_MIN DBL_MIN
57 #define AMREX_REAL_MAX DBL_MAX
58 #define AMREX_REAL_LOWEST (-DBL_MAX)
59 #endif
60 
61 #ifdef AMREX_SINGLE_PRECISION_PARTICLES
62 typedef float amrex_particle_real; // NOLINT(modernize-use-using)
63 #else
64 typedef double amrex_particle_real; // NOLINT(modernize-use-using)
65 #endif
66 
67 #ifdef __cplusplus
68 namespace amrex {
76  using Real = amrex_real;
77 
85  using ParticleReal = amrex_particle_real;
86 
91 inline namespace literals {
92 
102  constexpr Real
103  operator"" _rt( long double x )
104  {
105  return Real( x );
106  }
107 
108  constexpr Real
109  operator"" _rt( unsigned long long int x )
110  {
111  return Real( x );
112  }
113 
114  constexpr ParticleReal
115  operator"" _prt( long double x )
116  {
117  return ParticleReal( x );
118  }
119 
120  constexpr ParticleReal
121  operator"" _prt( unsigned long long int x )
122  {
123  return ParticleReal( x );
124  }
126 } // namespace literals
127 } // namespace amrex
128 #endif
129 
130 #endif /* !BL_LANG_FORT */
131 
132 #endif /*BL_REAL_H*/
double amrex_real
Definition: AMReX_REAL.H:55
double amrex_particle_real
Definition: AMReX_REAL.H:64
Definition: AMReX_Amr.cpp:49