From 81285ab687f6436595f9c5219a865ad46186626f Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Tue, 13 Oct 2026 00:15:02 +0200 Subject: [PATCH] MathUtils: declare fastATan2's Pi where its lambdas can use it The local constexpr T Pi sits outside the two lambdas that read it. For a builtin T every use is an lvalue-to-rvalue conversion on a constant, so Pi is not odr-used and needs no capture. For a class type the operator call odr-uses it, which a lambda with no capture-default cannot do. Capturing it would not help either, because C, Pi025 and Pi075 are constexpr and a captured variable is not a constant expression. Declaring Pi inside each lambda satisfies both, and costs nothing: it is folded at compile time either way. --- Common/MathUtils/include/MathUtils/detail/trigonometric.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common/MathUtils/include/MathUtils/detail/trigonometric.h b/Common/MathUtils/include/MathUtils/detail/trigonometric.h index 3b363d1955a18..afdfbb57b0f28 100644 --- a/Common/MathUtils/include/MathUtils/detail/trigonometric.h +++ b/Common/MathUtils/include/MathUtils/detail/trigonometric.h @@ -275,12 +275,11 @@ GPUhdi() constexpr T fastATan2(T y, T x) // Average inaccuracy: 0.00048 // Max inaccuracy: 0.00084 // Speed: 6.2 times faster than atan2f() - constexpr T Pi = 3.1415926535897932384626433832795; - auto atan = [](T a) -> T { // returns the arctan for the angular range [-Pi/4, Pi/4] // the polynomial coefficients are taken from: // https://stackoverflow.com/questions/42537957/fast-accurate-atan-arctan-approximation-algorithm + constexpr T Pi = 3.1415926535897932384626433832795; constexpr T A = 0.0776509570923569; constexpr T B = -0.287434475393028; constexpr T C = ((Pi / 4) - A - B); @@ -290,6 +289,7 @@ GPUhdi() constexpr T fastATan2(T y, T x) auto atan2P = [atan](T yy, T xx) -> T { // fast atan2(yy,xx) for the angular range [0,+Pi] + constexpr T Pi = 3.1415926535897932384626433832795; constexpr T Pi025 = 1 * Pi / 4; constexpr T Pi075 = 3 * Pi / 4; const T x1 = xx + yy; // point p1 (x1,y1) = (xx,yy) - Pi/4