Math problem

Bob Sneidar bobs at twft.com
Fri Feb 17 17:24:05 EST 2012


Thanks for that Paul!

Bob


On Feb 17, 2012, at 2:03 PM, Paul Dupuis wrote:

> Well Bob, here is one more:
> 
> -- countTheHour with NO IF statements, proper rounding, and a single
> calculation line
> -- pIncrement is in seconds, so 900 equals 15 minutes increments. The
> default (by the max function) is 1 minute (60 seconds)
> -- 1 second in 1 hour is 1/3600 or 0.000278, so the roundUp adjustment
> only needs 4 decimal places of precision i.e. 0.4999
> 
> FUNCTION countTheHours pStartTime, pEndTime, pIncrement
>  TRY
>    convert pStartTime to seconds
>    convert pEndTime to seconds
>    put ( round(((pEndTime-pStartTime)/ max(pIncrement,60))+0.4999,0) /
> (3600/max(pIncrement,60)) ) into theResult
>  CATCH theError
>    put "ERROR: Not a valid time!" into theResult
>  END TRY
>  return theResult
> END countTheHours
> 
> 
> On 2/17/2012 4:21 PM, Bob Sneidar wrote:
>> Thanks all. Some ingenious ways of going about it. Never ceases to amaze me when I see all the ways of doing something when I thought there was only 1. :-)
>> 
>> Bob
>> 
>> 
>> On Feb 17, 2012, at 11:49 AM, Peter M. Brigham, MD wrote:
>> 
>>> On Feb 17, 2012, at 12:20 PM, Geoff Canyon Rev wrote:
>>> 
>>>> function roundUp x,i -- rounds x up to the next i
>>>> return ((x - .00001) div i + 1) * i
>>>> end roundUp
>>> Works except for values like 4.000000001.
>>> 
>>> Try this instead. It's a sort of a trick to avoid using a conditional construction, though the logic is conditional in structure, but does it in one line. I couldn't find a way of doing it using just LC's math functions, maybe someone else can.
>>> 
>>> function roundUp x
>>>  return trunc(x) + char itemoffset((x mod 1 > 0),"true,false") of "10"
>>> end roundUp
>>> 
>>> -- Peter
>>> 
>>> Peter M. Brigham
>>> pmbrig at gmail.com
>>> http://home.comcast.net/~pmbrig
>>> 
>>> 
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
>> _______________________________________________
>> use-livecode mailing list
>> use-livecode at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>> 
> 
> -- 
> Paul Dupuis
> Cofounder
> Researchware, Inc.
> http://www.researchware.com/
> http://www.twitter.com/researchware
> http://www.facebook.com/researchware
> http://www.linkedin.com/company/researchware-inc
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list