From 1541cfa8a6c007f28708360926608c2a39d8eb44 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 5 May 2023 12:10:54 -0400 Subject: [PATCH] clang-tidy: fix `bugprone-incorrect-roundings` lints Adding `0.5` is not correct in all cases. Namely, adding `0.5` will cause the value immediately before it to be rounded to `1` due to the "round to nearest even" rule. Trust the standard library to get this right. --- vtkm/worklet/colorconversion/Conversions.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vtkm/worklet/colorconversion/Conversions.h b/vtkm/worklet/colorconversion/Conversions.h index d48dec971..f6ca9ad58 100644 --- a/vtkm/worklet/colorconversion/Conversions.h +++ b/vtkm/worklet/colorconversion/Conversions.h @@ -10,6 +10,8 @@ #ifndef vtk_m_worklet_colorconversion_Conversions_h #define vtk_m_worklet_colorconversion_Conversions_h +#include + namespace vtkm { namespace worklet @@ -26,13 +28,13 @@ VTKM_EXEC inline vtkm::UInt8 ColorToUChar(T t) template <> VTKM_EXEC inline vtkm::UInt8 ColorToUChar(vtkm::Float64 t) { - return static_cast(t * 255.0f + 0.5f); + return static_cast(std::round(t * 255.0f)); } template <> VTKM_EXEC inline vtkm::UInt8 ColorToUChar(vtkm::Float32 t) { - return static_cast(t * 255.0f + 0.5f); + return static_cast(std::round(t * 255.0f)); }