From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 23 16:29:30 2015 Received: (at submit) by debbugs.gnu.org; 23 Mar 2015 20:29:30 +0000 Received: from localhost ([127.0.0.1]:34190 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ya8yX-00014g-U1 for submit@debbugs.gnu.org; Mon, 23 Mar 2015 16:29:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38834) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Ya8yV-00014T-Jk for submit@debbugs.gnu.org; Mon, 23 Mar 2015 16:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ya8yP-00010p-Gm for submit@debbugs.gnu.org; Mon, 23 Mar 2015 16:29:22 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:53614) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya8yP-00010l-EG for submit@debbugs.gnu.org; Mon, 23 Mar 2015 16:29:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya8yO-0002AZ-9c for bug-gnu-emacs@gnu.org; Mon, 23 Mar 2015 16:29:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ya8yK-0000y1-6t for bug-gnu-emacs@gnu.org; Mon, 23 Mar 2015 16:29:20 -0400 Received: from [86.53.51.141] (port=46821 helo=snares-penguin.marcade.biz) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ya8yJ-0000xM-UX for bug-gnu-emacs@gnu.org; Mon, 23 Mar 2015 16:29:16 -0400 Received: by snares-penguin.marcade.biz (Postfix, from userid 1000) id EC7572A0B8E; Mon, 23 Mar 2015 20:29:13 +0000 (GMT) From: Bernard Hurley To: bug-gnu-emacs@gnu.org Subject: 24.4.50; problem with built-in function "ldexp" Emacs Ver: 24.4.50.1 X-Attribution: Bernard Date: Mon, 23 Mar 2015 20:29:13 +0000 Message-ID: <87y4mn4fvq.fsf@snares-penguin.marcade.biz> MIME-Version: 1.0 Content-Type: text/plain X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) (24.4.50) 3.2 Floating-Point Basics we read: ---------- snip ------------ -- Function: ldexp sig &optional exp This function returns a floating-point number corresponding to the significand SIG and exponent EXP. ----------snip ------------- However it is easy to verify that the second argument is not optional. For example: (ldexp 5.0) triggers the error: *** Eval error *** Wrong type argument: integerp, nil The code for ldexp in floatfn.c reads: ---------- snip --------------- DEFUN ("ldexp", Fldexp, Sldexp, 1, 2, 0, doc: /* Construct number X from significand SGNFCAND and exponent EXP. Returns the floating point value resulting from multiplying SGNFCAND (the significand) by 2 raised to the power of EXP (the exponent). */) (Lisp_Object sgnfcand, Lisp_Object exponent) { CHECK_NUMBER (exponent); return make_float (ldexp (XFLOATINT (sgnfcand), XINT (exponent))); } ---------- snip ------------- The declaration conforms to that in the manual but nothing seems to have been done to take into account what happens when `exp' is missing. It seems to me that there are two possibilities: EITHER: The declaration in floatfns.c is incorrect and should read: DEFUN ("ldexp", Fldexp, Sldexp, 1, 1, 0, .... In which case it will need to be changed and the manual will need to be changed accordingly. OR: `exp' is supposed to have a default value (0 say), when the code in floatfns.c should be changed accordingly. In this case it might still be a good idea to update the manual to explain that it has this value. From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 24 14:57:23 2015 Received: (at 20185-done) by debbugs.gnu.org; 24 Mar 2015 18:57:23 +0000 Received: from localhost ([127.0.0.1]:35257 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YaU0w-0006Di-IF for submit@debbugs.gnu.org; Tue, 24 Mar 2015 14:57:23 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:38857) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YaU0t-0006DQ-2L for 20185-done@debbugs.gnu.org; Tue, 24 Mar 2015 14:57:20 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 4856CA6003F; Tue, 24 Mar 2015 11:57:12 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id W28+rImDLULl; Tue, 24 Mar 2015 11:57:10 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id B2FB7A60001; Tue, 24 Mar 2015 11:57:10 -0700 (PDT) Message-ID: <5511B386.6010802@cs.ucla.edu> Date: Tue, 24 Mar 2015 11:57:10 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Bernard Hurley Subject: Re: 24.4.50; problem with built-in function "ldexp" Emacs Ver: 24.4.50.1 Content-Type: multipart/mixed; boundary="------------030003040505080407070709" X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 20185-done Cc: 20185-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This is a multi-part message in MIME format. --------------030003040505080407070709 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for catching that bug. While fixing it I noticed some related minor glitches with ldexp, so I installed the attached patch. --------------030003040505080407070709 Content-Type: text/x-patch; name="0001-Fix-minor-ldexp-issues.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Fix-minor-ldexp-issues.patch" >From 68a58397370381fd9b5d08f5cc16a5afa2b5fd26 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 24 Mar 2015 11:42:53 -0700 Subject: [PATCH] Fix minor ldexp issues * doc/lispref/numbers.texi (Float Basics): Improve ldexp documentation. * src/floatfns.c (Fldexp): Require 2 args. Avoid undefined behavior if the exponent is out of 'int' range. Improve documentation. Fixes: bug#20185 --- doc/lispref/ChangeLog | 4 ++++ doc/lispref/numbers.texi | 12 +++++++++--- src/ChangeLog | 7 +++++++ src/floatfns.c | 10 +++++----- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index a546306..9b1bbb3 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,3 +1,7 @@ +2015-03-24 Paul Eggert + + * numbers.texi (Float Basics): Improve ldexp documentation. + 2015-03-23 Eli Zaretskii * commands.texi (Event Input Misc): Fix incorrect usage of @code. diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi index 8d1d3a7..7b4a0a6 100644 --- a/doc/lispref/numbers.texi +++ b/doc/lispref/numbers.texi @@ -265,9 +265,15 @@ If @var{x} is a NaN, then @var{s} is also a NaN@. If @var{x} is zero, then @var{e} is 0. @end defun -@defun ldexp sig &optional exp -This function returns a floating-point number corresponding to the -significand @var{sig} and exponent @var{exp}. +@defun ldexp s e +Given a numeric significand @var{s} and an integer exponent @var{e}, +this function returns the floating point number +@ifnottex +@var{s} * 2**@var{e}. +@end ifnottex +@tex +@math{s 2^e}. +@end tex @end defun @defun copysign x1 x2 diff --git a/src/ChangeLog b/src/ChangeLog index 815c117..23f125c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2015-03-24 Paul Eggert + + Fix minor ldexp issues + * floatfns.c (Fldexp): Require 2 args. Avoid undefined behavior + if the exponent is out of 'int' range. Improve documentation. + Fixes: bug#20185 + 2015-03-24 Daniel Colascione * process.c (Fprocess_running_child_p): Return number identifier of diff --git a/src/floatfns.c b/src/floatfns.c index c68b9bd..072e857 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -185,14 +185,14 @@ If X is zero, both parts (SGNFCAND and EXP) are zero. */) return Fcons (make_float (sgnfcand), make_number (exponent)); } -DEFUN ("ldexp", Fldexp, Sldexp, 1, 2, 0, - doc: /* Construct number X from significand SGNFCAND and exponent EXP. -Returns the floating point value resulting from multiplying SGNFCAND -(the significand) by 2 raised to the power of EXP (the exponent). */) +DEFUN ("ldexp", Fldexp, Sldexp, 2, 2, 0, + doc: /* Return X * 2**EXP, as a floating point number. +EXP must be an integer. */) (Lisp_Object sgnfcand, Lisp_Object exponent) { CHECK_NUMBER (exponent); - return make_float (ldexp (XFLOATINT (sgnfcand), XINT (exponent))); + int e = min (max (INT_MIN, XINT (exponent)), INT_MAX); + return make_float (ldexp (XFLOATINT (sgnfcand), e)); } DEFUN ("exp", Fexp, Sexp, 1, 1, 0, -- 2.1.0 --------------030003040505080407070709-- From unknown Mon Jun 16 23:28:35 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 22 Apr 2015 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator