MOD function does not work! So be warned!
Dar Scott
dsc at swcp.com
Sun Mar 31 12:55:01 CST 2002
On Sunday, March 31, 2002, at 09:00 AM, Richard Gaskin wrote:
> Interestingly, when you type "put 5 mod 5" (or "255 md 5" or
> other number
> divisible by five that fails when inside a loop) into the Message
> Box the
> result is 0.
>
> Stranger still, if you rewrite the line like this so that the loop
> var is
> evaluated outside of the rest of the statement:
>
> do "put loop &tab&"& loop &&"mod 5 & return after msg"
>
> ...you get 0.
>
> What is it about loops that affects this so?
>
> :\
It is not the loop, it is addition. Every Revolution number (a
priori) has a potential error. This accumulates. (I say "a
priori" because some numbers, can be represented exactly.)
Worse, when two numbers are added, information in the smaller
number is thrown away. In the extreme case, no matter how many
times you add a very small number to a larger, it doesn't change.
In the "do" example, the value of loop is rounded by the default
value of numberFormat when the "do" string is created. That seems
to be enough to make the result close enough to look like a whole
multiple of 5.
When such results are "interesting" and "strange"...
Dar Scott
More information about the use-livecode
mailing list