Sign in to follow this  

unending variable

This topic is 4345 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

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

This topic is 4345 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this