r10469: add number-within-percentage
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 26 Apr 2005 21:45:12 +0000 (21:45 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 26 Apr 2005 21:45:12 +0000 (21:45 +0000)
math.lisp
os.lisp
package.lisp
tests.lisp

index fcbab3c4baa2e922b0eba049af0bd04079a19739..b3df9d6a045e0fb66938e21f0bdf7d7acb3a364e 100644 (file)
--- a/math.lisp
+++ b/math.lisp
                       (double-float double-float-epsilon)
                       (long-float long-float-epsilon))
                     (- exponent 1.0-exponent))))))
+
+(defun sinc (x)
+  (if (zerop x)
+      1d0
+    (let ((x (coerce x 'double-float)))
+      (/ (sin x) x))))
+
+
+(defun number-within-percentage (a b percent)
+  "Determines if two numbers are equal within a percentage difference."
+  (let ((abs-diff (* 0.01 percent 0.5 (+ (abs a) (abs b)))))
+    (< (abs (- a b)) abs-diff)))
diff --git a/os.lisp b/os.lisp
index 9eece913162b90f4b8c9bf9cab0c84749fdcd3b4..805b10c3c5275baa529601ad4350c2e37a55c38c 100644 (file)
--- a/os.lisp
+++ b/os.lisp
@@ -167,7 +167,7 @@ returns (VALUES output-string pid)"
   #+(and lispworks (not win32)) (system::getpid)
   #+sbcl (sb-posix:getpid)
   #+cmu (unix:unix-getpid)
-  #+openmcl (ccl:getpid)
+  #+openmcl (ccl::getpid)
   #+(and clisp unix) (system::program-id)
   #+(and clisp win32) (cond ((find-package :win32)
                             (funcall (find-symbol "GetCurrentProcessId" 
index db3f1c7c26a09067cd78affbafe9afe857910efb..f714514020c9b970762cbb9bb83da7a75aab4561 100644 (file)
    #:histogram
    #:fixnum-width
    #:scaled-epsilon
-   
+   #:sinc
+   #:number-within-percentage
+
    ;; macros.lisp
    #:time-iterations
    #:time-seconds
index b555555c170c45c182922c8a46decfd23e700238..9a84a7b67f96eec72ee7ffc5cd45922462cb0b84 100644 (file)
 (deftest :unique.2
     (unique-slot-values nil 'a)
   nil)
-     
+
+(deftest :nwp.1     
+       (number-within-percentage 1. 1.1 9)
+  nil)
+
+(deftest :nwp.2
+       (number-within-percentage 1. 1.1 11)
+  t)
+  
           
  ;;; MOP Testing