For example, if I have:
if(x < 2*0.025) { ... }
Does the 2*0.025 get computed every time? Or does a 0.05 get substituted in so that the multiplication operation doesn’t have to run every time?
In other words, is it more efficient to use 0.05 instead of 2*0.025?
Every compiler I know implements constant folding, i.e. calculates constant expressions at compile time, so there is no difference. The standard, however, does not mandate it:
You can explicitly disable this optimization with some compilers. For example,
-frounding-mathdisables constant folding for floating point expressions in gcc.