Common numeric computation in C++