[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> floating point errors in MSWLogo



OOps - where is a tail of my mail ??

Do not blame Logo for bad addition....

We may also see additions, which give no effect. For example 1000000000.1+0.0000001 give as the result 1000000000.1 
We can use this effect to make some trick. Let's take a look on following procedure
(In this example global *makes* are applied intentionally, Yehuda - please don't extract them this time)

to xsum 
 make "a0 :a
 make "a :a0 + :delta
 make "b1 :a0 - :a
 make "b2 :b1 + :delta
 make "b :b2 + :b
end

You may say, that :a0 + :delta - :a0 - :delta  equals 0. This is true in arithmetic, but not on floating point computation. Small difference will be gathered in variable :b. Please repeat xsum 1640 times with :a0=0 :delta=0.02 (all other variables should start with 0 also) and take :a+:b as the result. You will get 32.8 exactly. With :delta about 0.000000001 

Best regards
Andrzej B.


---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home