#ifndef __my_formula_with_inverse_h__ #define __my_formula_with_inverse_h__ //#include "formula.h" double my_b_to_p(double b, double rtt, double tzero, int psize, int bval) { // printf("b=%f, rtt=%f, tzero=%f, psize=%d, bval=%d",b,rtt,tzero,psize,bval); double p, pi, bres; int ctr=0; p=0.5;pi=0.25; while(1) { bres=p_to_b(p,rtt,tzero,psize, bval); /* * if we're within 5% of the correct value from below, this is OK * for this purpose. */ if ((bres>0.95*b)&&(bres<1.05*b)) return p; if (bres>b) { p+=pi; } else { p-=pi; } pi/=2.0; ctr++; if (ctr>30) { return p; } } } #endif /* __my_formula_with_inverse_h__ */