mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
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.
This commit is contained in:
parent
0ce73eb680
commit
1541cfa8a6
@ -10,6 +10,8 @@
|
|||||||
#ifndef vtk_m_worklet_colorconversion_Conversions_h
|
#ifndef vtk_m_worklet_colorconversion_Conversions_h
|
||||||
#define vtk_m_worklet_colorconversion_Conversions_h
|
#define vtk_m_worklet_colorconversion_Conversions_h
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace vtkm
|
namespace vtkm
|
||||||
{
|
{
|
||||||
namespace worklet
|
namespace worklet
|
||||||
@ -26,13 +28,13 @@ VTKM_EXEC inline vtkm::UInt8 ColorToUChar(T t)
|
|||||||
template <>
|
template <>
|
||||||
VTKM_EXEC inline vtkm::UInt8 ColorToUChar(vtkm::Float64 t)
|
VTKM_EXEC inline vtkm::UInt8 ColorToUChar(vtkm::Float64 t)
|
||||||
{
|
{
|
||||||
return static_cast<vtkm::UInt8>(t * 255.0f + 0.5f);
|
return static_cast<vtkm::UInt8>(std::round(t * 255.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
VTKM_EXEC inline vtkm::UInt8 ColorToUChar(vtkm::Float32 t)
|
VTKM_EXEC inline vtkm::UInt8 ColorToUChar(vtkm::Float32 t)
|
||||||
{
|
{
|
||||||
return static_cast<vtkm::UInt8>(t * 255.0f + 0.5f);
|
return static_cast<vtkm::UInt8>(std::round(t * 255.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user