From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: Using the GNU GMP Library for Bignums in Emacs Date: Mon, 23 Apr 2018 13:26:22 -0700 Organization: UCLA Computer Science Department Message-ID: <2608106a-cb82-3e55-e1f1-8ea99a846e1d@cs.ucla.edu> References: <29f933ac-a6bf-8742-66a7-0a9d6d3e5a88@disroot.org> <83bmecy6fx.fsf@gnu.org> <0d3175d8-d996-651e-b221-71978bde3a65@cs.ucla.edu> <51e619e0-ee38-eb97-6c1d-0925b675290a@disroot.org> <8e12135a-0fcc-7aa3-d000-731d2f26d918@disroot.org> <87lgde9v0b.fsf@linux-m68k.org> <12e4d927-c3fd-933c-6b7c-5e5086b45622@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1524515072 31532 195.159.176.226 (23 Apr 2018 20:24:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 23 Apr 2018 20:24:32 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 Cc: Emacs development discussions To: Helmut Eller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 23 22:24:27 2018 Return-path: Envelope-to: ged-emacs-devel@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 1fAi0e-00083O-8H for ged-emacs-devel@m.gmane.org; Mon, 23 Apr 2018 22:24:24 +0200 Original-Received: from localhost ([::1]:55363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAi2l-00007Q-1q for ged-emacs-devel@m.gmane.org; Mon, 23 Apr 2018 16:26:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fAi2e-00007A-VX for emacs-devel@gnu.org; Mon, 23 Apr 2018 16:26:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fAi2b-0004R9-SM for emacs-devel@gnu.org; Mon, 23 Apr 2018 16:26:28 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:53624) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fAi2b-0004QL-Ls for emacs-devel@gnu.org; Mon, 23 Apr 2018 16:26:25 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 8F77B16004E; Mon, 23 Apr 2018 13:26:23 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id nQdz_jP3wAG7; Mon, 23 Apr 2018 13:26:22 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6175C160054; Mon, 23 Apr 2018 13:26:22 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id HpICo-Ame5Q0; Mon, 23 Apr 2018 13:26:22 -0700 (PDT) Original-Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 46B1216004E; Mon, 23 Apr 2018 13:26:22 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224819 Archived-At: On 04/23/2018 12:22 PM, Helmut Eller wrote: > If I read the code in in data.c correctly, than Emacs uses the > INT_MULTIPLY_WRAPV macro which boils down to the __builtin_mul_overflow. > Which indeed produces nice machine code. But the original question was > about ANSI C, which seems to require a division and 3 conditional jumps > for the range check (with gcc 6). Yes, in general INT_MULTIPLY_WRAPV does require a division on platforms that do not support overflow-checking builtins. In practice, though, this tends to not be an issue, as the major compilers are moving in the direction of supporting such builtins. > Does INT_MULTIPLY_WRAPV macro even perform fixnum overflow tests? No, it checks only for machine-level overflow. We could come up with a variant that does both machine-level and fixnum-level checking simultaneously; I'm not sure it's worth the trouble, though, as most arithmetic operations are addition and subtraction and for these, fixnum-level checking suffixes. > Anyway, I find it curios that the following two expression yield > different values: > > (* (* most-positive-fixnum 2) 1.0) => -2.0 > > (* most-positive-fixnum 2 1.0) => 4.611686018427388e+18 Cool, huh? That's done on purpose; see this Emacs commit: https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=0ae6bdee0085b05028108325b0a4ce979eadb24e The idea is to produce a floating-point answer that is more mathematically-correct, while sticking to Common Lisp-style rules for contagion and argument processing.