Jump to content
  • Advertisement
Sign in to follow this  
jordi_0071

unending variable

This topic is 4687 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
You probably mean an arbitrary precision number. http://www.swox.com/gmp/ is a library that implements them.

You could also use Python or similar languages that have builtin support for arbitrary precision numbers.

Share this post


Link to post
Share on other sites
You can use GMP in C++. Look here

For all practical purposes an "unsigned long long" can count up as long as the program is running. On a modern CPU it would take decades to reach it's limit.

Share this post


Link to post
Share on other sites
Quote:
Original post by willthiswork89
if its in msdos that will be kinda hard but if its in like sdl you put it in your main loop like this

while(quit == false)
{
Counter++;
}


wha...huh??

It makes no difference if you're using a console app (which is what I assume you mean by "msdos") or "sdl", which is a library, not a platform..

Quote:
Original post by Trap
For all practical purposes an "unsigned long long" can count up as long as the program is running. On a modern CPU it would take decades to reach it's limit.

I agree. If you don't care about negative numbers, an unsigned long long should be sufficient. An unsigned long long is a 64-bit number, giving you a range of 0 to 264 or 18,446,744,073,709,551,616.

Assuming you had a 4GHz CPU and you could increment that variable once every clock tick it would still take over 146 years to overflow.

However, if you ever need a very very large number (for scientific simulations/calculations or whatever) then yeah, look into GMP or another arbitrary-length or precision number library.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Another possiblity is to write your own class that will add 1 to a number that is stored as a string of numbers. Which is most likely how GMP does it.

Share this post


Link to post
Share on other sites
Quote:
Original post by pragma Fury
I agree. If you don't care about negative numbers, an unsigned long long should be sufficient. An unsigned long long is a 64-bit number, giving you a range of 0 to 264 or 18,446,744,073,709,551,616.

Assuming you had a 4GHz CPU and you could increment that variable once every clock tick it would still take over 146 years to overflow.

Not every compiler supports the "long long int" type. Use whatever type is 64 bits. In Visual C, that is __int64.

If an unsigned 64-bit number takes 146 years to wrap around, then a signed number will take 73 years. So if 73 years is good enough, then you can use a signed type, if necessary.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!