lua-users home
lua-l archive

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


Just saw this.

I guess that clears up my misunderstanding, but I still regard an operation called "integer division" which sometimes returns a result of type "float" to be counterintuitive. Fortunately, it does not appear to matter for the application I'm currently working on. Plus, now that I know about this quirk, I can work around it.

On Nov 25, 2015 10:06, "Roberto Ierusalimschy" <roberto@inf.puc-rio.br> 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?

That talk was given before Lua 5.3 was released, and some details in
those slides were outdated.  Between the talk and the release, the
operation changed from "integer division" to "floor division".

-- Roberto