If you repeat the same thing over and over again, you should think of yourself as a βfunction!β:
double invsqrt(const double x) { return 1.0 / std::sqrt(x); }
Now the code is more self-documenting: people do not need to output 1.0 / std::sqrt(x) - this is the inverse square root, they read it. In addition, you can now connect to any specific implementation, and each call site automatically uses the updated definition.
To answer your question, no, there is no C (++) function for it, but now that you have created it, if you find that your performance is too insufficient, you can replace your own definition.
source share