From 7e2f6629fd30942bbb5cafc8f1c0fdcd7fd5102b Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 3 Mar 2019 00:45:56 +0100 Subject: [PATCH] fixed a bug with hdist returning nan due to precision errors --- hyperpoint.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 9096295a..8d0e5282 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -588,8 +588,10 @@ double hdist(const hyperpoint& h1, const hyperpoint& h2) { ld iv = intval(h1, h2); switch(cgclass) { case gcEuclid: + if(iv < 0) return 0; return sqrt(iv); case gcHyperbolic: + if(iv < 0) return 0; return 2 * asinh(sqrt(iv) / 2); case gcSphere: return 2 * asin_auto_clamp(sqrt(iv) / 2);