Issue with bit shift in Lua 5.4 Work releases

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with bit shift in Lua 5.4 Work releases

Jasper Klein
Hello lua-l!

This is my first post here and I'm not familiar with mailing lists.
With this post I want to bring up an issue that I've found in Lua 5.4 work  
releases.

The following three lines runs without errors in Lua 5.3.

local foo = 13.37
local bar = foo // 1
type( bar <<  8 )

The shift on the third line fails with Lua 5.4 with the following error:  
"number (local 'bar') has no integer representation".

It still fails with the error "attempt to perform bitwise operation on a  
nil value (local 'bar')" when 'bar' is explicit converted to an integer.

local foo = 13.37
local bar = math.tointeger( foo // 1 )
type( bar <<  8 )

Is this a bug or did I use the wrong method?


Jasper

Reply | Threaded
Open this post in threaded view
|

Re: Issue with bit shift in Lua 5.4 Work releases

Dirk Laurie-2
2018-07-06 17:37 GMT+02:00 Jasper Klein <[hidden email]>:

> Hello lua-l!
>
> This is my first post here and I'm not familiar with mailing lists.
> With this post I want to bring up an issue that I've found in Lua 5.4 work
> releases.
>
> The following three lines runs without errors in Lua 5.3.
>
> local foo = 13.37
> local bar = foo // 1
> type( bar <<  8 )
>
> The shift on the third line fails with Lua 5.4 with the following error:
> "number (local 'bar') has no integer representation".
>
> It still fails with the error "attempt to perform bitwise operation on a nil
> value (local 'bar')" when 'bar' is explicit converted to an integer.
>
> local foo = 13.37
> local bar = math.tointeger( foo // 1 )
> type( bar <<  8 )
>
> Is this a bug or did I use the wrong method?

The manual says: rounds the quotient towards minus infinity, that is,
the floor of the division of its operands, which does not happen, so
it is a bug.

It is interesting, though, that the metamethod-powered version:

bar = "13.37"//1

does give 13.

Reply | Threaded
Open this post in threaded view
|

Re: Issue with bit shift in Lua 5.4 Work releases

Roberto Ierusalimschy
In reply to this post by Jasper Klein
> The following three lines runs without errors in Lua 5.3.
>
> local foo = 13.37
> local bar = foo // 1
> type( bar <<  8 )
>
> The shift on the third line fails with Lua 5.4 with the following error:
> "number (local 'bar') has no integer representation".
>
> It still fails with the error "attempt to perform bitwise operation on a nil
> value (local 'bar')" when 'bar' is explicit converted to an integer.
>
> local foo = 13.37
> local bar = math.tointeger( foo // 1 )
> type( bar <<  8 )
>
> Is this a bug or did I use the wrong method?

It is a (stupid) bug, but not in bit shift:

> foo = 13.37
> print(foo // 1)     --> 13.7

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Issue with bit shift in Lua 5.4 Work releases

Dirk Laurie-2
2018-07-06 17:55 GMT+02:00 Roberto Ierusalimschy <[hidden email]>:

>> The following three lines runs without errors in Lua 5.3.
>>
>> local foo = 13.37
>> local bar = foo // 1
>> type( bar <<  8 )
>>
>> The shift on the third line fails with Lua 5.4 with the following error:
>> "number (local 'bar') has no integer representation".
>>
>> It still fails with the error "attempt to perform bitwise operation on a nil
>> value (local 'bar')" when 'bar' is explicit converted to an integer.
>>
>> local foo = 13.37
>> local bar = math.tointeger( foo // 1 )
>> type( bar <<  8 )
>>
>> Is this a bug or did I use the wrong method?
>
> It is a (stupid) bug, but not in bit shift:
>
>> foo = 13.37
>> print(foo // 1)     --> 13.7

When is a bug not stupid?

Reply | Threaded
Open this post in threaded view
|

Re: Issue with bit shift in Lua 5.4 Work releases

Roberto Ierusalimschy
> > It is a (stupid) bug, but not in bit shift:
> >
> >> foo = 13.37
> >> print(foo // 1)     --> 13.7
>
> When is a bug not stupid?

When it is not detectable by a minimum test?

For an example, see the other bug being discussed now, about the garbage
collector.

-- Roberto

Reply | Threaded
Open this post in threaded view
|

Re: Issue with bit shift in Lua 5.4 Work releases

Lorenzo Donati-3
In reply to this post by Dirk Laurie-2
On 06/07/2018 17:58, Dirk Laurie wrote:

> 2018-07-06 17:55 GMT+02:00 Roberto Ierusalimschy <[hidden email]>:
>>> The following three lines runs without errors in Lua 5.3.
>>>
>>> local foo = 13.37
>>> local bar = foo // 1
>>> type( bar <<  8 )
>>>
>>> The shift on the third line fails with Lua 5.4 with the following error:
>>> "number (local 'bar') has no integer representation".
>>>
>>> It still fails with the error "attempt to perform bitwise operation on a nil
>>> value (local 'bar')" when 'bar' is explicit converted to an integer.
>>>
>>> local foo = 13.37
>>> local bar = math.tointeger( foo // 1 )
>>> type( bar <<  8 )
>>>
>>> Is this a bug or did I use the wrong method?
>>
>> It is a (stupid) bug, but not in bit shift:
>>
>>> foo = 13.37
>>> print(foo // 1)     --> 13.7
>
> When is a bug not stupid?
>
>

It somewhat depends on your reaction when you find it.

Stupid bug:

"doh!!!" (*palm-face*)


Not-so-stupid bug:

"aha!!!"
(*mumbling: "I found you! You little dirty <add your favourite expletive
here>"*)


Of course this is somewhat relative: it depends on the "doh"-threshold
of the specific programmer with the specific language.

:-)

There are no bug-free programs.
Any program has at least one unavoidable big bug: its end-user.

:-D