1 double dist( double h, double p ) 2 { 3 double sum = h; 4 while(h*p >= TOL) 5 { 6 h *= p; 7 sum += h*2; 8 } 9 return sum; 10 }