Use std::round for rounding to nearest.

main
Kevin Backhouse 4 years ago
parent 8d5e70379e
commit ed1db4ace2
No known key found for this signature in database
GPG Key ID: 9DD01852EE40366E

@ -2607,16 +2607,14 @@ namespace Exiv2 {
URational ur(1, 1);
const double tmp = std::exp(std::log(2.0) * static_cast<double>(shutterSpeedValue));
if (tmp > 1) {
// Add 0.5 for rounding.
const double x = tmp + 0.5;
const double x = std::round(tmp);
// Check that x is within the range of a uint32_t before casting.
if (x <= std::numeric_limits<uint32_t>::max()) {
ur.second = static_cast<uint32_t>(x);
}
}
else {
// Add 0.5 for rounding.
const double x = 1/tmp + 0.5;
const double x = std::round(1/tmp);
// Check that x is within the range of a uint32_t before casting.
if (0 <= x && x <= std::numeric_limits<uint32_t>::max()) {
ur.first = static_cast<uint32_t>(x);

Loading…
Cancel
Save