不要不断前pressions数学函数得到$ P $在编译时对如何计算? [英] Do math functions of constant expressions get pre-calculated at compile time?
问题描述
我倾向于使用恒定的前pressions的数学函数的舒适性和连贯性(即日志(X)/日志(2)
而不是日志(X)/0.3 ...
)。由于这些功能实际上不是语言本身的一部分,也不是他们在文件math.h
(仅申报)规定,将不断得到那些在pcalculated $ P $编译的时候,还是会在运行时被浪费计算?
I tend to use math functions of constant expressions for convinience and coherence (i.e log(x)/log(2)
instead of log(x)/0.3...
). Since these functions aren't actually a part of the language itself, neither are they defined in math.h
(only declared), will the constant ones get precalculated at compile time, or will they be wastefully calculated at runtime?
推荐答案
一些编译器在编译时将对其进行评估,但是这种行为并不保证(而且这样做也可能会导致问题)。你需要检查你的编译器,看看它做什么。
Some compilers will evaluate them at compile time, but this behavior is not guaranteed (and doing so may also cause problems). You'll need to check your compiler and see what it does.
请注意,在许多系统上,日志(2)
可从<$ C $宏 M_LN2
C>&LT;文件math.h方式&gt;
Note that on many systems, log(2)
is available from the macro M_LN2
in <math.h>
.
这篇关于不要不断前pressions数学函数得到$ P $在编译时对如何计算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!