lua-users home
lua-l archive

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

On Jun 4, 2014, at 8:37 PM, Rena <> wrote:

> I'd be very surprised if math.max(a, b) behaved any differently from:
> function max(a, b)
>     if a > b then return a
>     else return b
>     end
> end
> i.e. no changing of types involved (and for that matter, not caring at all about types, as long as the operands have > defined).
> (Of course it's slightly trickier since math.max() accepts any number of values except zero, but the principle is the same.)
> -- 
> Sent from my Game Boy.

I think the problem here is the historical placement of min/max in the math library. If Lua had global min() and max() functions then I suspect most people would expect what you say to be true, allowing for polymorphic min/max functions (for any type that defined < or __le). However, placement in the math library seems kinda-sorta to suggest that they work as floating point in keeping with the rest of this library.

If it were me, I’d go with the polymorphic form, but I doubt that this will happen.