GNU bug report logs - #21901
bit shift wrong on maximal right shift

Previous Next

Package: guile;

Reported by: Zefram <zefram <at> fysh.org>

Date: Fri, 13 Nov 2015 10:23:02 UTC

Severity: normal

Done: Mark H Weaver <mhw <at> netris.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21901 in the body.
You can then email your comments to 21901 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#21901; Package guile. (Fri, 13 Nov 2015 10:23:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zefram <zefram <at> fysh.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Fri, 13 Nov 2015 10:23:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zefram <zefram <at> fysh.org>
To: bug-guile <at> gnu.org
Subject: bit shift wrong on maximal right shift
Date: Fri, 13 Nov 2015 10:22:03 +0000
With Guile 2.0.11:

scheme@(guile-user)> (ash 123 (ash -1 63))
$1 = 123

Correct result would of course be zero.  Problem only occurs for
exactly this shift distance: one bit less produces the right answer.
Problem also occurs on Guile 1.8.8.  Looking at the implementation,
the problem is attributable to the negation of the shift distance,
which in twos-complement fails to produce the expected positive result.

Note the resemblance to bug #14864, fixed in 2.0.10.  This bug is of
very similar form, but is distinct.  The test cases of #14864 pass for
me on the 2.0.11 that shows the problem with a 2^63 bit shift.  My bug
does occur with the rnrs bitwise-arithmetic-shift-right, which was used
in #14864, as well as with ash.

-zefram




Information forwarded to bug-guile <at> gnu.org:
bug#21901; Package guile. (Mon, 20 Jun 2016 16:03:01 GMT) Full text and rfc822 format available.

Message #8 received at 21901 <at> debbugs.gnu.org (full text, mbox):

From: Andy Wingo <wingo <at> pobox.com>
To: Zefram <zefram <at> fysh.org>
Cc: 21901 <at> debbugs.gnu.org
Subject: Re: bug#21901: bit shift wrong on maximal right shift
Date: Mon, 20 Jun 2016 18:02:50 +0200
On Fri 13 Nov 2015 11:22, Zefram <zefram <at> fysh.org> writes:

> With Guile 2.0.11:
>
> scheme@(guile-user)> (ash 123 (ash -1 63))
> $1 = 123
>
> Correct result would of course be zero.  Problem only occurs for
> exactly this shift distance: one bit less produces the right answer.
> Problem also occurs on Guile 1.8.8.  Looking at the implementation,
> the problem is attributable to the negation of the shift distance,
> which in twos-complement fails to produce the expected positive result.
>
> Note the resemblance to bug #14864, fixed in 2.0.10.  This bug is of
> very similar form, but is distinct.  The test cases of #14864 pass for
> me on the 2.0.11 that shows the problem with a 2^63 bit shift.  My bug
> does occur with the rnrs bitwise-arithmetic-shift-right, which was used
> in #14864, as well as with ash.

Fascinating, thank you!  Also occurs on 2.1.3.

Andy




Reply sent to Mark H Weaver <mhw <at> netris.org>:
You have taken responsibility. (Sun, 14 Oct 2018 09:42:02 GMT) Full text and rfc822 format available.

Notification sent to Zefram <zefram <at> fysh.org>:
bug acknowledged by developer. (Sun, 14 Oct 2018 09:42:02 GMT) Full text and rfc822 format available.

Message #13 received at 21901-done <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: Zefram <zefram <at> fysh.org>
Cc: 21901-done <at> debbugs.gnu.org
Subject: Re: bug#21901: bit shift wrong on maximal right shift
Date: Sun, 14 Oct 2018 05:40:51 -0400
Zefram <zefram <at> fysh.org> writes:

> With Guile 2.0.11:
>
> scheme@(guile-user)> (ash 123 (ash -1 63))
> $1 = 123
>
> Correct result would of course be zero.  Problem only occurs for
> exactly this shift distance: one bit less produces the right answer.

Nice catch!

It's finally fixed in commit 1990aa916382d0afcebd5315a6d6f555949ff654 on
the stable-2.2 branch.  The fix will be in Guile 2.2.5.

Thanks for the report.

      Mark




Information forwarded to bug-guile <at> gnu.org:
bug#21901; Package guile. (Sat, 20 Oct 2018 22:28:01 GMT) Full text and rfc822 format available.

Message #16 received at 21901-done <at> debbugs.gnu.org (full text, mbox):

From: Mark H Weaver <mhw <at> netris.org>
To: Zefram <zefram <at> fysh.org>
Cc: 21901-done <at> debbugs.gnu.org
Subject: Re: bug#21901: bit shift wrong on maximal right shift
Date: Sat, 20 Oct 2018 18:27:07 -0400
Zefram <zefram <at> fysh.org> writes:

> With Guile 2.0.11:
>
> scheme@(guile-user)> (ash 123 (ash -1 63))
> $1 = 123

Fixed in commit 1990aa916382d0afcebd5315a6d6f555949ff654 on the
stable-2.2 branch.  Closing this bug now.

Thanks very much for finding this subtle bug.

      Mark




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 18 Nov 2018 12:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 5 years and 161 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.