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

#1 2009-12-13 22:38:30

rakhi
Scratcher
Registered: 2009-03-28
Posts: 100+

[log1000=3]false?

When I enter  <(   log 1000 <=> 3 )>
it says false

Last edited by rakhi (2009-12-13 22:42:19)

Offline

 

#2 2009-12-14 04:42:57

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

Re: [log1000=3]false?

While you may think of log 1000 as an integer (whole number) value like 1,2,3 etc.  the computer is calculating it as a floating point number with a decimal place like 3.000.  Floating point numbers are really hard to compare on computers since they can't always be represented exactly by the binary numbers that the computer uses. 

Probably, at a level invisible to the values you see on the display, the binary representation of the floating point result of the log 1000 operation does not equal the binary representation of the value 3 you entered. 

To make a long story short...comparing for exact matches of floating point numbers is a very risky and problematic approach.  It's better to use an error margin such as

[blocks]
<(  <abs( (( log 1000 <-> 3 ))<<> 0.0001 )>
[/blocks]


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

Offline

 

#3 2009-12-14 08:26:06

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: [log1000=3]false?

Paddle2See wrote:

While you may think of log 1000 as an integer (whole number) value like 1,2,3 etc.  the computer is calculating it as a floating point number with a decimal place like 3.000.  Floating point numbers are really hard to compare on computers since they can't always be represented exactly by the binary numbers that the computer uses. 

Probably, at a level invisible to the values you see on the display, the binary representation of the floating point result of the log 1000 operation does not equal the binary representation of the value 3 you entered. 

To make a long story short...comparing for exact matches of floating point numbers is a very risky and problematic approach.  It's better to use an error margin such as

[blocks]
<(  <abs( (( log 1000 <-> 3 ))<<> 0.0001 )>
[/blocks]

Maybe we can try a variable(string)?

Offline

 

#4 2009-12-15 08:46:19

fanofcena
Scratcher
Registered: 2008-07-03
Posts: 1000+

Re: [log1000=3]false?

Nopes what paddle to see said is right its better to assign a variable it will auto remove float ( i dunno if its a bug with my PC)


http://i53.tinypic.com/2vxr2c0.png Click whats above u might make a cute planet happy ^_^

Offline

 

Board footer