[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Wishful request for next version: '// 1' should produce integer
- From: Francisco Olarte <folarte@...>
- Date: Fri, 7 Jan 2022 15:45:29 +0100
On Fri, 7 Jan 2022 at 10:49, Flyer31 Test <email@example.com> wrote:
> There might appear a problem if the float is above int range, so e. g.
> 1E40 // 1... in Lua32 or 1E80//1 in Lua64.
> But I think if somebody does this, its somehow "own fault" ...
> handling int's anyway is somehow always "somehow a bit dangerous
> concerning overflow issues", but I think this is somehow clear to any
> user using int's. Usually int's are used for "speed or numerical
> optimization", or for "bit operations witchcraft" ... and the users
> who want this are somehow "aware of the risks", such users typically
> clearly prefer speed against any "overflow security guarding".
It will never occur to anyone using ints, 1E80 is not an int, it is a
float, whose integer value is equal to itself and not representable in
The problems you encounter only occur when people manage their numbers
carelessly and store ints as floats. If you are working with ints, //
works as expected and returns an int. People who work with ints would
check before introducing data from a float into the pipeline (at least
//1 to produce an integer is not too useful, just do tointeger. If you
are working with integers it works reasonably.
The oddest thing, for me, is that in lua 8/3 is done as 8.0 / 3.0,
while 8*3 is not, It's / which seems to be a martian, not //, but I'm
used to it:
> print(123456789123456789*100000000, 123456789123456789/100000000, 123456789123456789//100000000)
-7473169249324075776 1234567891.2346 1234567891
I just avoid doing calculations in Lua.