From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Re: Merging bignum to master Date: Sun, 12 Aug 2018 10:34:29 -0600 Message-ID: <87a7prk0h6.fsf@tromey.com> References: <877ekwu1mn.fsf@tromey.com> <87o9e8oaot.fsf@tcd.ie> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1534096975 28463 195.159.176.226 (12 Aug 2018 18:02:55 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 12 Aug 2018 18:02:55 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) Cc: Tom Tromey , emacs-devel@gnu.org To: "Basil L. Contovounesios" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 12 20:02:51 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 1fouhU-0007Fm-4Z for ged-emacs-devel@m.gmane.org; Sun, 12 Aug 2018 20:02:48 +0200 Original-Received: from localhost ([::1]:35693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fouja-0004dE-M7 for ged-emacs-devel@m.gmane.org; Sun, 12 Aug 2018 14:04:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33444) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fouhi-0004TQ-4i for emacs-devel@gnu.org; Sun, 12 Aug 2018 14:03:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fougX-0002FC-TG for emacs-devel@gnu.org; Sun, 12 Aug 2018 14:02:57 -0400 Original-Received: from gateway21.websitewelcome.com ([192.185.46.121]:14088) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fougO-0002AP-M9 for emacs-devel@gnu.org; Sun, 12 Aug 2018 14:01:47 -0400 Original-Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway21.websitewelcome.com (Postfix) with ESMTP id D6AD74010E9EF for ; Sun, 12 Aug 2018 11:34:31 -0500 (CDT) Original-Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id otK3fVAaoRPojotK3fyOtJ; Sun, 12 Aug 2018 11:34:31 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=vrh/4l9JfkRfx+VVw+agO4at2Enp7Z+UGEZ/yqQ65NI=; b=QYUZZbD17cOyEiCEKX/sNJ2F4c D+igylRg2poMjkvg3Qg/k6Ytv2J9Jyf6D/7tTd939NOanUW94WTpU5RU2zOW55X6fGXSjebJc3Ne8 Kz5seLsFfot3E0wVTgaBWSKe4; Original-Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:57040 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fotK3-000jA5-G9; Sun, 12 Aug 2018 11:34:31 -0500 X-Attribution: Tom In-Reply-To: <87o9e8oaot.fsf@tcd.ie> (Basil L. Contovounesios's message of "Sun, 12 Aug 2018 00:28:02 +0300") X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.85.72 X-Source-L: No X-Exim-ID: 1fotK3-000jA5-G9 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-85-72.hlrn.qwest.net (bapiya) [75.166.85.72]:57040 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 192.185.46.121 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:228444 Archived-At: >>>>> "Basil" == Basil L Contovounesios writes: Basil> It'd be nice if expt could be updated to handle bignums: What do you think of this? Tom diff --git a/src/floatfns.c b/src/floatfns.c index bbf7df4db3..c55418a35c 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -206,25 +206,28 @@ DEFUN ("expt", Fexpt, Sexpt, 2, 2, 0, { CHECK_FIXNUM_OR_FLOAT (arg1); CHECK_FIXNUM_OR_FLOAT (arg2); - if (FIXNUMP (arg1) /* common lisp spec */ + if (INTEGERP (arg1) /* common lisp spec */ && FIXNUMP (arg2) /* don't promote, if both are ints, and */ && XFIXNUM (arg2) >= 0) /* we are sure the result is not fractional */ { /* this can be improved by pre-calculating */ - EMACS_INT y; /* some binary powers of x then accumulating */ - EMACS_UINT acc, x; /* Unsigned so that overflow is well defined. */ Lisp_Object val; + mpz_t x, *xp, r; - x = XFIXNUM (arg1); - y = XFIXNUM (arg2); - acc = (y & 1 ? x : 1); - - while ((y >>= 1) != 0) + if (BIGNUMP (arg1)) + xp = &XBIGNUM (arg1)->value; + else { - x *= x; - if (y & 1) - acc *= x; + mpz_init_set_si (x, XFIXNUM (arg1)); + xp = &x; } - XSETINT (val, acc); + + mpz_init (r); + mpz_pow_ui (r, *xp, XFIXNUM (arg2)); + + val = make_number (r); + mpz_clear (r); + if (xp == &x) + mpz_clear (x); return val; } return make_float (pow (XFLOATINT (arg1), XFLOATINT (arg2))); diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el index 7714c05d60..4fab032ecb 100644 --- a/test/src/floatfns-tests.el +++ b/test/src/floatfns-tests.el @@ -46,4 +46,8 @@ (should (= (+ (logb most-positive-fixnum) 1) (logb (+ most-positive-fixnum 1))))) +(ert-deftest bignum-expt () + (should (= (expt 10 100) + (apply #'* (make-list 100 10))))) + (provide 'floatfns-tests)