[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: math.max
- From: Duncan Cross <duncan.cross@...>
- Date: Mon, 1 Aug 2011 15:07:13 +0100
On Mon, Aug 1, 2011 at 2:47 PM, Chris Datfung <email@example.com> wrote:
> I have a variable that contains numeric values separated by a comma, e.g.
> Values = "1, 7, 5". I want to figure out which value within that variable is
> the lowest and highest. The math.min and math.max functions seem most
> appropriate except that they wont accept a variable as an argument. Is this
> possible with the built in math functions or do I need to parse the variable
> and compare values with tonumber()?
It definitely isn't readily possible just with math functions. If your
'Values' string does not come from an untrusted source you could do
something a little hacky like this:
MaxValue = math.max(loadstring("return " .. Values)())
...otherwise, yes, you will need to parse it yourself.