[alexandria-devel] median function
If you want this: CL-USER> (float (alexandria:median '(1 2 3 4))) 2.5 CL-USER> (alexandria:median '(100 0 99 1 98 2 97 96)) 193/2 Then you need this patch (the test is also wrong): johan@perle:~/prg/cllibs/alexandria$ darcs diff -u diff -rN -u old-alexandria/numbers.lisp new-alexandria/numbers.lisp --- old-alexandria/numbers.lisp 2009-09-12 01:24:20.000000000 +0200 +++ new-alexandria/numbers.lisp 2009-09-12 01:24:20.000000000 +0200 @@ -97,7 +97,7 @@ (middle (truncate length 2))) (if (oddp length) (aref vector middle) - (/ (+ (aref vector middle) (aref vector (1+ middle))) 2)))) + (/ (+ (aref vector middle) (aref vector (1- middle))) 2)))) (declaim (inline variance)) (defun variance (sample &key (biased t)) diff -rN -u old-alexandria/tests.lisp new-alexandria/tests.lisp --- old-alexandria/tests.lisp 2009-09-12 01:24:20.000000000 +0200 +++ new-alexandria/tests.lisp 2009-09-12 01:24:20.000000000 +0200 @@ -855,7 +855,7 @@ (deftest median.2 (median '(100 0 99 1 98 2 97 96)) - 195/2) + 193/2) (deftest variance.1 (variance (list 1 2 3)) johan@perle:~/prg/cllibs/alexandria$
participants (2)
-
Attila Lendvai
-
Johan Ur Riise