lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, Jun 21, 2010 at 4:22 PM, Shaun McVey <shaun.mcvey@gmail.com> wrote:
> I think my previous atttempt was rather premature.  Didn't look at all
> the tests...
>
> function math.between(a, b)
>   local max = math.max(a, b)
>   local min = math.min(a, b)
>   local diff = max - min
>   if diff == 0 then
>      return min;
>   else
>      return diff / 2 + min;
>   end
> end
>
> Can't see a function with this behaviour ever being added to the std lib though.

It's really just the average of two numbers, (x+y)/2. An averaging
function isn't such a bad idea, particularly if it takes an arbitrary
number of parameters (like Jeff Pohlmeyer's implementation in this
thread).

~Jonathan