From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jefferson Carpenter Newsgroups: gmane.emacs.devel Subject: Re: Using the GNU GMP Library for Bignums in Emacs Date: Sun, 3 Jun 2018 23:44:55 +0000 Message-ID: References: <29f933ac-a6bf-8742-66a7-0a9d6d3e5a88@disroot.org> <83bmecy6fx.fsf@gnu.org> <0d3175d8-d996-651e-b221-71978bde3a65@cs.ucla.edu> <42cbc5ab-2f02-4aa5-4b19-7b2357f91692@cs.ucla.edu> <1f58acbf-a7d8-bf4e-3d0e-a285515a22e6@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 1528069429 5243 195.159.176.226 (3 Jun 2018 23:43:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 3 Jun 2018 23:43:49 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 04 01:43:45 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 1fPcf2-0001HN-3s for ged-emacs-devel@m.gmane.org; Mon, 04 Jun 2018 01:43:44 +0200 Original-Received: from localhost ([::1]:36949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPch9-0007r6-7t for ged-emacs-devel@m.gmane.org; Sun, 03 Jun 2018 19:45:55 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38057) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fPcgV-0007qP-Oi for emacs-devel@gnu.org; Sun, 03 Jun 2018 19:45:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fPcgV-0004af-09 for emacs-devel@gnu.org; Sun, 03 Jun 2018 19:45:15 -0400 Original-Received: from mail-io0-x232.google.com ([2607:f8b0:4001:c06::232]:40239) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fPcgU-0004aU-QX for emacs-devel@gnu.org; Sun, 03 Jun 2018 19:45:14 -0400 Original-Received: by mail-io0-x232.google.com with SMTP id g22-v6so7802608iob.7 for ; Sun, 03 Jun 2018 16:45:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=G+7Iz5RftBzd1HqjNFvzHmTFunYAMnCjBS2YCAa0bxE=; b=laglFWK1rs/bjOWcNbUl2gXhmwETrG/kbQXup0EQbIX1U3BqRrn3sghCXT3hjpkdCS y3FcFv2S7fc3V4KRRRjhm45hko/oJ3HTyDGm63BHFLnAvuv3JghyrzWEW3QES33ORuAd Il2fSXuSGxAZoNKxy2rNhOQAoI7OEpPmUQqomErTAsxCzOSlXHSDb36NZG2YmrUcxJkJ /RfIwUJCxhxTvt+qMseM8Um3GGuLVtU/3cLXbPZT6veTVAXhw2Ja1TKGkncudBsraSNR Ay50KRpCX4wcsjcoSILPdG0CVMV0gLcQCkw7LiUvosevV5FvIxabIMSqJq0piuSsFlVQ q6Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=G+7Iz5RftBzd1HqjNFvzHmTFunYAMnCjBS2YCAa0bxE=; b=HIneLhMpWstTHD64vww+KHpR7McyXD5wCBscaovdIm7Ds+hIuEx8l5jf26SADWZQ8W B0va4jC5I+X46Z32UkW+K6YdcI4zVFFulttNyPDoYWxOyziiONsYWUoBZ2c6hD2VY1n1 CNxyRa2DS2oNCCGbYAyn7mTthllqolXVEZhUQcOe6K8V4SH9+Hv7bCf8onAxqgW7rXjx Rud7xKxYIENdh1JIZxmea6/EZTpRA5g+p5NG5HTmi2aGnIjBHrMSqr1CGjlrUJlXoe+r QL7vu4c6bmzAwwjnP+g041su7zPGCUQSlLCFV0CFuOGxT/zKVojW77UQCTW1J/tnV1wJ a2mQ== X-Gm-Message-State: ALKqPwfFvgE7GhWOHeMliLPSW4fONh8+O7QPohCav1ZUGh++1kMvdHBd jphAVAnOGlN1TBFcxWJwjAKDbaOS X-Google-Smtp-Source: ADUXVKL3C20is9ARB11ztC7TSWo/uDyqTFhqd7FJ8dHCsQKvC6Nxd/7zw6ZsL3oM7zFSxL013mwncg== X-Received: by 2002:a6b:8208:: with SMTP id e8-v6mr18626730iod.264.1528069513375; Sun, 03 Jun 2018 16:45:13 -0700 (PDT) Original-Received: from ?IPv6:2601:441:8680:4631:dd12:fc7d:bd62:9a80? ([2601:441:8680:4631:dd12:fc7d:bd62:9a80]) by smtp.gmail.com with ESMTPSA id p20-v6sm1874519itf.4.2018.06.03.16.45.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Jun 2018 16:45:12 -0700 (PDT) In-Reply-To: Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c06::232 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:225979 Archived-At: On 4/24/2018 5:45 AM, Helmut Eller wrote: > On Mon, Apr 23 2018, Paul Eggert wrote: > >> Even in the standard C library (which lacks bignums), the %x printf >> format is supposed to be used only with unsigned integers. Nowadays >> GCC even optionally warns about using %x on signed integers. > > Maybe %x should then print the (shortest) two's complement > representation for bignums. In Common Lisp: > > (defun 2comp (x) > (format nil "~x" (logand x (1- (ash 1 (+ 1 (integer-length x))))))) > > (2comp -1) => "1" > (2comp -2) => "2" > (2comp -3) => "5" > (2comp -15) => "11" > (2comp -16) => "10" > > In practice, only integers smaller than most-negative-fixnum would use > this rule. > > Helmut > > I don't think that would make sense, because you can't tell whether a given output string was generated from a positive or a negative number. For instance, (2comp -6) = (2comp 10) = "A". "Two's complement" isn't a representation of integers; "N-bit two's complement" is a representation of integers from -2^N to 2^N-1, for positive integer N. So, I think that function should take another argument, the number of bits `n` to output. Jefferson