diff --git a/common/AzimuthalIntegrationProfile.cpp b/common/AzimuthalIntegrationProfile.cpp index 165bfe27..3b271293 100644 --- a/common/AzimuthalIntegrationProfile.cpp +++ b/common/AzimuthalIntegrationProfile.cpp @@ -18,7 +18,10 @@ inline float calc_std(float sum, float sum2, uint64_t count) { return NAN; const auto fp_count = static_cast(count); const float variance = (sum2 - sum * sum / fp_count) / (fp_count - 1); - return std::sqrt(variance); + // The two sums are floats accumulated over millions of pixels, so on a near-constant ring the + // difference of two nearly equal large numbers lands either side of zero; clamp before the root + // rather than emit a NaN standard deviation. Both spot-finder ring accumulators do the same. + return std::sqrt(std::max(0.0f, variance)); } AzimuthalIntegrationProfile::AzimuthalIntegrationProfile(const AzimuthalIntegrationMapping &mapping)