let bisect f lo hi =
  let lo = ref lo and hi = ref hi in
  for _ = 1 to 50 do
    let mid = (!lo +. !hi) /. 2.0 in
    if f mid = 0.0 || f !lo *. f mid < 0.0 then hi := mid
    else lo := mid
  done;
  !lo

;;

let r = bisect (fun x -> x *. x -. 2.0) 1.0 2.0 in
int_of_float (r *. 100.0)
