I know this has been asked a lot, but only for C/C++ and Java. The question is related to the performance benefits of using constant expressions:
When I call a static function with only constants as arguments, is there a way to tell the compiler that it should evaluate the call already at compile time and replace the call by the result?
Example:
const double pi = Math.PI; //works as Math.PI is a constant
const double spi = Math.Sin(Math.PI); //compiler error, because expression must be constant
Are there no directives (better: Attributes) to tell the compiler explicitely that a static method like Math.Sin() is not modifying nor reading any data internally, so that it was technically possible to evaluate the call at compile time?
Oh, and please don't answer like "just do const double spi = 0
" :), because my example is just a simplified version of the problem I have: Improving code maintainability while keeping maximum performance.
Thanks for any help - it is really appreciated!