Use std::round for rounding to nearest.
This commit is contained in:
parent
8d5e70379e
commit
ed1db4ace2
@ -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…
Reference in New Issue
Block a user