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
https://forums.phpfreaks.com/topic/72390-i-need-a-more-precise-number/
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.