Skip to content

Commit a2a569c

Browse files
committed
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.
1 parent 8653401 commit a2a569c

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

‎Common/MathUtils/include/MathUtils/detail/StatAccumulator.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct StatAccumulator {
4242
wsum += w;
4343
n++;
4444
}
45-
double getMean() const { return wsum > 0. ? sum / wsum : 0.; }
45+
double getMean() const { return wsum > 0. ? sum / wsum : double{}; }
4646

4747
#ifndef GPUCA_GPUCODE_DEVICE
4848
template <typename T = float>

0 commit comments

Comments
 (0)