D
D
devalone2017-07-18 17:57:03
Game development
devalone, 2017-07-18 17:57:03

What to use, int, float or double in modern game engine?

Consider modern CPU architectures with 64 bit instructions and modern GPUs, for example, nvidia 1080.
If we represent the world with millimeter precision, then a 64-bit integer type allows us to make a world with a size of > 9000000000000 km, double ~ 10000000000 km and float ~ 10 km.
int is big enough and I doubt anyone would want an even bigger open world game. But modern processors have had a co-processor for floating point operations for a long time and I don't think that floating point arithmetic will be much slower. If you choose between float and double, double is larger, but video cards work faster with float https://en.wikipedia.org/wiki/GeForce_10_series#Ge...
GeForce GTX 1080 Ti: Single precision - 10609 GFLOPS, Double precision - 332 GFLOPS .
Engines like Unity use float, but there are also those that use double like unigine unigine.com/en/products/engine/unbounded-world Do they have problems with slow double arithmetic?
What is better to use to represent position, speed, acceleration, etc. game objects: int(64), float or double?
Or maybe break the world into cubes, let's say 10 km? But then there are problems with rendering large scenes.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
maaGames, 2017-07-18
@maaGames

And this and that and that. It is better not to transfer a double to a video card (especially to nvidia cards), so float. In a physics engine, double is better, or a real number with a fixed point (read int/int64).
You have an error in judgment. Is 1mm a lot or a little? Is it ok for linear size? And for the corner? And if you turn clockwise five times and counterclockwise three times, while the coordinate is saved to the nearest millimeter? If we turn the ship, 300 meters long? And if the pencil is 7 centimeters long? What if the character blinks? Those. you need to use those data types that are sufficient to represent the data you are working with. Moreover, they may well be converted into each other, possibly with a loss of accuracy.

L
laxikodeje, 2017-07-18
@laxikodeje

floats VERY STRONGLY Slow down calculations.
although they avoid rounding, inaccuracies and overflows MUCH better than ints.
What and where to use is up to you.
depends on specific locations.
But will it slow down there on not the coolest hardware.
Or are you focusing only on top-end hardware.
if in doubt - conduct tests, experiments, speed measurements.
what exactly where to use - without tests and experiments, you will know in advance only with experience.
UPD:
Depends on the logic of your world.
Maybe it will be easier to make a 128-bit integer - it will still be very fast.
or divide the world into independent segments - all the same, objects very far from each other most likely do not interact.
this technology was used in processors in the last century specifically for addressing. the so-called "segment:offset" and "short near addresses" and "far long addresses".

M
Mercury13, 2017-07-18
@Mercury13

Preliminary calculations (for example, model coordinates) should be carried out in a type of sufficient accuracy (and, of course, on the processor). The final ones are in the usual float.
And, of course, for open worlds you will have to write your own “bicycles” for cutting off distant horizons, and Unity is not sure what will fit in the standard package .
Again. The coordinates of the game participants are written in double. Model vertex coordinates are in float. We carry out initial coordinate transformations on the processor, make sure that the coordinates deserve to be rendered, convert them to floats and drive them to video.

S
Sergey, 2017-07-18
@begemot_sun

Float has such a thing as a presentation error.
For example, the expression (1/3) * 3 = 0.999999996 for a machine can be quite true :)
And operations with Int are always orders of magnitude faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question