Skip to content

Commit a6f3a00

Browse files
mgoodson-cvdrdbisme
authored andcommitted
Make constants constexpr.
Make the constants `constexpr` rather than just `const`. This should improve performance by setting the values at compile-time rather than run-time. See #250. Closes #250.
1 parent 87fa5db commit a6f3a00

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/general/Constants.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,22 @@ namespace Mutation {
3838

3939
/// \defgroup math Mathematical constants
4040
/// @{
41-
const double PI = 4.0 * std::atan(1.0); //!< \f$\pi\f$
42-
const double TWOPI = 2.0 * PI; //!< \f$2\pi\f$
43-
const double SQRT2 = std::sqrt(2.0); //!< \f$\sqrt{2}\f$
41+
constexpr double PI = 3.14159265358979323846; //!< \f$\pi\f$
42+
constexpr double TWOPI = 2.0 * PI; //!< \f$2\pi\f$
43+
constexpr double SQRT2 = 1.41421356237309504880; //!< \f$\sqrt{2}\f$
4444
/// @}
4545

4646
/// \defgroup physical Physical constants (all units in SI)
4747
/// @{
48-
const double NA = 6.0221415E23; //!< Avagadro's number (molecule/mol)
49-
const double KB = 1.3806503E-23; //!< Boltzmann's constant (J/molecule-K)
50-
const double RU = NA * KB; //!< Universal Gas constant (J/mole-K)
51-
const double HP = 6.626068E-34; //!< Planck's constant (J-s)
52-
const double MU0 = PI * 4.0E-7; //!< Magnetic constant (H/m)
53-
const double C0 = 299792458.0; //!< Speed of light in vacuum (m/s)
54-
const double EPS0 = 1.0/(MU0*C0*C0); //!< Vacuum permittivity (F/m)
55-
const double QE = 1.602176565E-19; //!< Elementary positive charge (C)
56-
const double ONEATM = 101325.0; //!< 1 atm in Pa
48+
constexpr double NA = 6.0221415E23; //!< Avogadro's number (molecule/mol)
49+
constexpr double KB = 1.3806503E-23; //!< Boltzmann's constant (J/molecule-K)
50+
constexpr double RU = NA * KB; //!< Universal Gas constant (J/mole-K)
51+
constexpr double HP = 6.626068E-34; //!< Planck's constant (J-s)
52+
constexpr double MU0 = PI * 4.0E-7; //!< Magnetic constant (H/m)
53+
constexpr double C0 = 299792458.0; //!< Speed of light in vacuum (m/s)
54+
constexpr double EPS0 = 1.0/(MU0*C0*C0); //!< Vacuum permittivity (F/m)
55+
constexpr double QE = 1.602176565E-19; //!< Elementary positive charge (C)
56+
constexpr double ONEATM = 101325.0; //!< 1 atm in Pa
5757
/// @}
5858

5959
/// @}

0 commit comments

Comments
 (0)