Skip to content

Commit e0b2022

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 e0b2022

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
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)

test/data/exiv2-test.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ File 6/15: 20030925_201850.jpg
10771077
20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
10781078
20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
10791079
20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
1080-
20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
1080+
20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
10811081
20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
10821082
20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
10831083
20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
@@ -2690,7 +2690,7 @@ Compare image data and extracted data ------------------------------------
26902690
< 20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
26912691
< 20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
26922692
< 20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
2693-
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
2693+
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
26942694
< 20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
26952695
< 20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
26962696
< 20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
@@ -4231,7 +4231,7 @@ Compare image data and extracted data ------------------------------------
42314231
> 20030925_201850.exv Exif.CanonCs.0x0015 Short 1 32767
42324232
> 20030925_201850.exv Exif.CanonCs.LensType Short 1 n/a
42334233
> 20030925_201850.exv Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
4234-
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.6
4234+
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.5
42354235
> 20030925_201850.exv Exif.CanonCs.MinAperture Short 1 F22
42364236
> 20030925_201850.exv Exif.CanonCs.FlashActivity Short 1 Did not fire
42374237
> 20030925_201850.exv Exif.CanonCs.FlashDetails Short 1
@@ -5992,7 +5992,7 @@ Compare original and inserted image data ---------------------------------
59925992
< 20030925_201850.jpg Exif.CanonCs.0x0015 Short 1 32767
59935993
< 20030925_201850.jpg Exif.CanonCs.LensType Short 1 n/a
59945994
< 20030925_201850.jpg Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
5995-
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.6
5995+
< 20030925_201850.jpg Exif.CanonCs.MaxAperture Short 1 F3.5
59965996
< 20030925_201850.jpg Exif.CanonCs.MinAperture Short 1 F22
59975997
< 20030925_201850.jpg Exif.CanonCs.FlashActivity Short 1 Did not fire
59985998
< 20030925_201850.jpg Exif.CanonCs.FlashDetails Short 1
@@ -7533,7 +7533,7 @@ Compare original and inserted image data ---------------------------------
75337533
> 20030925_201850.exv Exif.CanonCs.0x0015 Short 1 32767
75347534
> 20030925_201850.exv Exif.CanonCs.LensType Short 1 n/a
75357535
> 20030925_201850.exv Exif.CanonCs.Lens Short 3 18.0 - 55.0 mm
7536-
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.6
7536+
> 20030925_201850.exv Exif.CanonCs.MaxAperture Short 1 F3.5
75377537
> 20030925_201850.exv Exif.CanonCs.MinAperture Short 1 F22
75387538
> 20030925_201850.exv Exif.CanonCs.FlashActivity Short 1 Did not fire
75397539
> 20030925_201850.exv Exif.CanonCs.FlashDetails Short 1

0 commit comments

Comments
 (0)