[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Variable representation in StarLogo
- Date: Wed, 18 Jun 1997 10:41:09 +0100
- From: "Miklos Gyorgy" <MIKLOS@ttt-atm.ttt.bme.hu>
- Subject: Variable representation in StarLogo
Hello,
I would like to ask the StarLogo creators at MIT to write a bit more
about how variables are represented.
In the reference manual I could read this:
> In StarLogo, numbers range from -32768.0 (minnum) to
> 32767.99998 (maxnum). If you restrict calculations to
> observer commands, you will get much more precision
> than using numbers in turtles and patches. (Note: In
> turtles and patches, numbers are represented as 16 bits of
> integer and 16 bits of decimal.)
I am not sure if I understand that 16 bits of decimal. Does it mean
that the integer part of a number is stored separately in 16
bit binary format, while the fractional part is stored up to 4
decimal digits in Binary Coded Decimal (BCD) format, with 4 bits
given to each decimal digit?
And the questions remain: what is the difference in variable
representation between observer and turtles/patches? What is the
difference between integer and real number representation?
And are there other things that limit precision apart from number
representation?
I faced with those questions when I wanted to have turtles uniformly
distributed over the interior of a circle. I wanted to transform the
uniform distribution on [0,1) with the sqrt function and so I wrote
this:
ca
crt 1000
fd 50 * sqrt((random 1000) / 1000)
Much to my surprise, it produced uniform distribution in the middle
but farther from the center rings emerged. (It suggests that
precision is much less than four digits.)
It took me a while to realize the cause, that turtles use less
precise (and faster) computation routines than the observer. (Using
`show' to inspect the argument of `fd' gives satisfactory numbers.)
The solution is to rephrase it:
fd sqrt(random 2500)
works fine.
I think in general the limitations to precision could usually be
overcome by properly rephrasing the expressions. For this, a little
knowledge on how StarLogo works would help.
Cheers,
Gyorgy
P.S. I used Starlogo 1.5 for the above programs, but I think these
things didn't change in 2.0.