Initial revision
[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 (file-comment
15   "$Header$")
16
17 ;;; FIXME: This probably belongs in SB-INT instead of SB-KERNEL.
18 ;;; And couldn't it be limited to FIXNUM arguments?
19 (defun positive-primep (x)
20   #!+sb-doc
21   "Returns T iff X is a positive prime integer."
22   (declare (integer x))
23   (if (<= x 5)
24       (and (>= x 2) (/= x 4))
25       (and (not (evenp x))
26            (not (zerop (rem x 3)))
27            (do ((q 6)
28                 (r 1)
29                 (inc 2 (logxor inc 6)) ;; 2,4,2,4...
30                 (d 5 (+ d inc)))
31                ((or (= r 0) (> d q)) (/= r 0))
32              (declare (fixnum inc))
33              (multiple-value-setq (q r) (truncate x d))))))