GNU bug report logs -
#56641
Deprecate `lsh`
Previous Next
Full log
Message #38 received at 56641 <at> debbugs.gnu.org (full text, mbox):
20 juli 2022 kl. 05.20 skrev Po Lu <luangruo <at> yahoo.com>:
> It might be rare, but there's nothing wrong with using lsh for its
> intended purpose, which is handling negative numbers correctly in
> several different situations.
The purpose of `lsh` is not breaking old code. (It used to have a different purpose but it vanished when bignums were introduced.)
There is no reasonable use for it in new code. Even in the unlikely event of code that just happens to need that sort of quirky behaviour, it is much better implemented explicitly where it's used, in terms of `ash`.
> Byte-compiler warnings are supposed to point out problems. Using lsh is
> not a problem
You are right that most uses of `lsh` are perfectly innocuous but that's because they are used in a way where `ash` would give the same result. This is often true even when the return values of `lsh` and `ash` differ, as in
(logand (lsh x -16) #xff)
which would give the same result even for negative x if `lsh` were replaced with `ash`.
However there is a potential problem since the behaviour of `lsh` is strongly platform-dependent, and it's impossible to write correct code without taking that into account (consider replacing -16 with -24 above). Users may not be aware of how it works and mistakenly think it is the 'unsigned' or 'logical' shift that they know from other languages.
This bug report was last modified 2 years and 301 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.