Floating point numbers permeate almost every area of game programming. They are used to represent everything from position, velocity, and acceleration, to fuzzy AI variables, texture coordinates, and colors.
Yet, despite their ubiquitous role, few programmers really take the time to study the underlying mechanics of floating point numbers, their inherent limitations, and the specific problems these can bring to games.
As an independently written articles that's part of Intel's Visual Computing microsite
, Neversoft co-founder and veteran programmer Mick West lays out the specifics to help visualize the problems with floats in a new article that starts off as follows:
"A float consists of 32 bits: a sign bit, an 8-bit exponent (e), and a 23-bit significand (s).
To visualize the problems with floats, it's useful to visualize the differences between floats and integers. Consider how the 32-bit integers represent space. There are 232 integers; each one can be thought of as representing a region between two points on a line.
If each integer represents 1 millimeter, then you can represent any distance using integers from 1mm to 232mm. That's any distance up to about 4,295km, about 2,669 miles, with a resolution of 1mm."
You can now read the full Gamasutra feature
on visualizing floats, floats versus integers and other useful calculations (no registration required, please feel free to link to this feature from other websites).