Lord Hakk Posted October 26, 2006 Report Posted October 26, 2006 hi. I am wondering how to give a program the concept of infinity for stuff like calculating pi ( i wont really do that but it would be fun to know). do I use the "WHEN WHILE" loop thing? or the "IF THEN" loop? do I put them togeather? I also would like it if someone gave me an example program with taht in it. for some reason i cant program from scratch but I can change around and existing program. thanks. Quote
TheFaithfulStone Posted October 26, 2006 Report Posted October 26, 2006 In pseudo-code: while (1){/* your code here */} That runs the loop forever. Actually, I guess that's C. - Just set the condition of while to anything that's always true 1==1, 1<2 something like that. TFS Quote
Turtle Posted October 26, 2006 Report Posted October 26, 2006 hi. I am wondering how to give a program the concept of infinity for stuff like calculating pi ( i wont really do that but it would be fun to know). do I use the "WHEN WHILE" loop thing? or the "IF THEN" loop? do I put them togeather? I also would like it if someone gave me an example program with taht in it. for some reason i cant program from scratch but I can change around and existing program. thanks. Infinity is not a number and computers have no concepts. The best you can do in your program is set the loop limit to the largest allowed integer by specifically typing it out. DO WHILE limit = 239456701391936713671376946724624096724876214284067200276140132760210467040123468770670127456802421468...Or such a matter. ;) Quote
skuzie Posted October 27, 2006 Report Posted October 27, 2006 Try to use exponential growth, like: while (1){x = x ^2} With each iteration you are approaching the limit of infinity, since infinity has no limit it just keeps growing and growing at a faster rate .. untill you get an integer overflow on x :shrug: Quote
Buffy Posted October 27, 2006 Report Posted October 27, 2006 As aluded to above, the devil is in the implementation. Native data types have 1,2,4,8 bytes in them for integers: most compilers/interpreters only implement these. They overflow at an "uninteresting" number of digits. Some languages implement "big integers" which are handled in software rather than hardware, but are usually always still "trivial" as far as mathematicians are concerned. You can also implement your own "really, really, really" big--best if you make them dynamically extensible--integers. This is the *only* way to do the "1 million digits of pi" problem, but no one really ever has an excuse to implement these in any efficient sort of way. But its a great way to learn the limitations of computers and how number theory and abstract algebra work. With 100 decimal places you can represent the universe,Buffy Quote
TheFaithfulStone Posted October 27, 2006 Report Posted October 27, 2006 see, i misunderstood the question. tfs Quote
billythekiddrummer Posted November 1, 2006 Report Posted November 1, 2006 that would probably freeze the computer and really be a slow down:hihi: :shrug: :hihi: Quote
pgrmdave Posted November 1, 2006 Report Posted November 1, 2006 Infinity cannot be represented by an infinitely long number. Quote
Lord Hakk Posted November 6, 2006 Author Report Posted November 6, 2006 Couldent I just use the when while loop along with the if then loop? also I need to see an acutal working program to make changes to fit what i want. Quote
Buffy Posted November 6, 2006 Report Posted November 6, 2006 Couldent I just use the when while loop along with the if then loop? also I need to see an acutal working program to make changes to fit what i want.In Basic, an infinite loop can be created using:while (true)'''''''' Stuff to be done ad nauseum herewendNow, what is it that you want to do? Nonresponsive,Buffy Quote
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.