02.02.2013 Views

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

Flash MX 2004 Games : Art to ActionScript

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Flash</strong> <strong>MX</strong> <strong>2004</strong> <strong>Games</strong><br />

153 = 9.99999999999998e-311<br />

154 = 9.99999999998466e-313<br />

155 = 9.99999999963881e-315<br />

156 = 9.99999983659715e-317<br />

157 = 9.99998748495601e-319<br />

158 = 9.99988867182684e-321<br />

159 = 9.88131291682494e-323<br />

160 = 0<br />

After the 160th iteration, the value becomes zero. This may seem unlikely, but a computer would<br />

whiz through the calculation in a blink of an eye. Once the value has diminished <strong>to</strong> zero the<br />

quantity has disappeared. If the intention was <strong>to</strong> use the result <strong>to</strong> multiply another variable then<br />

this <strong>to</strong>o will become zero. Floating-point errors like this are another source of difficult-<strong>to</strong>-locate<br />

bugs in a program. Always remember that unless you are working with integers within a sensible<br />

range, all other values are approximate. You may test two floating-point values <strong>to</strong> see if they are<br />

the same, using<br />

if (number1==number2){<br />

//Do something<br />

}<br />

Although this would work fine for integers, don’t use it for floats. Instead use<br />

if (((number1 - number2)*(number1 - number2))

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!