]> code.delx.au - gnu-emacs/commitdiff
(/ N) now returns the reciprocal of N
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 21 Oct 2015 01:16:47 +0000 (18:16 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 21 Oct 2015 01:22:48 +0000 (18:22 -0700)
This is more compatible with Common Lisp and XEmacs (Bug#21690).  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’t complain about single-argument calls to ‘/’.
* src/data.c (arith_driver, float_arith_driver):
Implement the change.

doc/lispref/numbers.texi
etc/NEWS
lisp/color.el
lisp/emacs-lisp/bytecomp.el
lisp/emacs-lisp/cl-extra.el
lisp/net/shr-color.el
src/data.c

index 3c70d2f0a06951bc149ef6c6e6db021ae08ae8a4..54c8d3e5988be171f76dfad713e5e92e06628e37 100644 (file)
@@ -642,10 +642,11 @@ product.  When given no arguments, @code{*} returns 1.
 @end example
 @end defun
 
-@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.
 
 If all the arguments are integers, the result is an integer, obtained
@@ -673,6 +674,14 @@ by rounding the quotient towards zero after each division.
      @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
index 7b31357c345d3f5128d8f396c9dbb03a31cc0dda..ac6ccb86f01c09f2bf626373654093e8eedf57e8 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1008,6 +1008,12 @@ dynamically.
 dynamically.  Any third-party code that changes these templates should
 be updated accordingly.
 
++++
+** ‘(/ N)’ is now equivalent to ‘(/ 1 N)’ rather than to ‘(/ N 1)’.
+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 ‘/’.
+
 \f
 * Lisp Changes in Emacs 25.1
 
index d572222021b24ab1f3cc94eeb3077373f0674814..97656ca9e3372431fc626a6a7e14e8bdffa3c75e 100644 (file)
@@ -93,7 +93,7 @@ resulting list."
   "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 @@ inclusive."
                 (- (+ 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))))))
 
 (defun color-complement-hex (color)
   "Return the color that is the complement of COLOR, in hexadecimal format."
@@ -199,13 +199,13 @@ RED, GREEN and BLUE should be between 0.0 and 1.0, inclusive."
         (b (+ (* 0.0556434 X) (* -0.2040259 Y) (* 1.0572252 Z))))
     (list (if (<= r 0.0031308)
               (* 12.92 r)
-            (- (* 1.055 (expt r (/ 2.4))) 0.055))
+            (- (* 1.055 (expt r (/ 2.4))) 0.055))
           (if (<= g 0.0031308)
               (* 12.92 g)
-            (- (* 1.055 (expt g (/ 2.4))) 0.055))
+            (- (* 1.055 (expt g (/ 2.4))) 0.055))
           (if (<= b 0.0031308)
               (* 12.92 b)
-            (- (* 1.055 (expt b (/ 2.4))) 0.055)))))
+            (- (* 1.055 (expt b (/ 2.4))) 0.055)))))
 
 (defconst color-d65-xyz '(0.950455 1.0 1.088753)
   "D65 white point in CIE XYZ.")
@@ -222,13 +222,13 @@ conversion.  If omitted or nil, use `color-d65-xyz'."
              (yr (/ Y Yr))
              (zr (/ Z Zr))
              (fx (if (> xr color-cie-ε)
-                     (expt xr (/ 3.0))
+                     (expt xr (/ 3.0))
                    (/ (+ (* color-cie-κ xr) 16) 116.0)))
              (fy (if (> yr color-cie-ε)
-                     (expt yr (/ 3.0))
+                     (expt yr (/ 3.0))
                    (/ (+ (* color-cie-κ yr) 16) 116.0)))
              (fz (if (> zr color-cie-ε)
-                     (expt zr (/ 3.0))
+                     (expt zr (/ 3.0))
                    (/ (+ (* color-cie-κ zr) 16) 116.0))))
         (list
          (- (* 116 fy) 16)                  ; L
index 6f7ba3353f697814b59df34f9c1b75744c3f6d5d..d138effcd9d4a85352e95b28ca9b59694ff3f7cc 100644 (file)
@@ -3617,8 +3617,8 @@ discarding."
 
 (defun byte-compile-quo (form)
   (let ((len (length form)))
-    (cond ((<= len 2)
-          (byte-compile-subr-wrong-args form "2 or more"))
+    (cond ((< len 2)
+          (byte-compile-subr-wrong-args form "1 or more"))
          ((= len 3)
           (byte-compile-two-args form))
          (t
index dddfca7ae83f6cb5a4a5f23569af280bdc12e84a..afa021dffc73b73872ee3d7d9cdeca09cd189443 100644 (file)
@@ -497,7 +497,7 @@ This sets the values of: `cl-most-positive-float', `cl-most-negative-float',
        (setq cl-least-positive-normalized-float y
              cl-least-negative-normalized-float (- y))
        ;; Divide down until value underflows to zero.
-       (setq x (/ 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
index 482f829707d2b75d7ffa0c54105c7e05ae573513..f8d358c27b3704271eddb6b387c56407c0de6f75 100644 (file)
@@ -211,7 +211,7 @@ This will convert \"80 %\" to 204, \"100 %\" to 255 but \"123\" to \"123\"."
   "Convert X Y H to RGB value."
   (when (< h 0) (incf h))
   (when (> h 1) (decf h))
-  (cond ((< h (/ 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 @@ This will convert \"80 %\" to 204, \"100 %\" to 255 but \"123\" to \"123\"."
         (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 (/ 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 (/ 3.0))))))
+         (shr-color-hue-to-rgb m1 m2 (- h (/ 3.0))))))
 
 (defun shr-color->hexadecimal (color)
   "Convert any color format to hexadecimal representation.
index b85d8a77106abf4bbfc6e311e2cfe9e30dc3f0ec..33fe2855c99483cd966a4c73a6d566a9e48937d7 100644 (file)
@@ -2603,6 +2603,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
       accum = 0;
       break;
     case Amult:
+    case Adiv:
       accum = 1;
       break;
     case Alogand:
@@ -2658,7 +2659,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
            accum *= next;
          break;
        case Adiv:
-         if (!argnum)
+         if (! (argnum || nargs == 1))
            accum = next;
          else
            {
@@ -2727,7 +2728,7 @@ float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code,
          accum *= next;
          break;
        case Adiv:
-         if (!argnum)
+         if (! (argnum || nargs == 1))
            accum = next;
          else
            {
@@ -2782,9 +2783,11 @@ usage: (* &rest NUMBERS-OR-MARKERS)  */)
 }
 
 DEFUN ("/", Fquo, Squo, 1, MANY, 0,
-       doc: /* Return first argument divided by all the remaining arguments.
+       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;