develooper Front page | perl.perl5.porters | Postings from June 2015

Re: Coverity finding: shift by negative

Thread Previous | Thread Next
From:
Paul "LeoNerd" Evans
Date:
June 23, 2015 11:03
Subject:
Re: Coverity finding: shift by negative
Message ID:
20150623120235.3302164b@shy.leonerd.org.uk
On Mon, 22 Jun 2015 17:58:46 -0700
Jan Dubois <jand@activestate.com> wrote:

> > shift left by negative n == shift right by -n ?
> > shift right by negative n == shift left by -n?  
> 
> Yes, that's what I would expect a high-level language to do.
> 
> It also means that $a << $b == $a * 2**$b, even for negative $b, which
> is again something I naively expect. :)
> 
> I believe I once wrote $a << ($p-$q) and expected this generalized
> behaviour, but can't remember any context.

SGTM. This sort of DWIMery feels like the right approach, especially in
cases like your  << ($p-$q).

((In fact I think I already have one of those in a piece of C code I
recently wrote, that probably only works because $p is known larger
than $q in my case and both are compiletime constants.))

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk
http://www.leonerd.org.uk/  |  https://metacpan.org/author/PEVANS

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About