Commit | Line | Data |
---|---|---|
5e8276dc LF |
1 | Fix FTBFS on i686-linux due to rounding issue (see references). |
2 | ||
3 | Fixes Guix bug #22049 (see below). | |
4 | ||
5 | Copied from Debian. | |
6 | ||
7 | Source: | |
8 | https://sources.debian.net/src/ilmbase/2.2.0-11/debian/patches/testBoxAlgo.patch/ | |
9 | https://sources.debian.net/src/ilmbase/2.2.0-11/debian/patches/testBox.patch/ | |
10 | ||
11 | References: | |
12 | https://lists.nongnu.org/archive/html/openexr-devel/2015-12/msg00001.html | |
13 | https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22049 | |
14 | https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=815712 | |
15 | https://anonscm.debian.org/cgit/pkg-phototools/ilmbase.git/commit/?id=ab28bb45cdad8adc32e345b777ab8e692b1d9a9c | |
16 | ||
17 | --- | |
18 | ||
19 | Subject: testBoxAlgo: allow fuzzy match of b12 == b2 | |
20 | From: Steven Chamberlain <steven@pyro.eu.org> | |
21 | Date: Wed, 24 Feb 2016 01:04:11 +0000 | |
22 | ||
23 | Also fix a pre-existing typo. | |
24 | ||
25 | Index: ilmbase/ImathTest/testBoxAlgo.cpp | |
26 | =================================================================== | |
27 | --- ilmbase.orig/ImathTest/testBoxAlgo.cpp | |
28 | +++ ilmbase/ImathTest/testBoxAlgo.cpp | |
29 | @@ -886,10 +886,11 @@ boxMatrixTransform () | |
30 | ||
31 | assert (approximatelyEqual (b2.min, b4.min, e)); | |
32 | assert (approximatelyEqual (b2.max, b4.max, e)); | |
33 | - assert (approximatelyEqual (b3.max, b4.max, e)); | |
34 | + assert (approximatelyEqual (b3.min, b4.min, e)); | |
35 | assert (approximatelyEqual (b3.max, b4.max, e)); | |
36 | ||
37 | - assert (b21 == b2); | |
38 | + assert (approximatelyEqual (b2.min, b21.min, e)); | |
39 | + assert (approximatelyEqual (b2.max, b21.max, e)); | |
40 | assert (b31 == b3); | |
41 | ||
42 | M[0][3] = 1; | |
43 | ||
44 | --- | |
45 | ||
46 | Subject: testBox: allow fuzzy comparison of floats, doubles | |
47 | From: Steven Chamberlain <steven@pyro.eu.org> | |
48 | Date: Wed, 24 Feb 2016 01:10:11 +0000 | |
49 | ||
50 | Allow for inexact values, as long as the error is smaller than the | |
51 | epsilon of the data type. | |
52 | ||
53 | On 32-bit x86, allow even greater discrepency at double | |
54 | precision, due to possible double-rounding. See | |
55 | https://lists.nongnu.org/archive/html/openexr-devel/2015-12/msg00001.html | |
56 | ||
57 | Index: ilmbase/ImathTest/testBox.cpp | |
58 | =================================================================== | |
59 | --- ilmbase.orig/ImathTest/testBox.cpp | |
60 | +++ ilmbase/ImathTest/testBox.cpp | |
61 | @@ -47,6 +47,58 @@ using namespace IMATH_INTERNAL_NAMESPACE | |
62 | ||
63 | namespace { | |
64 | ||
65 | +template <class T> | |
66 | +bool | |
67 | +approximatelyEqual (const T &p1, const T &p2) | |
68 | +{ | |
69 | + /* int and short should be exact */ | |
70 | + return (p1 == p2); | |
71 | +} | |
72 | + | |
73 | +bool | |
74 | +approximatelyEqual (const Vec2<float> &p1, const Vec2<float> &p2) | |
75 | +{ | |
76 | + float e = limits<float>::epsilon(); | |
77 | + float m = 0; | |
78 | + | |
79 | + for (int i = 0; i < 2; ++i) | |
80 | + { | |
81 | + m = max (m, abs (p1[i])); | |
82 | + m = max (m, abs (p2[i])); | |
83 | + } | |
84 | + | |
85 | + for (int i = 0; i < 2; ++i) | |
86 | + if (!equalWithAbsError (p1[i], p2[i], m * e)) | |
87 | + return false; | |
88 | + | |
89 | + return true; | |
90 | +} | |
91 | + | |
92 | +bool | |
93 | +approximatelyEqual (const Vec2<double> &p1, const Vec2<double> &p2) | |
94 | +{ | |
95 | +#if defined(__i386__) || defined(_M_IX86) | |
96 | + /* double-rounding on 32-bit x86 may cause larger error: | |
97 | + use epsilon of float rather than double */ | |
98 | + double e = limits<float>::epsilon(); | |
99 | +#else | |
100 | + double e = limits<double>::epsilon(); | |
101 | +#endif | |
102 | + double m = 0; | |
103 | + | |
104 | + for (int i = 0; i < 2; ++i) | |
105 | + { | |
106 | + m = max (m, abs (p1[i])); | |
107 | + m = max (m, abs (p2[i])); | |
108 | + } | |
109 | + | |
110 | + for (int i = 0; i < 2; ++i) | |
111 | + if (!equalWithAbsError (p1[i], p2[i], m * e)) | |
112 | + return false; | |
113 | + | |
114 | + return true; | |
115 | +} | |
116 | + | |
117 | // | |
118 | // Test case generation utility - create a vector of IMATH_INTERNAL_NAMESPACE::Vec{2,3,4} | |
119 | // with all permutations of integers 1..T::dimensions(). | |
120 | @@ -250,7 +302,8 @@ testExtendByPoint(const char *type) | |
121 | ||
122 | IMATH_INTERNAL_NAMESPACE::Box<T> b; | |
123 | b.extendBy(p); | |
124 | - assert(b.min == p && b.max == p); | |
125 | + assert (approximatelyEqual (b.min, p)); | |
126 | + assert (approximatelyEqual (b.max, p)); | |
127 | } | |
128 | ||
129 | // | |
130 | @@ -283,7 +336,8 @@ testExtendByPoint(const char *type) | |
131 | ||
132 | b.extendBy(p); | |
133 | ||
134 | - assert(b.min == min && b.max == max); | |
135 | + assert (approximatelyEqual (b.min, min)); | |
136 | + assert (approximatelyEqual (b.max, max)); | |
137 | } | |
138 | } | |
139 | } | |
140 | @@ -358,7 +412,8 @@ testExtendByBox(const char *type) | |
141 | } | |
142 | b.extendBy(IMATH_INTERNAL_NAMESPACE::Box<T>(p0, p1)); | |
143 | ||
144 | - assert(b.min == min && b.max == max); | |
145 | + assert (approximatelyEqual (b.min, min)); | |
146 | + assert (approximatelyEqual (b.max, max)); | |
147 | } | |
148 | } | |
149 | } |