]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-comb.el
Don’t create unnecessary marker in ‘delete-trailing-whitespace’
[gnu-emacs] / lisp / calc / calc-comb.el
index c933ecd7e0000bb54575a6cb5ef2319712267c73..132757aed5c5ab1d97639aea09867a621ed97c28 100644 (file)
@@ -1,17 +1,15 @@
 ;;; calc-comb.el --- combinatoric functions for Calc
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 1990-1993, 2001-2016 Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
-;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +17,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -80,7 +76,7 @@
      4877 4889 4903 4909 4919 4931 4933 4937 4943 4951 4957 4967 4969 4973
      4987 4993 4999 5003])
 
-;; The variable math-prime-factors-finished is set by calcFunc-prfac to 
+;; The variable math-prime-factors-finished is set by calcFunc-prfac to
 ;; indicate whether factoring is complete, and used by calcFunc-factors,
 ;; calcFunc-totient and calcFunc-moebius.
 (defvar math-prime-factors-finished)
 ;;; Factorial and related functions.
 
 (defconst math-small-factorial-table
-  (eval-when-compile
-    (vector 1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800
-            (math-read-number-simple "479001600")
-            (math-read-number-simple "6227020800")
-            (math-read-number-simple "87178291200")
-            (math-read-number-simple "1307674368000")
-            (math-read-number-simple "20922789888000")
-            (math-read-number-simple "355687428096000")
-            (math-read-number-simple "6402373705728000")
-            (math-read-number-simple "121645100408832000")
-            (math-read-number-simple "2432902008176640000"))))
+  (vector 1 1 2 6 24 120 720 5040 40320 362880 3628800 39916800
+          (math-read-number-simple "479001600")
+          (math-read-number-simple "6227020800")
+          (math-read-number-simple "87178291200")
+          (math-read-number-simple "1307674368000")
+          (math-read-number-simple "20922789888000")
+          (math-read-number-simple "355687428096000")
+          (math-read-number-simple "6402373705728000")
+          (math-read-number-simple "121645100408832000")
+          (math-read-number-simple "2432902008176640000")))
 
 (defun calcFunc-fact (n)   ; [I I] [F F] [Public]
   (let (temp)
       (while (<= (length math-stirling-local-cache) n)
        (let ((i (1- (length math-stirling-local-cache)))
              row)
-         (setq math-stirling-local-cache 
-                (vconcat math-stirling-local-cache 
+         (setq math-stirling-local-cache
+                (vconcat math-stirling-local-cache
                          (make-vector (length math-stirling-local-cache) nil)))
          (aset math-stirling-cache k math-stirling-local-cache)
          (while (< (setq i (1+ i)) (length math-stirling-local-cache))
        (let ((i 200))
          (while (> (setq i (1- i)) 0)
            (math-random-base))))
-    (random t)
     (setq var-RandSeed nil
          math-random-cache nil
          math-random-shift -4)  ; assume RAND_MAX >= 16383
          (i (/ (+ n slop) 3))
          (rnum 0))
     (while (> i 0)
-      (setq rnum 
+      (setq rnum
             (math-add
              (math-random-three-digit-number)
              (math-mul rnum 1000)))
                         (list nil v)
                       '(t))))
                  ((not (equal n (car math-prime-test-cache)))
-                  (cond ((= (% (nth 1 n) 2) 0) '(nil 2))
-                        ((= (% (nth 1 n) 5) 0) '(nil 5))
+                  (cond ((if (consp n)
+                              (= (% (nth 1 n) 2) 0)
+                            (= (% n 2) 0))
+                          '(nil 2))
+                        ((if (consp n)
+                              (= (% (nth 1 n) 5) 0)
+                            (= (% n 5) 0))
+                          '(nil 5))
                         (t (let ((q n) (sum 0))
                               (while (not (eq q 0))
                                 (setq sum (%
                                            (+
                                             sum
-                                            (calcFunc-mod 
+                                            (calcFunc-mod
                                              q 1000000))
                                            111111))
-                                (setq q 
-                                      (math-quotient 
+                                (setq q
+                                      (math-quotient
                                        q 1000000)))
                              (cond ((= (% sum 3) 0) '(nil 3))
                                    ((= (% sum 7) 0) '(nil 7))
 
 (provide 'calc-comb)
 
-;;; arch-tag: 1d75ee9b-0815-42bd-a321-bb3dc001cc02
 ;;; calc-comb.el ends here