Pages: 1
Topic closed
Hi guys, here's my project at: http://scratch.mit.edu/projects/nisarg_shah/1499975
But the problem here is that the timer doesn't stop at 0. Please help me out guys!
Thanks in advance,
Nisarg Shah
Offline
O_o It looks correct, so why is it messing up?
Though I notice that in the experimental viewer the number's a bit off (so it wouldn't work there)... but what about the actual Scratch program?
EDIT: Here's a bit of stuff I found - maybe this has something to do with it:
TheSuccessor wrote:
ScratchReallyROCKS wrote:
It's just computer number inaccuracy. I don't fully understand it, but I know it's not specifically a Scratch glitch. It even happens in other programming languages.
It's because computers store numbers in binary. Integers can be translated perfectly, but decimals are different. ½ in binary = 0.1, and ¼ = 0.01, 3/8 = 0.011 and 5/8 = 0.101. Mathematical people might begin to see the pattern now. 1/3 in binary = 0.0101 recurring. This is converted back from 0.0101010101 (or however many digits your computer stores it to) as 1/4 + 1/16 + 1/64 + 1/256 + 1/1024. This comes to 0.333007812.
Your computer will do it more accurately as it stores the binary number to many more decimal places. Some numbers though, are particularly difficult to store in binary, and so, when the computer rounds the number, once it has been converted back, incorrectly, these errors creep in. [/longBoringLectureOnMaths]
Last edited by Jonathanpb (2010-12-25 05:12:09)
Offline
Change the
repeat until timer = 0
to
repeat until timer < 0
Offline
Topic closed
Pages: 1