在编译时计算常量库函数
我想在我的函数中使用玻尔兹曼常数。我使用以下代码来声明 Boltzmann 常量
const double boltzmann_constant = 1.3806503 * pow (10,-23);
这会在编译时本身计算吗?如果现在,我应该如何确保它确实在编译时计算?还有其他方法来声明常量吗?
I want to use boltzmann constant in my functions. I am using the following code to 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
pow()
函数不太可能在编译时计算。然而,所请求的操作可以直接用科学记数法表示,科学记数法是浮点数的标准方面:对于更复杂的情况,例如
sin(M_PI / 3)
,编写一个程序来计算并显示这些值,以便将它们编辑到程序中。如果你这样做,请帮大家一个忙,并添加一条注释来解释常数是什么: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: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: