| | |
number string
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I have been working on a function which creates a 1 million digit value of pi but php is treating a theoretical numeric variable as a string. Below is the code I used and for now I have put a small limit on the digits but it is line 22 that wont calculate. Does anybody know how to make it so that a function inside a variable can be executed with its mathematical calculations?
With the echo functions inside the code, the below is echoed
All except the last line in the above box is a var_dump of the looped variable which will not perform the mathematical and function calculations. The last line is the answer that the function has got for pi. The reason why it is zero is because of line 22 where $tempval is a string. But it needs to be a mathematical string as it has functions that need to execute. Does anyone know how to execute this variable?
php Syntax (Toggle Plain Text)
<? function realpi() { $pival=1; while ($pirow<6) { $pirow+=1; $pisubrow=1; $tempval="(0.5*sqrt(2"; while ($pisubrow<$pirow) { $tempval.="+sqrt(2"; $pisubrow+=1; } $pisubrow=1; while ($pisubrow<$pirow) { $tempval.=")"; $pisubrow+=1; } $tempval.="))"; $pival=$pival*$tempval; var_dump($tempval); echo "<br>"; } $pival=$pival/2; return $pival; unset($pirow); } echo realpi(); ?>
PHP Syntax (Toggle Plain Text)
string(13) "(0.5*sqrt(2))" string(21) "(0.5*sqrt(2+sqrt(2)))" string(29) "(0.5*sqrt(2+sqrt(2+sqrt(2))))" string(37) "(0.5*sqrt(2+sqrt(2+sqrt(2+sqrt(2)))))" string(45) "(0.5*sqrt(2+sqrt(2+sqrt(2+sqrt(2+sqrt(2))))))" string(53) "(0.5*sqrt(2+sqrt(2+sqrt(2+sqrt(2+sqrt(2+sqrt(2)))))))" 0
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
I have just discovered a major bug in php and an example is the below code. For some reason php rounds the variable $var to the number 2 and displays "2" instead of 1.99999999999999999999999999999999999999. So how would I make php display 1.99999999999999999999999999999999999999 while keeping the variable an integre for mathematical calculations as I need to display a 1 million digit number?
php Syntax (Toggle Plain Text)
$var=1.99999999999999999999999999999999999999; echo $var; //displays "2" without the quotes
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
I have just checked the create_function() element/function in the official documentation but I can't see how impliment it into my code. However, I have made a second piece of that that might calculate pi (haven't confirmed this new method follows the algorithom) which should solve my first problem leaving my digit problem. The code I currently have is as follows:
But the only problem is that php is rounding it to the eleventh digit. Is there any way around it because I need 1 million digits.
php Syntax (Toggle Plain Text)
<? function realpi() { $pival=1; while ($pirow<25) { $pirow+=1; $pisubrow=0; $tempval="0"; while ($pisubrow<$pirow) { $tempval=sqrt(2+$tempval); $pisubrow+=1; } $pival=0.5*$tempval*$pival; var_dump($tempval); echo "<br>"; } $pival=$pival*2; return $pival; unset($pirow); } echo realpi(); ?>
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
•
•
I have just discovered a major bug in php and an example is the below code. For some reason php rounds the variable $var to the number 2 and displays "2" instead of 1.99999999999999999999999999999999999999. So how would I make php display 1.99999999999999999999999999999999999999 while keeping the variable an integre for mathematical calculations as I need to display a 1 million digit number?
php Syntax (Toggle Plain Text)
$var=1.99999999999999999999999999999999999999; echo $var; //displays "2" without the quotes
http://www.php.net/float
You might want to look into using the math extensions:
http://www.php.net/manual/en/refs.math.php
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Convert integer to string (C++)
- reversing number problem. (C)
- to convert string to integer value (Legacy and Other Languages)
- Number To String Conversion (PHP)
- check number is string (C)
- Finding the first number char in a string (Java)
- C++:three-digit number all odd, eve, or both (C++)
- Sorting a map<string,long> by the value... (C)
- How do i print int num1; a 5 digit number like 1 2 3 4 5 (Java)
Other Threads in the PHP Forum
- Previous Thread: sql query string logical problem
- Next Thread: HTTP request
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






