From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#21690: (/ N) should return the reciprocal of N Date: Thu, 15 Oct 2015 12:11:03 -0700 Organization: UCLA Computer Science Department Message-ID: <561FFA47.6020401@cs.ucla.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------080800050905010008050404" X-Trace: ger.gmane.org 1444936371 25988 80.91.229.3 (15 Oct 2015 19:12:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 15 Oct 2015 19:12:51 +0000 (UTC) To: 21690@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 15 21:12:38 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Zmnx1-0005Eb-4U for geb-bug-gnu-emacs@m.gmane.org; Thu, 15 Oct 2015 21:12:31 +0200 Original-Received: from localhost ([::1]:49271 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmnx0-0004YA-CT for geb-bug-gnu-emacs@m.gmane.org; Thu, 15 Oct 2015 15:12:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37161) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmnwc-0004X3-UT for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:12:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZmnwY-00040r-JZ for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:12:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:33678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZmnwY-00040n-Fs for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZmnwY-0007VF-5o for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Oct 2015 19:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21690 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: GNU Emacs bug reports Original-Received: via spool by submit@debbugs.gnu.org id=B.144493628228788 (code B ref -1); Thu, 15 Oct 2015 19:12:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Oct 2015 19:11:22 +0000 Original-Received: from localhost ([127.0.0.1]:52619 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zmnvt-0007UF-Jh for submit@debbugs.gnu.org; Thu, 15 Oct 2015 15:11:22 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:55273) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zmnvq-0007U6-Ou for submit@debbugs.gnu.org; Thu, 15 Oct 2015 15:11:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zmnvo-0003mX-V4 for submit@debbugs.gnu.org; Thu, 15 Oct 2015 15:11:18 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:40804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmnvo-0003mK-Ry for submit@debbugs.gnu.org; Thu, 15 Oct 2015 15:11:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmnvm-0004VU-Bh for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:11:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zmnvi-0003kR-7H for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:11:14 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:33921) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zmnvh-0003kK-VB for bug-gnu-emacs@gnu.org; Thu, 15 Oct 2015 15:11:10 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B5FA7160CB6 for ; Thu, 15 Oct 2015 12:11:08 -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 V1RkKB99VL9X for ; Thu, 15 Oct 2015 12:11:07 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id EA793160D3D for ; Thu, 15 Oct 2015 12:11:06 -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 BLA-w24GGdby for ; Thu, 15 Oct 2015 12:11:06 -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 AD4C1160CB6 for ; Thu, 15 Oct 2015 12:11:06 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:107655 Archived-At: This is a multi-part message in MIME format. --------------080800050905010008050404 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Tags: patch The attached proposed patch is a followup to the recent discussion on emacs-devel. We're in feature-freeze now, so it's not a good time to apply it. Although I'm sympathetic to Stefan's point that the Common Lisp behavior is less logical, it is more useful in practice (as can be seen from some uses in the proposed patch) and there is a benefit to being compatible with CL. --------------080800050905010008050404 Content-Type: text/x-patch; name="0001-N-now-returns-the-reciprocal-of-N.patch" Content-Disposition: attachment; filename="0001-N-now-returns-the-reciprocal-of-N.patch" Content-Transfer-Encoding: quoted-printable >From b512e3a7a814eba4f09c11c3aad6d96ea6d0ae7c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 15 Oct 2015 12:05:35 -0700 Subject: [PATCH] (/ N) now returns the reciprocal of N MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit This is more compatible with Common Lisp and with XEmacs. See: http://lists.gnu.org/archive/html/emacs-devel/2015-10/msg01053.html * lisp/color.el (color-hue-to-rgb, color-hsl-to-rgb) (color-xyz-to-srgb, color-xyz-to-lab): * lisp/emacs-lisp/cl-extra.el (cl-float-limits): * lisp/net/shr-color.el (shr-color-hue-to-rgb) (shr-color-hsl-to-rgb-fractions): Exploit the change to simplify the code a bit. * lisp/emacs-lisp/bytecomp.el (byte-compile-quo): Don=E2=80=99t complain about single-argument calls to =E2=80=98/=E2=80=99= . * src/data.c (arith_driver, float_arith_driver): Implement the change. --- doc/lispref/numbers.texi | 17 +++++++++++++---- etc/NEWS | 6 ++++++ lisp/color.el | 18 +++++++++--------- lisp/emacs-lisp/bytecomp.el | 4 ++-- lisp/emacs-lisp/cl-extra.el | 2 +- lisp/net/shr-color.el | 6 +++--- src/data.c | 11 +++++++---- 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi index 3c70d2f..54c8d3e 100644 --- a/doc/lispref/numbers.texi +++ b/doc/lispref/numbers.texi @@ -642,10 +642,11 @@ Arithmetic Operations @end example @end defun =20 -@defun / dividend divisor &rest divisors -This function divides @var{dividend} by @var{divisor} and returns the -quotient. If there are additional arguments @var{divisors}, then it -divides @var{dividend} by each divisor in turn. Each argument may be a +@defun / number &rest divisors +With one or more @var{divisors}, this function divides @var{number} +by each divisor in @var{divisors} in turn, and returns the quotient. +With no @var{divisors}, this function returns 1/@var{number}, i.e., +the multiplicative inverse of @var{number}. Each argument may be a number or a marker. =20 If all the arguments are integers, the result is an integer, obtained @@ -673,6 +674,14 @@ Arithmetic Operations @result{} 2.5 @end group @group +(/ 4.0) + @result{} 0.25 +@end group +@group +(/ 4) + @result{} 0 +@end group +@group (/ 25 3 2) @result{} 4 @end group diff --git a/etc/NEWS b/etc/NEWS index dbe0de3..8170c4a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1007,6 +1007,12 @@ dynamically. dynamically. Any third-party code that changes these templates should be updated accordingly. =20 ++++ +** =E2=80=98(/ N)=E2=80=99 is now equivalent to =E2=80=98(/ 1 N)=E2=80=99= rather than to =E2=80=98(/ N 1)=E2=80=99. +The new behavior is compatible with Common Lisp and with XEmacs. +This change does not affect Lisp code intended to be portable to +Emacs 24.2 and earlier, which did not support unary =E2=80=98/=E2=80=99. + =0C * Lisp Changes in Emacs 25.1 =20 diff --git a/lisp/color.el b/lisp/color.el index d572222..97656ca 100644 --- a/lisp/color.el +++ b/lisp/color.el @@ -93,7 +93,7 @@ color-hue-to-rgb "Compute hue from V1 and V2 H. Used internally by `color-hsl-to-rgb'." (cond - ((< h (/ 1.0 6)) (+ v1 (* (- v2 v1) h 6.0))) + ((< h (/ 6.0)) (+ v1 (* (- v2 v1) h 6.0))) ((< h 0.5) v2) ((< h (/ 2.0 3)) (+ v1 (* (- v2 v1) (- (/ 2.0 3) h) 6.0))) (t v1))) @@ -110,9 +110,9 @@ color-hsl-to-rgb (- (+ L S) (* L S)))) (m1 (- (* 2.0 L) m2))) (list - (color-hue-to-rgb m1 m2 (mod (+ H (/ 1.0 3)) 1)) + (color-hue-to-rgb m1 m2 (mod (+ H (/ 3.0)) 1)) (color-hue-to-rgb m1 m2 H) - (color-hue-to-rgb m1 m2 (mod (- H (/ 1.0 3)) 1)))))) + (color-hue-to-rgb m1 m2 (mod (- H (/ 3.0)) 1)))))) =20 (defun color-complement-hex (color) "Return the color that is the complement of COLOR, in hexadecimal form= at." @@ -199,13 +199,13 @@ color-xyz-to-srgb (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z)))) (list (if (<=3D r 0.0031308) (* 12.92 r) - (- (* 1.055 (expt r (/ 1 2.4))) 0.055)) + (- (* 1.055 (expt r (/ 2.4))) 0.055)) (if (<=3D g 0.0031308) (* 12.92 g) - (- (* 1.055 (expt g (/ 1 2.4))) 0.055)) + (- (* 1.055 (expt g (/ 2.4))) 0.055)) (if (<=3D b 0.0031308) (* 12.92 b) - (- (* 1.055 (expt b (/ 1 2.4))) 0.055))))) + (- (* 1.055 (expt b (/ 2.4))) 0.055))))) =20 (defconst color-d65-xyz '(0.950455 1.0 1.088753) "D65 white point in CIE XYZ.") @@ -222,13 +222,13 @@ color-xyz-to-lab (yr (/ Y Yr)) (zr (/ Z Zr)) (fx (if (> xr color-cie-=CE=B5) - (expt xr (/ 1 3.0)) + (expt xr (/ 3.0)) (/ (+ (* color-cie-=CE=BA xr) 16) 116.0))) (fy (if (> yr color-cie-=CE=B5) - (expt yr (/ 1 3.0)) + (expt yr (/ 3.0)) (/ (+ (* color-cie-=CE=BA yr) 16) 116.0))) (fz (if (> zr color-cie-=CE=B5) - (expt zr (/ 1 3.0)) + (expt zr (/ 3.0)) (/ (+ (* color-cie-=CE=BA zr) 16) 116.0)))) (list (- (* 116 fy) 16) ; L diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 6f7ba33..d138eff 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -3617,8 +3617,8 @@ byte-compile-minus =20 (defun byte-compile-quo (form) (let ((len (length form))) - (cond ((<=3D len 2) - (byte-compile-subr-wrong-args form "2 or more")) + (cond ((< len 2) + (byte-compile-subr-wrong-args form "1 or more")) ((=3D len 3) (byte-compile-two-args form)) (t diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el index dddfca7..afa021d 100644 --- a/lisp/emacs-lisp/cl-extra.el +++ b/lisp/emacs-lisp/cl-extra.el @@ -497,7 +497,7 @@ cl-float-limits (setq cl-least-positive-normalized-float y cl-least-negative-normalized-float (- y)) ;; Divide down until value underflows to zero. - (setq x (/ 1 z) y x) + (setq x (/ z) y x) (while (condition-case _ (> (/ x 2) 0) (arith-error nil)) (setq x (/ x 2))) (setq cl-least-positive-float x diff --git a/lisp/net/shr-color.el b/lisp/net/shr-color.el index 482f829..f8d358c 100644 --- a/lisp/net/shr-color.el +++ b/lisp/net/shr-color.el @@ -211,7 +211,7 @@ shr-color-hue-to-rgb "Convert X Y H to RGB value." (when (< h 0) (incf h)) (when (> h 1) (decf h)) - (cond ((< h (/ 1 6.0)) (+ x (* (- y x) h 6))) + (cond ((< h (/ 6.0)) (+ x (* (- y x) h 6))) ((< h 0.5) y) ((< h (/ 2.0 3.0)) (+ x (* (- y x) (- (/ 2.0 3.0) h) 6))) (t x))) @@ -223,9 +223,9 @@ shr-color-hsl-to-rgb-fractions (setq m2 (* l (+ s 1))) (setq m2 (- (+ l s) (* l s)))) (setq m1 (- (* l 2) m2)) - (list (shr-color-hue-to-rgb m1 m2 (+ h (/ 1 3.0))) + (list (shr-color-hue-to-rgb m1 m2 (+ h (/ 3.0))) (shr-color-hue-to-rgb m1 m2 h) - (shr-color-hue-to-rgb m1 m2 (- h (/ 1 3.0)))))) + (shr-color-hue-to-rgb m1 m2 (- h (/ 3.0)))))) =20 (defun shr-color->hexadecimal (color) "Convert any color format to hexadecimal representation. diff --git a/src/data.c b/src/data.c index b85d8a7..33fe285 100644 --- a/src/data.c +++ b/src/data.c @@ -2603,6 +2603,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, L= isp_Object *args) accum =3D 0; break; case Amult: + case Adiv: accum =3D 1; break; case Alogand: @@ -2658,7 +2659,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, L= isp_Object *args) accum *=3D next; break; case Adiv: - if (!argnum) + if (! (argnum || nargs =3D=3D 1)) accum =3D next; else { @@ -2727,7 +2728,7 @@ float_arith_driver (double accum, ptrdiff_t argnum,= enum arithop code, accum *=3D next; break; case Adiv: - if (!argnum) + if (! (argnum || nargs =3D=3D 1)) accum =3D next; else { @@ -2782,9 +2783,11 @@ usage: (* &rest NUMBERS-OR-MARKERS) */) } =20 DEFUN ("/", Fquo, Squo, 1, MANY, 0, - doc: /* Return first argument divided by all the remaining argume= nts. + doc: /* Divide number by divisors and return the result. +With two or more arguments, return first argument divided by the rest. +With one argument, return 1 divided by the argument. The arguments must be numbers or markers. -usage: (/ DIVIDEND &rest DIVISORS) */) +usage: (/ NUMBER &rest DIVISORS) */) (ptrdiff_t nargs, Lisp_Object *args) { ptrdiff_t argnum; --=20 2.1.0 --------------080800050905010008050404--