cooldude832 Posted October 9, 2007 Share Posted October 9, 2007 In honor of the 300th year of euler, I am reporting on his studies on the basal series, and I wanted to have a php engine to test the basal series proving how slowly it converges, I made it using <?php echo "<form method=\"get\" action=\"".$_SERVER['PHP_SELF']."\"> Number of Trials: <input type=\"text\" name=\"n\" value=\"100\" /> <input type=\"submit\" value=\"Run\" /> </form>"; $values = array(); if($_GET['n'] >0 && is_numeric($_GET['n'])){ $n = $_GET['n']; } else{ $n = 100; } echo "<pre>Approximation for the Basel problem with ".$n." estimations</pre>"; for($i = 1; $i <=$n; $i++){ $j = $i-1; if($j == 0){ $temp = 0; } else{ $temp = $values[$j]; } $values[$i] = floatval($values[$j] +(1/pow($i,2))); echo $i.": ".$values[$i]."<br />"; } ?> However the results returned are like 1.6447339267508 when a lot more digits exist out to the right. Any one have any help with getting these digits, as you can see I tried floatval and that didn't do much, or am I at the statory limit of a float in php? Quote Link to comment Share on other sites More sharing options...
dingus Posted October 9, 2007 Share Posted October 9, 2007 i think you hit the limit of floats in said math what you need is some form of Arbitrary precision there is a function for this in php called BCmath you can get more details on the website that follows http://au3.php.net/bc if that is not an option there is a class i have attached that will help a lot i use it my self but i must stress that i didn't write it nor am i responsibly for maintaining it but i hope it helps [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted October 9, 2007 Author Share Posted October 9, 2007 thanks for the info, Yeah I realized I probably hit the float limit, and i might just try this in C in stead Quote Link to comment Share on other sites More sharing options...
btherl Posted October 10, 2007 Share Posted October 10, 2007 PHP already uses doubles, so I doubt you'll see any improvement in C unless you have a method to extend beyond double precision. The Zend engine has no single precision float type, only double. It's all here Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.