vmedian   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/math.xtm

Implementation

(bind-func vmedian
  (lambda (buf:double* len:i64)
    (let ((h (vsort buf len))
          (idx (dtoi64 (ceil (/ (i64tod len) 2.0)))))
      (if (evenp len)
          (/ (+ (pref h idx) (pref h (- idx 1))) 2.0)
          (pref h idx)))))


Back to Index

Similar Entries