This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2010-01-31 10:35:24

Fyxen
Scratcher
Registered: 2009-06-24
Posts: 12

Re: A glitch in 1.4?

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

 

#27 2010-01-31 11:01:46

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: A glitch in 1.4?

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

 

#28 2010-01-31 11:15:17

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: A glitch in 1.4?

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

 

#29 2010-01-31 13:37:02

billyedward
Scratcher
Registered: 2008-01-03
Posts: 500+

Re: A glitch in 1.4?

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.


"I'd love to change the world, but they haven't released the source code yet."
Check out the latest version of Streak --> http://billy.scienceontheweb.net/Streak

Offline

 

#30 2010-02-06 16:48:54

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: A glitch in 1.4?

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!


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#31 2010-02-19 14:10:28

aweman
Scratcher
Registered: 2008-06-22
Posts: 100+

Re: A glitch in 1.4?

why would you want to type a negative number in a wait block?

Offline

 

#32 2010-02-19 21:27:24

mathematics
Scratcher
Registered: 2009-03-01
Posts: 1000+

Re: A glitch in 1.4?

aweman wrote:

why would you want to type a negative number in a wait block?

Just for fun.  big_smile

Offline

 

#33 2010-02-19 23:42:33

carnack
Scratcher
Registered: 2009-06-30
Posts: 100+

Re: A glitch in 1.4?

How many people here know how to program Squeak?


http://i853.photobucket.com/albums/ab95/7x9/Carnack.png
Carnack The Bug

Offline

 

#34 2010-02-20 04:37:34

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: A glitch in 1.4?

<set{seconds }to(1.89)
<wait(<{seconds}>)secsc>


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#35 2010-02-24 15:30:33

aweman
Scratcher
Registered: 2008-06-22
Posts: 100+

Re: A glitch in 1.4?

i tried that Daffy, it didn't work. but then i set 1.89 to 1.89 and it worked.

Offline

 

#36 2012-09-01 19:14:34

Hitechcomputergeek
Scratcher
Registered: 2010-11-21
Posts: 47

Re: A glitch in 1.4?

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


http://scratch.mit.edu/static/projects/Hitechcomputergeek/1687140_sm.png

Offline

 

#37 2012-09-01 21:43:44

shadow_7283
Scratcher
Registered: 2007-11-07
Posts: 1000+

Re: A glitch in 1.4?

Please don't post on topics that have been inactive for extended periods of time.  smile

Offline

 

#38 2012-09-02 09:30:50

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: A glitch in 1.4?

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...


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#39 2012-09-27 18:40:42

3sal2
Scratcher
Registered: 2012-03-22
Posts: 100+

Re: A glitch in 1.4?

Rounding error. Squeak has rounding issues.


http://scratch.mit.edu/static/projects/3sal2/3120946_sm.png In 2012, scientists at the LHC discovered the Higgs boson, which explains the source of the masses of the W+, W-, and Z bosons, as well as fermions.

Offline

 

Board footer