Jump to content

I need a more precise number!


cooldude832

Recommended Posts

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?

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.