Jump to content
Science Forums

Recommended Posts

Posted

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.

Posted
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. ;)

Posted

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:

Posted

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

Posted
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 here

wend

Now, what is it that you want to do?

 

Nonresponsive,

Buffy

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...