Bisection Method Implementation
You seem to assume that there is a root between a and b. If it is not the case, bisect will never terminate. Assuming that f is well-behaving, it would be prudent to test that f(a) and f(b) have different signs before proceeding.
Also, consider the case f(a) &gt; 0 &amp;&amp; f(b) &lt; 0

bisect doesn't find the approximation of the root. It finds an argument at which f is reasonably small. It could be quite far from the root. A prudent termination condition is b - a &lt; e.

a + b may overflow, and then all bets are off. Consider mid = a + (b - a)/2.