From 13716a0a97002c066e66ade8be25dcd6ea4d4f43 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 16 Sep 2023 14:39:42 -0700 Subject: [PATCH] clang-tidy: fix bad roundings Found with bugprone-incorrect-roundings Signed-off-by: Rosen Penev --- src/canonmn_int.cpp | 2 +- src/nikonmn_int.cpp | 4 ++-- src/tiffcomposite_int.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index 8292b0ad7a..ef8418dbc9 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2967,7 +2967,7 @@ std::ostream& CanonMakerNote::printSi0x0003(std::ostream& os, const Value& value // see also printSi0x0017 std::ostringstream oss; oss.copyfmt(os); - auto res = static_cast(100.0 * (static_cast(value.toInt64()) / 32.0 + 5.0) + 0.5); + auto res = std::lround(100.0 * (static_cast(value.toInt64()) / 32.0 + 5.0)); os << std::fixed << std::setprecision(2) << res / 100.0; os.copyfmt(oss); } diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index d191d3dd07..2e0ee50778 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -1731,8 +1731,8 @@ const TagInfo* Nikon3MakerNote::tagListLd4() { } std::ostream& Nikon3MakerNote::printIiIso(std::ostream& os, const Value& value, const ExifData*) { - double v = 100 * exp((value.toInt64() / 12.0 - 5) * log(2.0)); - return os << static_cast(v + 0.5); + auto v = std::lround(100.0f * std::exp((value.toInt64() / 12.0f - 5) * std::log(2.0f))); + return os << v; } std::ostream& Nikon3MakerNote::print0x0002(std::ostream& os, const Value& value, const ExifData*) { diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index b2eb6b8715..56c04f8de1 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -784,7 +784,7 @@ size_t TiffBinaryArray::doCount() const { typeSize = 1; } - return static_cast(static_cast(size()) / typeSize + 0.5); + return std::lround(static_cast(size()) / typeSize); } size_t TiffBinaryElement::doCount() const {