#include #include "utils.hpp" #include "compile_time_derivative.hpp" using std::cout; using std::endl; // x is the unknown expression::type> const x; // A transform works as a functor Derivative const derivative; template T fct(const T & x) { return (3)*x*x + (2)*x - (3) + (1)/x; } template T dfct(const T & x) { return (6)*x + (2) - (1)/(x*x); } // The file must be compiled with -O0 because with -O1 and up the compiler simplifies func and dfunc out... int main() { auto func = (3*x*x + 2*x - 3 + 1./x); // auto func = fct(x); auto dfunc = derivative(func); cout.precision(16); for(double i = 0.1 ; i < 2. ; i+=.1) std::cout << func(i) << "\t" << fct(i) << '\n'; for(double i = 0.1 ; i < 2. ; i+=.1) std::cout << func(i) << "\t" << fct(i) << "\t" << dfunc(i) << "\t" << dfct(i) << '\n'; return 0; }