unending variable
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.
You could also use Python or similar languages that have builtin support for arbitrary precision numbers.
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++;
}
while(quit == false)
{
Counter++;
}
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.
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.
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement