Square Root to a Given Precision Without Libraries

Reported in interviews at Point72

Problem statement

Given a nonnegative number $x$ and a tolerance $\varepsilon$, compute $\sqrt{x}$ to within $\varepsilon$ without using any library math functions.

Example

sqrt_precision(0.0, 1e-09) -> 0.0
Show hint

Which iterative root-finding method converges fastest on a smooth function whose derivative you know?

Relevant roles: ML Engineer, Forward Deployed Engineer and AI Engineer.

Related free problems