Commit 7a3a4a13 authored by Dave Cooper's avatar Dave Cooper

upgraded binary-search.

parent 71d5acb9
......@@ -953,12 +953,15 @@ toplevel inputs as specified in the snapshot file.
(min-max-search function comparison mid high tolerance verbose?)))))
(defun binary-search (function value low high &optional (tolerance *zero-epsilon*) verbose?)
(defun binary-search (function value low high &key
(tolerance *zero-epsilon*)
(search-granularity *zero-epsilon*)
verbose?)
(when verbose? (print-variables high low))
(if (near-to? high low tolerance)
(if (near-to? high low search-granularity)
(progn (warn "binary search did not converge, returning best guess")
high)
(let* ((mid (half (+ low high)))
......@@ -967,8 +970,16 @@ toplevel inputs as specified in the snapshot file.
(print-variables mid mid-value)
(cond ((near-to? mid-value value tolerance) mid)
((> mid-value value) (binary-search function value low mid tolerance verbose?))
((< mid-value value) (binary-search function value mid high tolerance verbose?))))))
((> mid-value value) (binary-search function value low mid
:tolerance tolerance
:search-granularity search-granularity
:verbose? verbose?))
((< mid-value value) (binary-search function value mid high
:tolerance tolerance
:search-granularity search-granularity
:verbose? verbose?))))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment