User:Melab-1/Archives/Reference Desk/Mathematics/November 23 2008/Number 1
Appearance
php large num calculation woes
After viewing e (number), I had an irrational urge to calculate e using the formula . So I got to work. I simply made a php file that contained:
<?php echo pow((1+(1/(<38,613 nines>)), <exact same string of 9's>); ?>
which returns the number 1 . I also tried putting the nines into a variable, for which I used:
<?php $1=<38,613 nines>; echo pow((1+(1/($1))), $1); ?>
Which returns something weird and completely unexpected. 1) Why is it doing that? I'm guessing PHP has built-in truncation, and that's what's doing it, but I'm not sure... and 2) How can I make my unnecessary and irrational fantasy become real (using PHP if at all possible)? flaminglawyercneverforget 00:45, 23 November 2008 (UTC)
- The problem is the variable-name. It can't start with a number, write "$v1" or something instead of "$1". On a related matter, 38,613 nines is an absurdly large number, and I'm not surprised PHP choked on it. Try a much smaller number, like 1,000,000 or something, that should give you a pretty good estimate (I think). If it doesn't, step it up one order of magnitude at a time (or something) 83.250.202.208 (talk) 00:53, 23 November 2008 (UTC)
- I just tested 1,000,000 with google calculator, and it gives e correct to five decimal digits which is, lets face it, pretty much enough. 83.250.202.208 (talk) 00:57, 23 November 2008 (UTC)
- The reason you ended up with "1" is because you've used an extremely large number (Why 38,613 digits particularly?) and run out of precision in the floating point representation used by PHP. See the PHP manual on floating point numbers, and if you really want to play with big numbers, try the BCMath and GMP modules it mentions. - IMSoP (talk) 01:17, 23 November 2008 (UTC)
- Just to clear up the fact that I'm not completely crazy, I got 38613 because I held the 9 button down for a few secs, then copied it, then held down Ctrl+V for a few secs. I didn't have an OCD attack and press the 9 button 38,613 times. flaminglawyercneverforget 01:32, 23 November 2008 (UTC)
- I've run into another problem - even though using a smaller number is correct enough (fixed), the number is still truncated to 12 decimal places. Is there some way to fix that? And (I'm a php/sql n00b), how would I go about installing GMP or BCMath on a free hosting site like I have? flaminglawyercneverforget 01:53, 23 November 2008 (UTC)
- Just to clear up the fact that I'm not completely crazy, I got 38613 because I held the 9 button down for a few secs, then copied it, then held down Ctrl+V for a few secs. I didn't have an OCD attack and press the 9 button 38,613 times. flaminglawyercneverforget 01:32, 23 November 2008 (UTC)
- Self-hosting is about a million times easier than remote hosting once you have it set up. If you're only doing it for yourself, why remote host? You have a lot more control when you self-host and you don't have to upload anything ever. --98.217.8.46 (talk) 19:53, 23 November 2008 (UTC)
- I don't like self-hosting because 1) it's not just for me, I'm trying to get my name on this list, and 2) I have a tiny hard drive, and 3) I don't want my processor to be maxxed out 100% with this one problem, because I actually do other things on my computer. flaminglawyercneverforget 21:25, 23 November 2008 (UTC)
- Hosting has nothing to do with a calculation like that. What you are asking is can you dent such a problem with your hardware or using a free hosting and ihe straightforward answer is no you can't and you shouldn't even be trying to as far as his hosting is concerned. Plus you should learn a lot more about the problem before attacking it even if you had good hardware. Anyway why do you mess up your sig with loads of user names?, sounds to me like you value the people answering questions just as much as your hosting provider. Dmcq (talk) 22:53, 23 November 2008 (UTC)
- I don't like self-hosting because 1) it's not just for me, I'm trying to get my name on this list, and 2) I have a tiny hard drive, and 3) I don't want my processor to be maxxed out 100% with this one problem, because I actually do other things on my computer. flaminglawyercneverforget 21:25, 23 November 2008 (UTC)
- Self-hosting is about a million times easier than remote hosting once you have it set up. If you're only doing it for yourself, why remote host? You have a lot more control when you self-host and you don't have to upload anything ever. --98.217.8.46 (talk) 19:53, 23 November 2008 (UTC)
- I'm not going to go to eight indents. I mess up my sig with loads of usernames because I miss them. They were good editors and the got banned/indef-blocked :( . And for your information, I hold my hosting provider in the highest respects. Hey, without them, I wouldn't have any hosting. flaminglawyercneverforget 00:08, 24 November 2008 (UTC)
The PHP code posted here consumes negligible resources, Dmcq. The OP did express an interest in calculating a large number of digits of e; however, this was after your post about time-wasting.To the OP: that formula is not at all how you would actually produce new digits of e — in fact, thepow()
function is probably using an extant value of e in its calculations! You would need specialized software (not PHP) and much bigger hardware to get a place on any modern list. --Tardis (talk) 18:05, 24 November 2008 (UTC)- If you would read the replies a bit more carefully please you would see that I said that after a poster suggested the use of BCMath or GMP and only commented negatively on the OP after he showed he had realized the problem was too big for his computer and that he wanted to run it on the free hosting. Dmcq (talk) 19:57, 24 November 2008 (UTC)