Skip to main content

bisect

Function bisect 

Source
pub fn bisect(
    below: impl FnMut(f64) -> bool,
    lo: f64,
    hi: f64,
    iters: usize,
) -> f64
Expand description

The threshold of a predicate by iters bisection steps of the bracket [lo, hi]: below(x) must hold below the threshold and fail above it (see the module).

§Examples

use comnum_math::bisect;
// the median of the exponential distribution: 1 - e^{-x} = 1/2
let m = bisect(|x| 1.0 - (-x).exp() < 0.5, 0.0, 10.0, 100);
assert!((m - 2f64.ln()).abs() < 1e-14);