From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Pip Cet Newsgroups: gmane.emacs.bugs Subject: bug#32463: 27.0.50; (logior -1) => 4611686018427387903 Date: Fri, 17 Aug 2018 11:36:06 +0000 Message-ID: References: <86mutll4w2.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1534505711 7308 195.159.176.226 (17 Aug 2018 11:35:11 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 17 Aug 2018 11:35:11 +0000 (UTC) Cc: 32463@debbugs.gnu.org To: andrewjmoreton@gmail.com, eggert@cs.ucla.edu Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Aug 17 13:35:07 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fqd22-0001jt-A9 for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 Aug 2018 13:35:06 +0200 Original-Received: from localhost ([::1]:33140 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqd46-00005Q-Vl for geb-bug-gnu-emacs@m.gmane.org; Fri, 17 Aug 2018 07:37:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqd3z-0008WL-FQ for bug-gnu-emacs@gnu.org; Fri, 17 Aug 2018 07:37:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqd3u-0000VO-5g for bug-gnu-emacs@gnu.org; Fri, 17 Aug 2018 07:37:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48271) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fqd3u-0000V6-16 for bug-gnu-emacs@gnu.org; Fri, 17 Aug 2018 07:37:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1fqd3t-0006B1-RU for bug-gnu-emacs@gnu.org; Fri, 17 Aug 2018 07:37:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Pip Cet Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 17 Aug 2018 11:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32463 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32463-submit@debbugs.gnu.org id=B32463.153450581223728 (code B ref 32463); Fri, 17 Aug 2018 11:37:01 +0000 Original-Received: (at 32463) by debbugs.gnu.org; 17 Aug 2018 11:36:52 +0000 Original-Received: from localhost ([127.0.0.1]:53289 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fqd3j-0006Ad-KU for submit@debbugs.gnu.org; Fri, 17 Aug 2018 07:36:51 -0400 Original-Received: from mail-lf1-f53.google.com ([209.85.167.53]:37540) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fqd3h-0006AR-Uz for 32463@debbugs.gnu.org; Fri, 17 Aug 2018 07:36:50 -0400 Original-Received: by mail-lf1-f53.google.com with SMTP id j8-v6so5668101lfb.4 for <32463@debbugs.gnu.org>; Fri, 17 Aug 2018 04:36:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oDVvIQR2+JDaSPRT5z6il0fZMHxY4E534OQu0+Lbhrw=; b=RYjWI5BJtSH+lxNi3SNBPoR7Fq9nL5RSS9OjwiqVD6za1s2jJRPLT6GwkXBcXQ+tTO LKjFRlzN/8G1wXHwGAYKHrBfh/SWrKgzmBVbeN1PgF7oB7j8hSzRpWI5VeYaYu5x3Vfb RPJnTbTUwFeLSEEcO5nrzxPJwC4u7TRKBlzOy4a/lzwUvn89tCkpWM0mykEkQLVWXush 7sFbqokk9IaTRIh6RsYdsqAta6oZERa0OL3ynWSQIBnbVu+eiAplSb090rgcsmQPTZbU UL6rYFWuevcSocQOux6L+bofe3+Bhu8iLbkYiwcN27ZT+ZEmbJZtN1N9Y/5u+gQ/j4oT h2YA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oDVvIQR2+JDaSPRT5z6il0fZMHxY4E534OQu0+Lbhrw=; b=pny7jrZIAGKqn+bDO3cQ0P+eMwJqMDSnHCGfwzXqQO5wgLdXqWyJync9tVgIf+hy0W vbGE+C1RqBeMVfFFOsnz8ufdI9JVclYIWdaCbgEbp/Sp24Tk8RV4WrX4MwVoIDkW+fqY 8smfDRLqAlScOq/Ms3qg0uhxiCkIuzlL7dlOVg/z8RO5CIgZy06KcSnY5bVUOxtJlRT6 gnDWbqbD7Ddfv9st/CZ0npwULQIVOWXJvT7W4yAosz3YaciaojzJzlmPH3zoItT1ccW5 9tTgad0QGwjcjBbjHbM9EXmsoqtFbMLWFYH89XgfJkcjo+vslMOrEGhO6f3y64a/S6FJ rbGQ== X-Gm-Message-State: AOUpUlHBy1x6E0bQLusy4XInLz9gRJFq206U2mC4hBJf1eA3W4cCkwCa isf7Oq/DUd4erjAZ4HCXz1Op3HmjU6uwIL5UVaw= X-Google-Smtp-Source: AA+uWPzQBDUlRoXqMwjhUnxSjO/xr3abySFD6+GQL/5ZwoRJ32FJgppfuaz2GeuBFzTvLkuXAVXy4zr0KZjUrww7S+4= X-Received: by 2002:a19:a5c5:: with SMTP id o188-v6mr22013547lfe.149.1534505804066; Fri, 17 Aug 2018 04:36:44 -0700 (PDT) In-Reply-To: <86mutll4w2.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:149552 Archived-At: On Fri, Aug 17, 2018 at 9:34 AM Andy Moreton wrote: > > On Fri 17 Aug 2018, Pip Cet wrote: > > > Can you try the attached patch? It fixes a few things that I reported > > to Tom yesterday: > > > > --- > > > > > > None of these are necessarily bugs, but: > > > > * I find the behavior of `lsh', `logand', `logior', and `logxor', when > > given negative arguments, surprising. I think it would make most sense > > to treat negative numbers as the infinite bitstream consisting of all > > ones to the left of the specified value: > > > > (logand -1 -1) would be interpreted as ...1111111 & ...1111111 = > > ...1111111, so it would be -1 (rather than 2 * most-positive-fixnum + > > 1). > > (lsh (- (lsh -1 64) 1) -1) would be ...1110111...1111 shifted to the > > right by one digit, an odd number, rather than the even number > > currently produced. (I believe lsh and ash should behave identically.) > > > @@ -3383,8 +3383,6 @@ ash_lsh_impl (Lisp_Object value, Lisp_Object count, bool lsh) > > mpz_init (result); > > if (XFIXNUM (count) >= 0) > > mpz_mul_2exp (result, XBIGNUM (value)->value, XFIXNUM (count)); > > - else if (lsh) > > - mpz_tdiv_q_2exp (result, XBIGNUM (value)->value, - XFIXNUM (count)); > > else > > mpz_fdiv_q_2exp (result, XBIGNUM (value)->value, - XFIXNUM (count)); > > val = make_number (result); > > @@ -3401,14 +3399,7 @@ ash_lsh_impl (Lisp_Object value, Lisp_Object count, bool lsh) > > Please add more test cases to test/src/data-tests.el to ensure that the > logical operations have the expected behaviour for positive and negative > arguments, and for both bignum and fixnum arguments. Paul committed a patch in the meantime (independently, I think?) which does add tests. I'll try to write some more. > The tdiv/fdiv were > added to give expected results. Pay particular attention to values around > most-positive-fixnum and most-negative-fixnum. I don't think they do give the expected results. We should discuss that in more detail, but first, can we agree that lsh and ash behave the same for bignums? If so, clearly one branch of the code you quoted is incorrect, and I think it's the tdiv one. I ran: (require 'cl) (let ((i 0)) (while (< i 128) (message "%d %x" i (lsh (- (lsh -1 i) 1) -1)) (incf i))) and got this output: [...] 57 -100000000000001 58 -200000000000001 59 -400000000000001 60 -800000000000001 61 -1000000000000000 62 -2000000000000000 63 -4000000000000000 64 -8000000000000000 [...] Something is wrong there. The expression certainly shouldn't switch from being odd to being even just because we're leaving the fixnum range. If I do the calculation by hand on a piece of paper, I get the results that correspond to the fixnum case, not the bignum case.