media-libs/ilmbase: fix test failure on x86
authorThomas Deutschmann <whissi@gentoo.org>
Wed, 24 Apr 2019 10:05:12 +0000 (12:05 +0200)
committerThomas Deutschmann <whissi@gentoo.org>
Wed, 24 Apr 2019 10:05:12 +0000 (12:05 +0200)
Package-Manager: Portage-2.3.64, Repoman-2.3.12
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
media-libs/ilmbase/files/ilmbase-2.3.0-testBox.patch [new file with mode: 0644]
media-libs/ilmbase/ilmbase-2.3.0.ebuild

diff --git a/media-libs/ilmbase/files/ilmbase-2.3.0-testBox.patch b/media-libs/ilmbase/files/ilmbase-2.3.0-testBox.patch
new file mode 100644 (file)
index 0000000..8211846
--- /dev/null
@@ -0,0 +1,104 @@
+Subject: testBox: allow fuzzy comparison of floats, doubles
+From: Steven Chamberlain <steven@pyro.eu.org>
+Date: Wed, 24 Feb 2016 01:10:11 +0000
+
+Allow for inexact values, as long as the error is smaller than the
+epsilon of the data type.
+
+On 32-bit x86, allow even greater discrepency at double
+precision, due to possible double-rounding.  See
+https://lists.nongnu.org/archive/html/openexr-devel/2015-12/msg00001.html
+
+Index: ilmbase/ImathTest/testBox.cpp
+===================================================================
+--- ilmbase.orig/ImathTest/testBox.cpp
++++ ilmbase/ImathTest/testBox.cpp
+@@ -47,6 +47,58 @@ using namespace IMATH_INTERNAL_NAMESPACE
+ namespace {
++template <class T>
++bool
++approximatelyEqual (const T &p1, const T &p2)
++{
++      /* int and short should be exact */
++      return (p1 == p2);
++}
++
++bool
++approximatelyEqual (const Vec2<float> &p1, const Vec2<float> &p2)
++{
++    float e = limits<float>::epsilon();
++    float m = 0;
++
++    for (int i = 0; i < 2; ++i)
++    {
++      m = max (m, abs (p1[i]));
++      m = max (m, abs (p2[i]));
++    }
++
++    for (int i = 0; i < 2; ++i)
++      if (!equalWithAbsError (p1[i], p2[i], m * e))
++          return false;
++
++    return true;
++}
++
++bool
++approximatelyEqual (const Vec2<double> &p1, const Vec2<double> &p2)
++{
++#if defined(__i386__) || defined(_M_IX86)
++    /* double-rounding on 32-bit x86 may cause larger error:
++       use epsilon of float rather than double */
++    double e = limits<float>::epsilon();
++#else
++    double e = limits<double>::epsilon();
++#endif
++    double m = 0;
++
++    for (int i = 0; i < 2; ++i)
++    {
++      m = max (m, abs (p1[i]));
++      m = max (m, abs (p2[i]));
++    }
++
++    for (int i = 0; i < 2; ++i)
++      if (!equalWithAbsError (p1[i], p2[i], m * e))
++          return false;
++
++    return true;
++}
++
+ //
+ // Test case generation utility - create a vector of IMATH_INTERNAL_NAMESPACE::Vec{2,3,4}
+ // with all permutations of integers 1..T::dimensions().
+@@ -250,7 +302,8 @@ testExtendByPoint(const char *type)
+                               
+         IMATH_INTERNAL_NAMESPACE::Box<T> b;
+         b.extendBy(p);
+-        assert(b.min == p && b.max == p);
++        assert (approximatelyEqual (b.min, p));
++        assert (approximatelyEqual (b.max, p));
+     }
+     //
+@@ -283,7 +336,8 @@ testExtendByPoint(const char *type)
+             b.extendBy(p);
+-            assert(b.min == min && b.max == max);
++            assert (approximatelyEqual (b.min, min));
++            assert (approximatelyEqual (b.max, max));
+         }
+     }
+ }
+@@ -358,7 +412,8 @@ testExtendByBox(const char *type)
+             }
+             b.extendBy(IMATH_INTERNAL_NAMESPACE::Box<T>(p0, p1));
+-            assert(b.min == min && b.max == max);
++            assert (approximatelyEqual (b.min, min));
++            assert (approximatelyEqual (b.max, max));
+         }
+     }
+ }
index 98490276a1d6c679758427985e83f916db04e2c5..bc9937e3b17e690a3c5a63cd6e9a08ef20b8d22b 100644 (file)
@@ -15,6 +15,8 @@ IUSE="static-libs"
 
 DEPEND="virtual/pkgconfig[${MULTILIB_USEDEP}]"
 
+PATCHES=( "${FILESDIR}"/${PN}-2.3.0-testBox.patch )
+
 DOCS=( AUTHORS ChangeLog NEWS README.md )
 MULTILIB_WRAPPED_HEADERS=( /usr/include/OpenEXR/IlmBaseConfig.h )