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

#1 2008-11-18 14:08:39

ffrazer
Scratcher
Registered: 2008-10-02
Posts: 1

round(-0.5) works differently in online Java versus standard Scratch

In standard Scratch, round(-0.5) rounds to -1
but in the online Java, round(-0.5) rounds to 0.
It would be more predictable if they worked the same. I would have expected that round(-0.5) would round to -1 for both.

Offline

 

#2 2008-11-18 16:08:01

Paddle2See
Scratch Team
Registered: 2007-10-27
Posts: 1000+

Re: round(-0.5) works differently in online Java versus standard Scratch

ffrazer wrote:

In standard Scratch, round(-0.5) rounds to -1
but in the online Java, round(-0.5) rounds to 0.
It would be more predictable if they worked the same. I would have expected that round(-0.5) would round to -1 for both.

You may be seeing a case of different internal representaitions leading to different evaluations.  There may be no exact representation for -0.5 in one or both environments and the binary approximation may be different enough that they evaluate differently when rounded.  Just a theory.

Also, take a look at this project which walks the values up from -1 to +1 by in steps of 0.1 and you can see that round-off error results in a different result than what you describe above.

http://scratch.mit.edu/projects/Paddle2SeeFixIt/325050


http://i39.tinypic.com/2nav6o7.gif

Offline

 

Board footer