UNPKG
bisect
Version:
latest (1.0.0)
1.0.0
0.0.0
Floating point binary search
github.com/mikolalysenko/bisect
mikolalysenko/bisect
bisect
/
bisect.js
15 lines
(14 loc)
•
218 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"use strict"
function
bisect
(
pred, lo, hi, tol
) { tol = tol ||
1e-8
while
(hi-lo>tol) {
var
m = (hi+lo)/
2
if
(
pred
(m)) { hi = m }
else
{ lo = m } }
return
lo }
module
.
exports
= bisect