#include "newton_raphson.h"

double newton_raphson(func_ptr f, func_ptr df, double x_start,
        double epsilon, unsigned int *steps, unsigned int max_steps) {
    double x = x_start, last_x = x - 1;

    for( ; fabs(x - last_x) >= epsilon; (*steps)++ ) {
        if( *steps == max_steps )
            return NAN;

        last_x = x;
        x -= f(x) / df(x);
    }

    return x;
}
