- Home /
Is there a way to use integers greater than unity's infinity?
I noticed that when an integer gets big enough unity just recognizes it as infinity, somewhere around 1 x 10^35,but i need to make calculations with values bigger than that. How would i go about doing that?
Thank you for your help!
Answer by Loius · Nov 25, 2012 at 04:29 PM
When you need a bigger number (and this is true even in low level stuff like building hardware), you extend your existing framework (in this case, the integer).
I'm very bad at actual math, so I can't give any specifics, but you basically need a second int to represent the 'number of infinities'. So something like (realInteger = int1 * 100000 + int2). Of course you can't use that formula 'cause it'd hit infinity, but you override your math calculations based on the assumption that you're now using two integers to represent the results.
A long time ago I did a little sniffing around into this sort of programming; I can't remember the exact name but that's the basic idea. It's named something simple like 'big' or 'huge' numbers.
Answer by leonalchemist · Nov 24, 2012 at 07:39 PM
not 100% sure but i think float is could be bigger than int; thats still a pretty darn big number so not sure why u'd want to go bigger than that; i cant quite remember but maybe 'double' exists in unity; not sure
I am trying to develop an environment that extends infinitely in all directions using terrains that spawn as you go and then calculate their distance from the origin, even tho in world space i have them stay within a certain range to avoid the floating point precision problem. I just needed a way to keep these distance values going forever.
Unity does support "double" and "decimal" in C#. If you really need and infinite world, you'll eventually run into an overflow, if you do measure the distance from the origin.
I have it set up where once you are a certain distance from the origin you jump back to the origin in world space but not in "actual game" space
Your answer
Follow this Question
Related Questions
Dealing with Texture2D.width as it is a float number 3 Answers
Float to int casting in C# script with modulo giving division by zero error 1 Answer
How to break up a number into seperate digits? 2 Answers
Really weird behaviour with boolean variables from custom class 2 Answers
Idle Game Currency Optimizing 1 Answer