I think there is a fundamental problem with your understanding of the C ++ language itself. Functions in C ++ are not the same as mathematical functions. So in C ++ you can define a function (which I will now call methods to avoid confusion) to implement a mathematical function:
float f (float x) { return x * x + 4.0f * x + 6.0f;
In C ++, there is no way to do anything using the f method, except to get the value of f (x) for the given x. The mathematical function f (x) can be easily transformed, for example, f '(x), which in the above example is f' (x) = 2x + 4. For this, in C ++ you need to define the df (x) method:
float df (float x) { return 2.0f * x + 4.0f;
you cannot do this:
get_derivative (f(x));
and the get_derivative method converts the f (x) method for you.
In addition, you will need to make sure that when you want to get the derivative of f that you invoke with the df method. If you accidentally called a method for the derivative g, your results would be incorrect.
We can, however, approximate the derivative f (x) for a given x:
float d (float (*f) (float x), x)
but it is very unstable and rather inaccurate.
Now, in C ++, you can create a class that will help here:
class Function { public: virtual float f (float x) = 0;
and create our specific math function:
class ExampleFunction : Function { float f (float x) { return x * x + 4.0f * x + 6.0f; } // f(x) = x^2 + 4x + 6 float df (float x) { return 2.0f * x + 4.0f; } // f'(x) = 2x + 4 float ddf (float x) { return 2.0f; } // f''(x) = 2 };
and pass an instance of this class to the serial extension program:
float Series (Function &f, float x) { return ff (x) + f.df (x) + f.ddf (x);
but we still need to create a method for the derived function, but at least we won't accidentally make a mistake.
Now, according to others, games tend to prefer speed, so the math is simplified: interpolation, pre-computed tables, etc.