#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "func_ptr.h"

#define TABLE_LINE(func, x, h) (printf("%-24s%.12f\t%.12f\n", #x, \
            slope_right(func, x, h), slope_central(func, x, h)))

double slope_right(func_ptr func, double x, double h) {
    return (func(x + h) - func(x)) / h;
}

double slope_central(func_ptr func, double x, double h) {
    return (func(x + h) - func(x - h)) / (2 * h);
}

int main(void) {
    puts("x\t\t\tright\t\tcentral");
    TABLE_LINE(&sin, M_PI / 3, 1e-5);
    TABLE_LINE(&sin, 100 * M_PI + M_PI / 3, 1e-4);
    TABLE_LINE(&sin, 1e12 * M_PI + M_PI / 3, 1e-3);

    return 0;
}
