From 8bfcd00543da85143cfffe3ad3ff862579ed2d8b Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:55:04 +0200 Subject: [PATCH 1/2] MathUtils: make getMean()'s ternary unambiguous for an emulated double On Metal the double keyword names a class that converts to float and back implicitly, so the conditional operator has to form an implicit conversion sequence from each arm to the type of the other. Both directions succeed and the standard has no tie-break, which makes wsum > 0. ? sum / wsum : 0. ill-formed there. With a builtin double the arms go through the usual arithmetic conversions instead, and those are ranked, so nothing has to be resolved. double{} gives both arms the declared type on every backend: zero for the builtin, and, since the emulated type's default constructor is not user-provided, an all-bits-zero +0.0 on Metal. --- Common/MathUtils/include/MathUtils/detail/StatAccumulator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h b/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h index abb8a716cc5ee..d35327086eeee 100644 --- a/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h +++ b/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h @@ -42,7 +42,7 @@ struct StatAccumulator { wsum += w; n++; } - double getMean() const { return wsum > 0. ? sum / wsum : 0.; } + double getMean() const { return wsum > 0. ? sum / wsum : double{}; } #ifndef GPUCA_GPUCODE_DEVICE template From 96da55af05f9d7df85280860f54abe9ff6720b06 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Mon, 12 Oct 2026 23:43:23 +0200 Subject: [PATCH 2/2] Update Common/MathUtils/include/MathUtils/detail/StatAccumulator.h Co-authored-by: David Rohr --- Common/MathUtils/include/MathUtils/detail/StatAccumulator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h b/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h index d35327086eeee..9eb9aa69e9783 100644 --- a/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h +++ b/Common/MathUtils/include/MathUtils/detail/StatAccumulator.h @@ -42,7 +42,7 @@ struct StatAccumulator { wsum += w; n++; } - double getMean() const { return wsum > 0. ? sum / wsum : double{}; } + double getMean() const { return wsum > 0. ? sum / wsum : double{0}; } #ifndef GPUCA_GPUCODE_DEVICE template