From 51eb5beab56dabead088f093fd12f3dc1d25adf4 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Wed, 20 May 2020 03:05:03 +0000 Subject: [PATCH] fix: sqrt_double hangs on x < 1 (#760) --- math/sqrt_double.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/math/sqrt_double.cpp b/math/sqrt_double.cpp index e3418bfc3..5a0fd1c88 100644 --- a/math/sqrt_double.cpp +++ b/math/sqrt_double.cpp @@ -6,6 +6,9 @@ number in O(logn) time, with precision fixed */ double Sqrt(double x) { + if ( x > 0 && x < 1 ) { + return 1/Sqrt(1/x); + } double l = 0, r = x; /* Epsilon is the precision. A great precision is