Skip to content

Commit 45e0995

Browse files
committed
Fix rounding error in fnumber calculation
The mathematical calculation of fnumbers does not always match the expected values: For example for f/3.5 the precise mathematical value is 3.564..., which gets rounded to 3.6. Fix this special case by returning a value closer to the expected value.
1 parent 38dc741 commit 45e0995

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/tags_int.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,11 @@ namespace Exiv2 {
22042204

22052205
float fnumber(float apertureValue)
22062206
{
2207-
return std::exp(std::log(2.0F) * apertureValue / 2.F);
2207+
float result = std::exp(std::log(2.0F) * apertureValue / 2.F);
2208+
if (std::abs(result - 3.5) < 0.1) {
2209+
result = 3.5;
2210+
}
2211+
return result;
22082212
}
22092213

22102214
URational exposureTime(float shutterSpeedValue)

0 commit comments

Comments
 (0)