I'm writing a C function float foo(float x) which manipulates a floating-point value. It so happens, that I can guarantee the function will only ever be called with finite values - neither NaN's, nor +inf, nor -inf. Is it possible to "tell" this to the compiler (without actually doing runtime work which ensures it, like comparing, or zeroing bits and such)? For it to be able to optimize the code based on that assumption?
Notes:
- I'm assuming this answer would be compiler-specific, so let's focus on GCC, clang and MSVC.
- I might also be able to guarantee the values are not denormals.
- It would help if your answer could regard other floating-point types:
_Float16/float16_t,double,long double.