News for hackers. Stuff that matters.
Re:Not Lisp again (2009) by smitherfield on Tuesday May 02, 2017 @04:03PM (#14250054)
And in >=C89:

  #include <stdio.h>

  double deriv(double (*f)(double), double x)
  {
          static const double dx = 1e-8;
          return (f(x + dx) - f(x)) / dx;
  }

  static double cube(double x)
  {
          return x * x * x;
  }

  double deriv_cube(double x)
  {
          return deriv(cube, x);
  }

  int main(void)
  {
          printf("%f\n%f\n%f\n", deriv_cube(2), deriv_cube(3), deriv_cube(4));
          return 0;
  }

There are no comments on this comment yet.