Click here to Skip to main content
15,671,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am currenty developing a game where my position can change in an integer. For instance:

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:[^]

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.
Updated 28-Feb-13 10:25am
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.

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.


Please see:[^].

Share this answer
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.

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.
Share this answer
Yvar Birx 28-Feb-13 16:35pm    
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.
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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900