I was looking through some source code which said:
I was looking through some source code which said:
In a lot of physics simulations, which it looks like this comes from, the numbers are kind of experimentally found and tuned to get something that "feels" or "looks" right. For example, you might have a MAX_SPEED value of 10.0f, and if you ask why 10.0f, you'll probably get the answer that because of the size of the game/map, and the way the character moves, etc. 10.0f gives a nice, balanced maximum speed. If you change the size of the map, or the way the character moves, or "zoom" the camera out, you might want to pick a different value.Why 0.89 of all numbers
Floats were often faster than doubles, because they're usually smaller (floats are usually 32 bits, doubles are usually 64 bits). These days, however, depending on your processor, your floating point math might always be done in 64-bits, so a 32 bit float might be converted to 64 bits when math is done on it (which means the float may not be faster). On some processors, float might still be faster.why is the above declared as a float instead of a double? Is it always like this? From my research, float is a 32 bit single precision number. Why not use a data type that covers more precision?
long is an integer type, double is a floating point type. Totally different things.From what I know from books: double has better precision than a long. Why not use a double? I only always use double and int when I declare variables.
It's probably an arbitrary choice or something found through experimentation (empiric observation)Why 0.89 of all numbers
It is true that 0.89 cannot be represented exactly by a float, and neither can a double; but it can represent it more precisely.Why not use a data type that covers more precision?
Double is for 64-by floating point arithmetic (an approximation of "Real" numbers from algebra) while long is a plain 32-bit integer. They're used for entirely different purpose. The 64-bit integer version is "long long" (or "__int64")From what I know from books: double has better precision than a long. Why not use a double? I only always use double and int when I declare variables.