11-24-2009, 03:30 PM
|
#1
|
|
|
Is actionscript selfish lol?
I have this script:
Code:
on(release){
_global.combospeed -= 0.1;
}
and the same with + version.
I also have a dynamic text where the combospeed is show.
But when I do - 0.1 at 9.6 --> 9.5 it doesnt subtract by 0.1, but by 0.0999999999
WHY?!
it also adds 0.099999999 at 9.5 --> 9.6
WTF is wrong with actionscript? xD
Last edited by Killya; 11-25-2009 at 02:26 PM..
|
|
|
11-24-2009, 03:39 PM
|
#2
|

 |
Halley Research Station,
Latitude 75°35' S,
Longitude 26°39' W,
Brunt Ice Shelf,
Coats Land,
Antarctica |
|
 |
4,158 |
|
|
There's nothing wrong with Actionscript. It's your computer that's "faulty"
http://en.wikipedia.org/wiki/Floatin...uracy_problems
__________________
©2006 GlosRFC - Searching 8,168,684,336 brain cells
|
|
|
11-25-2009, 03:25 PM
|
#5
|
|
|
Did you read the link that glos posted?
__________________
Proud Montanadian
 We tolerate living and breathing.
Name Brand Watches
|
|
|
11-26-2009, 12:15 PM
|
#7
|

 |
Halley Research Station,
Latitude 75°35' S,
Longitude 26°39' W,
Brunt Ice Shelf,
Coats Land,
Antarctica |
|
 |
4,158 |
|
|
Perhaps this is a simpler explanation of the floating point error with your PC:
http://kb2.adobe.com/cps/139/tn_13989.html
You can avoid these type of errors by adopting two simple rules of thumb:
1. Avoid any kind of rounding until the last possible moment in your calculations.
2. Rethink the level of precision you really need. For example, if combospeed is supposed to represent the movement of a movieclip across the stage, you'll only really want it to move in whole pixels anyway! Similarly, if you're attempting to increase/decrease the _alpha of a movieclip, the minimum step is 0.4, so you should probably be adding/subtracting 0.5 each time.
__________________
©2006 GlosRFC - Searching 8,168,684,336 brain cells
|
|
|
11-26-2009, 05:57 PM
|
#9
|

 |
Halley Research Station,
Latitude 75°35' S,
Longitude 26°39' W,
Brunt Ice Shelf,
Coats Land,
Antarctica |
|
 |
4,158 |
|
|
No problem. To simplify it further for you....
...some numbers are known as recurring numbers. For example, 1/3 = 0.33333..
The 3 is repeated indefinitely so we say that the answer is 0.3 recurring. Notice the dots following the number which is mathematical shorthand to tell us that the 3's keep repeating.
Now, we might not be able to understand how some of these numbers work (although your Maths teacher will be able to explain them) but our brains can cope with them in the real world. Imagine that you have a cake which you cut into three identical pieces. Each piece measures 0.33333.. parts of that cake but you know that the whole cake is still there. If you put the pieces back together you will get a whole cake again. So, when we add 0.33333.. + 0.33333.. + 0.33333.. in our heads we get the right answer, 1, because we know that must be the right answer, and our brains can automatically cope with all of those 3's.
Computers aren't that clever, although they're a lot faster at dividing cakes! When a computer divides a number it only has so much storage space to hold those floating point numbers, i.e. all of those 3's. At some point, when the storage space runs out, it ignores all of the remaining numbers. Let's just imagine that your computer can only store 7 digits in its memory at one time. So 0.3333333333333.. wil be shortened to 0.33333
Now, when we ask the computer to add those numbers back together, it gives us the wrong answer:
0.33333 + 0.33333 + 0.33333 = 0.99999
It's close to 1 but, not close enough, because the computer has lost all of those extra 3's that stretch to infinity.
The more you compute with numbers like these (typically when a computer is asked to round a number internally) the more often these floating point errors occur, and the bigger the error becomes.
And yes, rounding the number yourself is the easiest way to get round the problem, although the key phrase (linked to my second rule of thumb) is to make sure that your own rounding function uses an appropriate level of precision. FizixMan mentioned that too at the end of his post.
There's a few easy ways to remind yourself about the correct level of precision. Just say to yourself, elephants or ants!
If you want to weigh elephants, you'd use kilogrammes. If you want to weigh ants, you'd use grams
Or say snakes and worms (you'd use feet/metres to measure the length of a snake, and use inches/centimetres to measure a worm)
Hope that helps.
__________________
©2006 GlosRFC - Searching 8,168,684,336 brain cells
|
|
|
11-27-2009, 10:32 AM
|
#10
|
|
|
Thanks! That was like, an awesome easy explenation, but I don't know why it would get errors at particular moments when I'm doing 9.6-0.1
Guess I never know!
I fixed it now by multiplying and dividing by 10 again 
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 04:48 PM.
|
|