[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.3.0 (work2) now available
- From: Tim Hill <drtimhill@...>
- Date: Wed, 26 Mar 2014 14:36:58 -0700
On Mar 26, 2014, at 5:01 AM, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> As a side note, arithmetic shift is NOT equivalent to division by a power of two as the two functions have different rounding properties for negative dividends. Assuming you are using a C compiler that *does* do arithmetic shifts with signed operands, the following code will simulate integer division using shifts only:
>
> This is in C. In Lua both are equivalent; integer division in Lua rounds
> toward minus infinity, like an arithmetic shift.
>
> -- Roberto
>
Interesting, and a bit worrying. Is there any reason for this? I suspect this is going to be a source of confusion for some people porting code from C, as this can introduce subtle off-by-one bugs in algorithms.
—Tim
- References:
- [ANN] Lua 5.3.0 (work2) now available, Luiz Henrique de Figueiredo
- Re: [ANN] Lua 5.3.0 (work2) now available, Paul Baker
- Re: [ANN] Lua 5.3.0 (work2) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.3.0 (work2) now available, Coda Highland
- Re: [ANN] Lua 5.3.0 (work2) now available, Dirk Laurie
- Re: [ANN] Lua 5.3.0 (work2) now available, Coda Highland
- Re: [ANN] Lua 5.3.0 (work2) now available, Roberto Ierusalimschy
- Re: [ANN] Lua 5.3.0 (work2) now available, Tim Hill
- Re: [ANN] Lua 5.3.0 (work2) now available, Enrico Colombini
- Re: [ANN] Lua 5.3.0 (work2) now available, Tim Hill
- Re: [ANN] Lua 5.3.0 (work2) now available, Roberto Ierusalimschy