开发者

calculating constant library functions at compile time

I want to use boltzmann constant in my functions. I am using the following code to开发者_Go百科 declare the boltzmann constant

const double boltzmann_constant = 1.3806503 * pow (10,-23);

Will this get calculated at the compile time itself? If now, how should i ensure that it does get calculated at compile time? Any other method to declare the constant?


The pow() function is very unlikely to be calculated at compile time. However, the operation requested is directly expressible in scientific notation, a standard aspect of floating point numbers:

const double boltzmann_constant = 1.3806503e-23;

For a more complex situation, like sin(M_PI / 3), it can be useful to write a program to calculate and display such values so they can be edited into a program. If you do this, do everyone a favor and include a comment explaining what the constant is:

const double magic_val = 0.8660254037844385965883; // sin(M_PI / 3);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜