00001 #include "formula.h" 00002 00003 double b_to_p(double b, double rtt, double tzero, int psize, int bval) 00004 { 00005 double p, pi, bres; 00006 int ctr=0; 00007 p=0.5;pi=0.25; 00008 while(1) { 00009 bres=p_to_b(p,rtt,tzero,psize, bval); 00010 /* 00011 * if we're within 5% of the correct value from below, this is OK 00012 * for this purpose. 00013 */ 00014 if ((bres>0.95*b)&&(bres<1.05*b)) 00015 return p; 00016 if (bres>b) { 00017 p+=pi; 00018 } else { 00019 p-=pi; 00020 } 00021 pi/=2.0; 00022 ctr++; 00023 if (ctr>30) { 00024 return p; 00025 } 00026 } 00027 }