Okay folks, a little Computing 101. What Y'all are experiencing is a thing called round-off error. It happens because computers typically store numbers in one of several binary formats (ones and zeros), and just as a fraction results in an infinitely repeating pattern when represented as a decimal value, unless the denominator is the product of the of powers of factors of 10 (i.e 2^n*5^m), so too, it will result in an infinitely repeating pattern in binary, unless the denominator is a power of 2. Since computers can't use an infinite number of bits to store a number, eventually they round off the last bit, and you get a tiny error in the representation of your number. It happens everywhere, and is not a glitch in Scratch.
For this reason, one should generally avoid trying to compare "real" (noninteger) values for exact equality. Instead, compare for "close enough".
Example: Instead of checking to see if X=Y, check for ABS(X-Y)<E, where E is a very small number, like .0000001, that represents your allowable error in calculation.
In other words, 1.890...001 is as close as your computer can get to 1.89 in whatever format Scratch uses to represent nonintegers, and you're seeing it because Scratch doesn't have much output formatting and you're just going to have to live with it. *grins*
Best regards, Fyxen.
PS, a more general, scaling, form of the comparison would be
ABS(X-Y)/MAX(ABS(X),ABS(Y))<E, where E now represents tolerable error as a fraction of the maximum value involved (think "significant digits", sort of) instead of as an absolute error. Unfortunately this isn't so easily implemented in Scratch since no Maximum function is provided.
Last edited by Fyxen (2010-01-31 10:55:45)
Offline
mathematics wrote:
The same thing happens for 3.14159265.
Take a look at what mathematics said too. It works, but with a slightly more serious ending...
(3.14159265 = 3.1415926499999998)
I guess it all comes down to what fyxen said.
Offline
shadow_7283 wrote:
mathematics wrote:
The same thing happens for 3.14159265.
Take a look at what mathematics said too. It works, but with a slightly more serious ending...
(3.14159265 = 3.1415926499999998)
I guess it all comes down to what fyxen said.
It's only 0.0000000000000002 seconds...
Offline
Hmmmm... looks like a problem with the round function used in writing the typed in argument contents to RAM... I will see if I can fix it, and if so I'll post a changeset fo anyone interested in fixing it on their computer.
Offline
Hmm... Very interesting glitch. After I experimented around a little (to see if any other numbers have the glitch) I noticed you can type a negative number into a wait block!
Offline
why would you want to type a negative number in a wait block?
Offline
aweman wrote:
why would you want to type a negative number in a wait block?
Just for fun.
Offline
i tried that Daffy, it didn't work. but then i set 1.89 to 1.89 and it worked.
Offline
TheGameMaster1231 wrote:
Wow... That Is A Wierd Glitch. It Doesn't Work With Any Other Numbers...
Actually, it does.
http://scratch.mit.edu/forums/viewtopic.php?id=52326
Offline
Please don't post on topics that have been inactive for extended periods of time.
Offline
Hitechcomputergeek wrote:
TheGameMaster1231 wrote:
Wow... That Is A Wierd Glitch. It Doesn't Work With Any Other Numbers...
Actually, it does.
http://scratch.mit.edu/forums/viewtopic.php?id=52326
Don't post on old topics...
Offline