#include <math.h>
#include <stdio.h>
#include <assert.h>
#include "gpk_std.h"
#include "romberg.h"
#include "gpklib/ieee754.h"

struct xx_s     {void *cc; integrand_function ff; double sing;};
LOCAL double funcroot(double x, void *q, int nc);

/* for function that has a sqrt(x-a) singularity */
method_fr midsqrt(integrand_function func, double a, double b,
				int n, void *c, int nc)
{
 struct xx_s q;

 assert(a >= 0.0);
 assert(b > a);
 q.cc = (double *)c;
 q.ff = func;
 q.sing = a;
 return midpnt(funcroot, a>q.sing?(2./3.)*pow(a-q.sing, 1.5) : 0.0,
				(2./3.)*pow(b-q.sing, 1.5), n, &q, nc);
}

LOCAL double funcroot(double x, void *qq, int nc)
{
 struct xx_s *q = (struct xx_s *)qq;
 return quiet_nan(0);	/* This function seems to give the wrong answer. */
 /* return (*q->ff)(pow(1.5*x, 2./3.)+q->sing, q->cc, nc)/pow(1.5*x, 1./3.); */
}
