Coding challenge?

Thomas McGrath III 3mcgrath at adelphia.net
Mon May 30 21:51:37 EDT 2005


Well that was fun. I actually followed along nicely. I just wish when I 
am working with numbers that these things would come to mind. I tend to 
go the long way around and end up with a lot of extra code to boot.

Thank you for the explanations. I think they will help.

Tom


On May 30, 2005, at 8:56 PM, Dennis Brown wrote:

>
> On May 30, 2005, at 7:56 PM, Thomas McGrath III wrote:
>
>> I would like to see something graphic or animation based but would 
>> probably learn more from an SQL or XML challenge. You guys always 
>> blow me away with MOD and TRUNC etc. Since math is not to my 
>> advantage, I am rather visual in nature.
>>
>> TOm
>
> Tom,
>
> I am no math whiz either, but if you are you asking for an 
> explaination of the way I use Mod and Trunc, it is very simple:
>
> Trunc(number) is simply the integer function.  It hands you back the 
> number with any decimal portions thrown away (no rounding).  10.1 
> becomes 10 and 10.99999 becomes 10.
>
> Mod is the remainder function from a division.  It performs a division 
> and throws away the answer but hands you back the remainder.  10.99999 
> mod 10 is 0.99999.  10.99999/10 the answer is 1 with a remainder of 
> 0.99999.
>
> It is handy in loops if you want to see if a counter is at every Nth 
> count  --like every 11th time through the loop you want to do 
> something different.  You could say if loopCounter mod 11=0 then 
> doSomething.  The remainder will only be 0 if the loopCounter is an 
> even multiple of 11.  I use it in this way to update a field or check 
> for user aborts inputs in a long loop where I don't want to waste time 
> doing the UI stuff every time through the loop.
>
> It is also handy to do the opposite of the Trunc function --where you 
> want to throw away the whole number and keep the decimal portion.  In 
> this case anyNumber mod 1 will do the trick.  10.99999 mod 1 gives you 
> 0.99999.
>
> So:
>
> get 10.99999
> get trunc(it)&it mod 1 --take the number apart and put it back 
> together again
>
> it=10.99999
>
> Hope this helps,
> Dennis
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>

Thomas J. McGrath III
SCS
1000 Killarney Dr.
Pittsburgh, PA 15234
412-885-8541



More information about the use-livecode mailing list