[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Suggestion: math.between()**
**From**: Jonathan Castello <twisolar@...>
**Date**: Mon, 21 Jun 2010 17:30:30 -0700

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