lua-users home
lua-l archive

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


On Mon, 17 Nov 2014 19:42:52 -0200
Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:

> (What is the "expected result" of 4.5//1.5 or -5.2|-1.3?)
> 
> -- Roberto


I have a question:

Is there any problem defining x//y := math.floor(x/y) for all cases
where either x or y are not integral?

This seems to be most intuitive and allows usage of the // operator not
only for integral floats but also for non-integral numbers that have a
proper representation as float, i.e. "halfs", "quarters" etc.

That is, x//y == (x/2^n) // (y/2^n) as well as
x//(y/2^n) == x//y * math.tointeger(2^n) for integral n.

In particular it would be easy to floor a floating point number with the
following idiom: i//1


Kind Regards
Jan Behrens