Your question is Square Root Without Built-ins. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Freddie Mac analytics services may need a predictable square-root calculation without relying on language-provided math functions. Implement an algorithm that computes the square root of a nonnegative number using binary search.
Write sqrt_approx(x, epsilon):
x is a nonnegative integer or floating-point number.epsilon is a positive floating-point tolerance.r such that abs(r * r - x) <= epsilon.x = 0, return 0.0.The evaluator accepts answers within the required squared-error tolerance. Aim for logarithmic convergence rather than scanning candidate values incrementally.
def sqrt_approx(x, epsilon):