Coverage report: /home/ellis/comp/core/lib/math/prim.lisp

KindCoveredAll%
expression044 0.0
branch06 0.0
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; prim.lisp --- Lisp Primitives
2
 
3
 ;; 
4
 
5
 ;;; Code:
6
 (in-package :math)
7
 
8
 (defconstant +epsilon+ 1.e-7
9
   "Used as a liminal value to work around floating point inaccuracy.")
10
 
11
 (defconstant +pi+ (coerce pi 'single-float)
12
   "Single-float PI.")
13
 
14
 (declaim (inline ~))
15
 (defun ~ (a b &optional (epsilon +epsilon+))
16
   "Return true if A and B are within EPSILON of each other. EPSILON
17
 defaults to +DEFAULT-EPSILON+."
18
   (< (- epsilon) (- a b) epsilon))
19
 
20
 ;;; Open code comparisons to constants: no substraction needed at runtime.
21
 (define-compiler-macro ~ (&whole form a b &optional (epsilon +epsilon+))
22
   (if (constantp epsilon)
23
       (flet ((open-code (x constant)
24
                (let ((c (eval constant))
25
                      (e (eval epsilon)))
26
                  `(< ,(- c e) ,x ,(+ c e)))))
27
         (cond ((constantp a)
28
                (open-code b a))
29
               ((constantp b)
30
                (open-code a b))
31
               (t
32
                form)))
33
       form))