3 ms·
Here's the generic C++ version (https://gcc.godbolt.org/z/mMln6L https://gcc.godbolt.org/z/mMln6L): constexpr double delta = 1.0e-6; constexpr aut
by jcelerier 8y ago
Here's the generic C++ version (https://gcc.godbolt.org/z/mMln6L https://gcc.godbolt.org/z/mMln6L):
constexpr double delta = 1.0e-6;
constexpr auto deriv = [] (auto f) {
return [=] (double x) {
return (f(x+delta) - f(x)) / delta;
};
};
constexpr auto f¨ = [] (auto f) { return deriv(deriv(f)); };
double res = f¨([] (double x) { return x*x*x; })(2.0);