Should I pay attention on const modifier working with primitive types? Which one is more syntactically correct and why?
First version:
f
I would say that the third version is most "correct".
You tell the compiler that the arguments are const, which is correct since you don't modify them. This can help the compiler with optimizations for passing the arguments, as well as in the calculations.
And the return type is not const since the caller may want to modify the returned value. If the caller doesn't want to modify the returned value, then it's up to the caller to assign it to a const variable.
I would also have added const to the function declaration, since the function does not modify anything in the object:
float Foo::bar(const float a, const float b) const