lua-users home
lua-l archive

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





On Wed, Jun 4, 2014 at 10:37 PM, Rena <hyperhacker@gmail.com> wrote:
On Wed, Jun 4, 2014 at 9:31 PM, Philipp Janda <siffiejoe@gmx.net> wrote:
Am 04.06.2014 18:48 schröbte Andrew Starks:

print(math.min(1,2), math.max(1,2))
--1.0, 2.0

I would have expected integers.

It's the same with strings:

    print(type(math.max("1", "2")))


-Andrew


Philipp





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.


It's a brave new world when...

local big = 2^63 -2 
local bigger = 2^63 -1
print((big < bigger) == (math.min(big, bigger) < math.max(big, bigger)))
--> false
local big = 2.0^63 -2 
local bigger = 2.0^63 -1
print((big < bigger) == (math.min(big, bigger) < math.max(big, bigger)))
--> true


I don't want to type too much opinion about this, lest this be something that just didn't make the cut for Work 2. I'll only say that the math library can be simple, but it has to be reasonably predictable. This would fall short of that, IMHO.


-Andrew