Skip to main content
Participating Frequently
November 30, 2006
Question

Simple arithmatic function is not resulting in zero

  • November 30, 2006
  • 3 replies
  • 352 views
This is absolutely bizarre. 2.4 - 1.2 = 1.2 and 1.2-1.2 = 0, or so you'd think, except that Flash keeps telling me 1.2 - 1.2 = -4.44089209850063e-16. Subtract 1.2 once more from -4.44089209850063e-16 and you miraculously get -1.2. Even more bizarre is that this only happens if the starting value is greater than 2.4.

See attached code which began as something much more complex but I've commented out absolutely EVERYTHING except for this little bit of math and yet it keeps telling me that 0 is -4.44089209850063e-16. But only if rpm is greater than 2.4 to start with. If it's 2.4 or less, it does get to zero.

Thanks for any help.
This topic has been closed for replies.

3 replies

kglad
Community Expert
Community Expert
November 30, 2006
1. because your computer uses binary arithmatic.

2. you must round to get zero but you don't need to round to whole numbers. you can round to within 15 digits and then you'll get zero and won't loose any significant accuracy for most purposes.
kglad
Community Expert
Community Expert
November 30, 2006
0 = -4.44089209850063e-16 within 15 digits which is the limit of accuracy within flash.
maija_gAuthor
Participating Frequently
November 30, 2006
But why doesn't it return the whole numeral 0? And how do I get it to without rounding to whole numbers? I just want 0 and, in fact, I need it, for the rest of my script to work.

Thanks.
maija_gAuthor
Participating Frequently
November 30, 2006
P.S. the ClipButton class is just button behaviours on a movie clip: up, over, down. It's what I use instead of Flash Buttons.