Instead of using #defined constants, we can use static const variables that lets the system compute what the values would be. This puts to bed any debate around accuracy and rounding and if we added enough significant figures into the definition. What is one-third anyway? Just let the system decide...
(gdb) p (double) 1/3
$1 = 0.33333333333333331
Ideally we would want to use constexpr instead of const, because constexpr is evaluated at compile time. But constexpr is only available in C++. const is evaluated at the beginning of runtime. What I don't know is how often does a program start up in the field? If it is very frequent then maybe this is not a good idea.
Instead of using
#define
d constants, we can usestatic const
variables that lets the system compute what the values would be. This puts to bed any debate around accuracy and rounding and if we added enough significant figures into the definition. What is one-third anyway? Just let the system decide...Ideally we would want to use
constexpr
instead ofconst
, becauseconstexpr
is evaluated at compile time. Butconstexpr
is only available in C++.const
is evaluated at the beginning of runtime. What I don't know is how often does a program start up in the field? If it is very frequent then maybe this is not a good idea.