Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 43s
Bisection method searching for f(x) = 0 in [lo, hi] over 50
iterations:
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
Solving x^2 - 2 = 0 in [1, 2] via 'bisect (fun x -> x *. x -. 2.0)
1.0 2.0' converges to ~1.41421356... -> int_of_float (r *. 100) =
141.
Tests:
- higher-order function passing
- multi-let 'let lo = ref ... and hi = ref ...'
- float arithmetic
- int_of_float truncate-toward-zero (iter 117)
62 baseline programs total.