3
/* Solves equation (*f)(x) = 0 on x in [a,b]. Uses half interval method. */
4
/* Requires that (*f)(a) and (*f)(b) have opposite signs. */
5
/* Returns code=0 if signs are opposite. */
6
/* Returns code=1 if signs are both positive. */
7
/* Returns code=1 if signs are both negative. */
8
double (*f) (double), /* pointer to function to be solved */
9
double a, /* minimum value of solution */
10
double b, /* maximum value of solution */
11
double err, /* accuarcy of solution */
12
int *code /* error code */
15
int signa, signb, signc;
16
double fa, fb, fc, c, signaling_nan();
24
/* check starting conditions */
35
/* half interval search */
36
if ((dist = b - a) < 0)
50
if ((dist = b - a) < 0)
54
/* linear interpolation */
58
c = (a * fb - b * fa) / (fb - fa);