From efc22a5bd7abb315b75fd06f10cb96ddf885a346 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 10 Jan 2022 17:45:43 +0300 Subject: [PATCH] Add stable implementation of acos(x)/sqrt(1-x*x) --- libs/geom/include/psemek/geom/math.hpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index 61f91c44..81586461 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -57,6 +57,15 @@ namespace psemek::geom return std::sin(x) / x; } + template + T acos_over_sqrt_1_minus_x2(T const & x) + { + auto t = std::sqrt(T{1} - x * x); + if (t < std::numeric_limits::epsilon()) + return T{1}; + return std::acos(x) / t; + } + namespace detail {