MOD function does not work! So be warned!

Rob Cozens rcozens at pon.net
Thu Apr 4 11:02:01 EST 2002


>MOD is strictly a binary comparison.

Michael, et al:

This gets back to the other issue: can anyone give me an example of 
non-Xtalk implementation of the mod operator that is not limited to 
integer/longint values?  Does anyone know if the Xtalk list has 
decreed that mod should not be limited to integers, and if so, why? 
Does SuperCard allow decimal arguments? Is it Scott's intention that 
mod be used on decimal values?

Or is the real issue here the failure of HyperTalk, MC, & RR 
documentation writers to add a line indicating only non-decimal 
arguments are legal?  The HC documentation just says "numbers", 
implying one could legally script something like "999.999 mod 
333.333".

OOPS! I just looked more closely at the MC User Guide description of mod:
   "number remainder after a div".  Now I look up one line and find 
"div   # integer divide (no fractional part)".  That's the best 
evidence I can find so far that mod was not meant to be used with 
fractional values; but I'll admit the language is vague enough that 
someone else might construe a different meaning.

If, as in all implementations I recall using, the mod operation is 
limited to whole numbers, it can be derived with integer math:

function myMod zaValue,zaBase
   return(zaValue-((zaValue div zaBase)*zaBase)))
end myMod

Regarding my last post on this subject, it occurred to me that if one 
missed Ian's original post, my reference to anyNumber mod 5 cannot = 
5 might be lost because it doesn't relate to the handler in my 
message.  I am referring to the results of Ian's original handler:

>on mouseup
>   put 235 into startPoint
>   put 255 into endPoint
>   put 0.1 into increment
>   put empty into msg
>   put startPoint into loop
>   repeat while loop<=endPoint
>     put loop && loop mod 5 & return after msg
>     add increment to loop
>   end repeat
>end mouseup
>
>It will output to the message box a list of numbers.  The loop counter is on
>each line followed by a space and the loop mod 5.
>
>Here's my output:
>
>235 0   <<<<---- correct
>235.1 0.1
>235.2 0.2
>235.3 0.3
><<SNIP>>
>240 5   <<<<---- wrong and impossible

Pick up on the "impossible", Michael: the mod operator blew it.
-- 

Rob Cozens
CCW, Serendipity Software Company
http://www.oenolog.com/who.htm

"And I, which was two fooles, do so grow three;
Who are a little wise, the best fooles bee."

from "The Triple Foole" by John Donne (1572-1631)



More information about the use-livecode mailing list