514Part IIIAdvanced (Ftp web hosting) Features and TechniquesTo convert this to

514Part IIIAdvanced Features and TechniquesTo convert this to an arbitrary-precision version, we must replace all the math functions andoperators that need precision with their BC counterparts, like so: function pi_approx_bc($iterations, $print_frequency, $scale) { $squared_approx = 12 ; $next_sign = -1; $denom = 2; for ($iter = 0; $iter < $iterations; $iter++) { $squared_approx = bcadd( $squared_approx, bcmul($next_sign, bcdiv(12, bcpow($denom, 2, $scale), $scale), $scale), $scale); $denom++; $next_sign = - $next_sign; if ($denom % $print_frequency == 0) { $estimate = bcsqrt($squared_approx,$scale); print( $denom iterations: $estimate
); } } } Notice that although the BC functions want string arguments, we can as always use regularnumbers in their places and rely on PHP to convert the arguments to strings for us. Also noticethat we did not bother making the numerical computations that do not require great precisioninto BC computations (for instance, we still have $denom++rather than bcadd($denom,1). Finally, we added a scale argument to the entire function, which turns the decimal precision ofeach BC function it calls. Unfortunately, both your authors and our browsers ran out of patience with this series beforeit got even got to the level of precision of PHP s value. Here are some late results of callingpi_approx_bc(1250000,50000,50): 50000 iterations: 3.14159265397177274129723551068347726371297686926596100000 iterations: 3.14159265368528715924598769254390594927146205337113150000 iterations: 3.14159265363223483956231649503922204272933217538202[..] 1150000 iterations: 3.141592653590515303104552554096025800032655499550031200000 iterations: 3.141592653590456384611480874034589189444055471472111250000 iterations: 3.14159265359040439393304018710072157703501022388304The correct digits in the preceding output are about one digit shy of the PHP value. This isthe fault of the series we chose rather than the arbitrary-precision libraries with a moresophisticated and speedier approximation series, you too can serve up millions of digits of pito your eager audience.
Note: If you are looking for cheap and reliable webhost to host and run your web application check Vision coldfusion web hosting services

Leave a Reply