lua-users home
lua-l archive

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

On 03/01/2022 19:28, Flyer31 Test wrote:
if in some furture version integer division // 1 would produce integer
result, this would be very nice.

Now only int // int produces integer, but float // int produces float,
which somehow is a bit "ugly" for the result of an integer division.

(I can of course write math.floor(2.5) instead of 2.5//1, but I
somehow would like the second writing much more...).

Mmm, funnily I never noticed this.

I'm an old timer (since Lua 5.1) user, and although I welcomed the new operators in Lua 5.3, I never used // much.

I really wonder why // produces a float at all. It would make sense to always produce an integer.

Just having the oddball case of just "// 1" producing an integer goes against the principle of least surprise and probably could slow things down: every time the engine needed to perform // it would have to check whether or not to convert its result according to its 2nd operand.

I'd rather prefer to change the semantics of // to always return an integer, unless someone convince me the current behavior is more useful. After all if you write "//" you probably want an integer, not a float with integer value.


-- Lorenzo