lua-users home
lua-l archive

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


I did uncover a misunderstanding that I had in my last email.

C:\>lua
Lua 5.3.1  Copyright (C) 1994-2015 Lua.org, PUC-Rio
> 2 // 3
0
> 63 // 4
15
> 63 // 4.0
15.0
> 64 // 4.0
16.0
> 63.0 // 4.0
15.0
> 63.0 / 4
15.75
> 63 / 4
15.75
> 63.1 // 4.0
15.0

This snippet shows that // does indeed do integer division, and does appear to convert the operands to integer. But in the case that one or both of the operands are formatted as floats, the result is formatted as a float. The result always has a ".0" appended, which threw me off initially.

So this appears to be more of a "quirk" than a "bug."



On Wed, Nov 25, 2015 at 9:40 AM, Howard Lee Harkness <howard@howardleeharkness.com> wrote:

From page 18 of a PDF at http://www.lua.org/wshop14/Ierusalimschy.pdf, Professor Ierusalimschy states: "Integer division converts operands to integers and does an integer division."

However, the following examples using Lua 5.3.1 interactively, show that either there is something about this I don't understand, or the preceding statement is not correct:

C:\>lua
Lua 5.3.1  Copyright (C) 1994-2015 Lua.org, PUC-Rio

> 1//1
1
> 3.0//2
1.0

> 3.0 // 3.0
1.0
> 3 // 2
1
> 2.0//2
1.0
> 2 // 2.0
1.0
> 6.0 // 1
6.0

These examples show that the operands of // are *not* converted to integer, and in the case of non-integer operands, // does not do an integer division unless both operands are in integer form.

Am I just misunderstanding something basic, or is this actually a bug?


Howard Lee Harkness