New Math

Marty Knapp martyknapp at comcast.net
Sat Feb 18 20:51:28 EST 2012


Cool. Thanks everyone for your responses, I think I'm good to go.

Marty
> Not exactly one line, but this works for all the combinations I could think
> of:
>
> function incTo x,i -- increments x to the next i
>     if i = 0 then
>        return x
>     else if x mod i<>  0 and x * i<  0 then
>        return x div i * i
>     else
>        return x div i * i + i
>     end if
> end incTo
>
> Here's my test results. First column is x, second is i, third is expected
> result, fourth is actual result, fifth is whether test passed:
>
> 30 20 40 40 true
> 20 20 40 40 true
> 30 -20 20 20 true
> 40 -20 20 20 true
> -30 20 -20 -20 true
> -20 20 0 0 true
> -30 -20 -40 -40 true
> -20 -20 -40 -40 true
> 0 20 20 20 true
> 0 -20 -20 -20 true
> -30 0 -30 -30 true




More information about the use-livecode mailing list