File: fix-float.diff

package info (click to toggle)
lensfun 0.3.95-6
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 7,796 kB
  • sloc: xml: 34,868; cpp: 10,776; python: 3,617; ansic: 587; sh: 70; makefile: 13; javascript: 3
file content (50 lines) | stat: -rw-r--r-- 1,793 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>
 
 //------------------------------------------------------------------------//
 
@@ -163,8 +164,8 @@ std::regex extender_magnification_regex
 
 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);
@@ -243,13 +244,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)