0.6.7.22: removed CVS dollar-Header-dollar tags from sources
[sbcl.git] / src / code / numbers.lisp
1 ;;;; numeric things needed within the cross-compiler
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!KERNEL")
13
14 ;;; FIXME: This probably belongs in SB-INT instead of SB-KERNEL.
15 ;;; And couldn't it be limited to FIXNUM arguments?
16 (defun positive-primep (x)
17   #!+sb-doc
18   "Returns T iff X is a positive prime integer."
19   (declare (integer x))
20   (if (<= x 5)
21       (and (>= x 2) (/= x 4))
22       (and (not (evenp x))
23            (not (zerop (rem x 3)))
24            (do ((q 6)
25                 (r 1)
26                 (inc 2 (logxor inc 6)) ;; 2,4,2,4...
27                 (d 5 (+ d inc)))
28                ((or (= r 0) (> d q)) (/= r 0))
29              (declare (fixnum inc))
30              (multiple-value-setq (q r) (truncate x d))))))