15,671,266 members
See more:
I am currenty developing a game where my position can change in an integer. For instance:

C#
`Player.X -= Player.WalkingSpeed;`

Now I presumed that the Integer was infinite, but to make sure, I did a quick google check and found this:

http://msdn.microsoft.com/en-us/library/5kzh1b5w%28v=vs.80%29.aspx[^]

Which is telling me that an integer ranges from -2,147,483,648 to 2,147,483,647. Is there any way I can make an(my) integer (so it)that does not stop at -2,147,483,648 and 2,147,483,647?

Edit: Any other solutions are welcome to, but I need it to be a whole number since I can not use doubles.
Posted
Updated 28-Feb-13 10:25am
v2
Richard C Bishop 28-Feb-13 16:25pm
Yes, use a Long. It mine as well be infinite.
Yvar Birx 28-Feb-13 16:31pm
Cheers man. If no other solutions, I'll choose yours.
joshrduncan2012 28-Feb-13 16:37pm
I'd go with long or use the custom BigInt class.

## Solution 1

No. And it is not needed. But you can use positive and negative infinity and not-a-number with floating-point types and do value arithmetic with those values.

[EDIT]

—SA

v2
Richard C Bishop 28-Feb-13 16:36pm
Nice, +5. I didn't even know about that, thank you.
Sergey Alexandrovich Kryukov 28-Feb-13 16:50pm
Oh! they are very important! Well before .NET, when one had to build corresponding bit patterns to use them (by IEEE-754 standard, see a link after [EDIT]), I found some good uses for them:
default value, "no data", "unassigned". On very effective use way drawing histogram-like graphs (with fixed step). In real life, some points was missing. People did a lot of incorrect things, such as interpolation, but to be true, they should have used some concept of "no point".
In rendering, the graph simply missed the points.

You can do x=-1.0/0 and obtain -inf. Then, you can calculate 1.0 / ( 1.0 + 1/x) and obtain the value 1.0. In .NET, its a correct calculation. Inf - Int, 0.0/0.0, Inf/Inf will give you NaN.
In x86, there is a special flag: to throw exception on such operations, or return inf/NaN. Finally, on .NET they decided to keep this flag to allow such operations. Thanks goodness! If you calculate correctly, it's quite save.

One should understand that floating-point numbers are not real numbers but only the models of them, so extension the values sets with Inf and NaN is more natural.

—SA

## Solution 2

There is not an infinite integer, but you can use a Long. Its range is negative 9,223,372,036,854,775,808 to positive 9,223,372,036,854,775,807. That is plus or minus nine quintillion.

v2
Yvar Birx 28-Feb-13 16:35pm
Thanks!
Richard C Bishop 28-Feb-13 16:42pm
You are welcome.
Sergey Alexandrovich Kryukov 28-Feb-13 16:52pm
My 4, because you should have mentioned (for naive beginners): never use those literals, use int.MinimumValue, int.MaximumValue, uint.MinimumValue, uint.MaximumValue, byte.MinimumValue, byte.MaximumValue, etc.
—SA
Richard C Bishop 28-Feb-13 16:54pm
Fair enough.
Yvar Birx 28-Feb-13 16:57pm
"Naive", I hope you know what the definition means, because this is probably the third time you have insulted me on my questions.