Skip to content

Commit

Permalink
clang-tidy: fix bad roundings
Browse files Browse the repository at this point in the history
Found with bugprone-incorrect-roundings

Signed-off-by: Rosen Penev <[email protected]>
  • Loading branch information
neheb committed Sep 16, 2023
1 parent c54afb5 commit 13716a0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(100.0 * (static_cast<short>(value.toInt64()) / 32.0 + 5.0) + 0.5);
auto res = std::lround(100.0 * (static_cast<short>(value.toInt64()) / 32.0 + 5.0));
os << std::fixed << std::setprecision(2) << res / 100.0;
os.copyfmt(oss);
}
Expand Down
4 changes: 2 additions & 2 deletions src/nikonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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*) {
Expand Down
2 changes: 1 addition & 1 deletion src/tiffcomposite_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ size_t TiffBinaryArray::doCount() const {
typeSize = 1;
}

return static_cast<size_t>(static_cast<double>(size()) / typeSize + 0.5);
return std::lround(static_cast<double>(size()) / typeSize);
}

size_t TiffBinaryElement::doCount() const {
Expand Down

0 comments on commit 13716a0

Please sign in to comment.