unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#21901: bit shift wrong on maximal right shift
@ 2015-11-13 10:22 Zefram
  2016-06-20 16:02 ` Andy Wingo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Zefram @ 2015-11-13 10:22 UTC (permalink / raw)
  To: 21901

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#21901: bit shift wrong on maximal right shift
  2015-11-13 10:22 bug#21901: bit shift wrong on maximal right shift Zefram
@ 2016-06-20 16:02 ` Andy Wingo
  2018-10-14  9:40 ` Mark H Weaver
  2018-10-20 22:27 ` Mark H Weaver
  2 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2016-06-20 16:02 UTC (permalink / raw)
  To: Zefram; +Cc: 21901

On Fri 13 Nov 2015 11:22, Zefram <zefram@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#21901: bit shift wrong on maximal right shift
  2015-11-13 10:22 bug#21901: bit shift wrong on maximal right shift Zefram
  2016-06-20 16:02 ` Andy Wingo
@ 2018-10-14  9:40 ` Mark H Weaver
  2018-10-20 22:27 ` Mark H Weaver
  2 siblings, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2018-10-14  9:40 UTC (permalink / raw)
  To: Zefram; +Cc: 21901-done

Zefram <zefram@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#21901: bit shift wrong on maximal right shift
  2015-11-13 10:22 bug#21901: bit shift wrong on maximal right shift Zefram
  2016-06-20 16:02 ` Andy Wingo
  2018-10-14  9:40 ` Mark H Weaver
@ 2018-10-20 22:27 ` Mark H Weaver
  2 siblings, 0 replies; 4+ messages in thread
From: Mark H Weaver @ 2018-10-20 22:27 UTC (permalink / raw)
  To: Zefram; +Cc: 21901-done

Zefram <zefram@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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-20 22:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-13 10:22 bug#21901: bit shift wrong on maximal right shift Zefram
2016-06-20 16:02 ` Andy Wingo
2018-10-14  9:40 ` Mark H Weaver
2018-10-20 22:27 ` Mark H Weaver

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).