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

Re: LOGO-L> 2180000000



At 17:19 28.12.1998 -0500, dajoy@hoy.net wrote:
>show (20000*20000)-(4*50000*-8900)
>-1380000000
>
>show difference (product 20000 20000) (product 4 50000 -8900)
>-1380000000
>
>
>What is the problem? Is 2180000000 too big a number?

This problem occurs in MSW Logo. In MicroWorlds and SuperLogo the result is
correct.
It seems to be an MSW Logo bug.
If the program (a version of Logo in this case) uses 32-bits to store
signed numbers then the maximum is 2147483648.
If the result of a computation with integral numbers exceedes this limit,
then the result is incorrect. 
This is well known to programmers in "typed" languages (Like C or Pascal
where the programmer can tell the compiler if a variable holds only
integral values or it can hold also fractions). As Logo is not typed, it
should try to re-compute the expression once more using floating point
operands each time when the result of a computation with integral numbers
overflows (it is implemented like this in SuperLogo).

Knowing all the above facts, a little trick helps:
If you write the first number 20000 as 20000.0 then the whole computation
is done in floating point numbers and the result is correct.

show 20000.0*20000-4*50000*-8900
2180000000



Regards

Peter Tomcsanyi

My favourite Logo:
http://www.logo.com/catalogue/titles/superlogo/index.html
http://www.edi.fmph.uniba.sk/logo/

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