File: fix-float.diff

package info (click to toggle)
lensfun 0.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,672 kB
  • sloc: xml: 52,273; cpp: 7,831; ansic: 7,411; python: 1,725; sh: 17; ruby: 16; makefile: 13; javascript: 3
file content (50 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Author: Pino Toscano <pino@debian.org>
Description: Stop using INT_MIN/INT_MAX for floats
 .
 INT_MIN/INT_MAX are meant for the int type, and thus casting them to a
 different type (float) means loss of precision which may lead to failed
 comparisons later on.
 .
 Instead use the proper limits using std::numeric_limits.
Forwarded: https://github.com/lensfun/lensfun/pull/2094
Last-Update: 2023-08-12

--- a/libs/lensfun/lens.cpp
+++ b/libs/lensfun/lens.cpp
@@ -14,6 +14,7 @@
 #include <math.h>
 #include "windows/mathconstants.h"
 #include <algorithm>
+#include <limits>
 
 static struct
 {
@@ -245,8 +246,8 @@ void lfLens::AddMount (const char *val)
 
 void lfLens::GuessParameters ()
 {
-    float minf = float (INT_MAX), maxf = float (INT_MIN);
-    float mina = float (INT_MAX), maxa = float (INT_MIN);
+    float minf = std::numeric_limits<float>::max(), maxf = std::numeric_limits<float>::min();
+    float mina = std::numeric_limits<float>::max(), maxa = std::numeric_limits<float>::min();
 
     char *old_numeric = setlocale (LC_NUMERIC, NULL);
     old_numeric = strdup (old_numeric);
@@ -325,13 +326,13 @@ void lfLens::GuessParameters ()
 
     }
 
-    if (minf != INT_MAX && !MinFocal)
+    if (minf != std::numeric_limits<float>::max() && !MinFocal)
         MinFocal = minf;
-    if (maxf != INT_MIN && !MaxFocal)
+    if (maxf != std::numeric_limits<float>::min() && !MaxFocal)
         MaxFocal = maxf;
-    if (mina != INT_MAX && !MinAperture)
+    if (mina != std::numeric_limits<float>::max() && !MinAperture)
         MinAperture = mina;
-    if (maxa != INT_MIN && !MaxAperture)
+    if (maxa != std::numeric_limits<float>::min() && !MaxAperture)
         MaxAperture = maxa;
 
     if (!MaxFocal)