lua-users home
lua-l archive

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


>>>>> "Guislain" == Guislain Duthieuw <guislain.duthieuw@gmail.com> writes:

 >> Obviously because normal division is always returning a float,
 >> whereas floor division between integers returns an integer.

 Guislain> I am not a Lua expert but I tested this :
 Guislain> =10.0//3
 Guislain> 3.0

10.0 is a float.

 Guislain> Does that show floor division can return a float ? (as the
 Guislain> manual says I think)

The manual says (emphasis mine):

    With the exception of exponentiation and float division, the
    arithmetic operators work as follows: IF BOTH OPERANDS ARE INTEGERS,
    the operation is performed over integers and the result is an
    integer. OTHERWISE, if both operands are numbers or strings that can
    be converted to numbers (see §3.4.3), then they are converted to
    floats, the operation is performed following the usual rules for
    floating-point arithmetic (usually the IEEE 754 standard), and THE
    RESULT IS A FLOAT.

    Exponentiation and float division (/) always convert their operands
    to floats and the result is always a float.

So 10.0//3 does not have both operands as integers so it is performed
over floats. But 10//3 has both integer operands and therefore an
integer result.

-- 
Andrew.