[PATCH] D50047: [compiler-rt] [test] Use approximate comparison on float types

Luka Ercegovcevic via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 31 03:23:44 PDT 2018


erceg95 created this revision.
erceg95 added reviewers: compnerd, scanon, mgorny.
Herald added a subscriber: dberris.

We are resubmitting this patch (https://reviews.llvm.org/D28862) as it still causes this test of fail on Ubuntu 18.04 , Ubuntu GLIBC 2.27-3ubuntu1.


https://reviews.llvm.org/D50047

Files:
  test/builtins/Unit/divsc3_test.c


Index: test/builtins/Unit/divsc3_test.c
===================================================================
--- test/builtins/Unit/divsc3_test.c
+++ test/builtins/Unit/divsc3_test.c
@@ -15,6 +15,7 @@
 #include "int_lib.h"
 #include <math.h>
 #include <complex.h>
+#include <stdbool.h>
 #include <stdio.h>
 
 // REQUIRES: c99-complex
@@ -50,6 +51,25 @@
     return non_zero;
 }
 
+// check for equality assuming that both real and imaginary parts
+// can differ by exactly 1 representable value, in order to handle
+// different levels of accuracy on 32-bit x86
+static bool approx_equal(float _Complex a, float _Complex b) {
+    if (a != b) {
+        float ra = __real__ a;
+        float ia = __imag__ a;
+        float rb = __real__ b;
+        float ib = __imag__ b;
+
+        if (ra != rb && nextafterf(ra, rb) != rb)
+            return false;
+        if (ia != ib && nextafterf(ia, ib) != ib)
+            return false;
+    }
+
+    return true;
+}
+
 int test__divsc3(float a, float b, float c, float d)
 {
     float _Complex r = __divsc3(a, b, c, d);
@@ -103,7 +123,7 @@
             {
             float _Complex z = (a * c + b * d) / (c * c + d * d)
                              + (b * c - a * d) / (c * c + d * d) * _Complex_I;
-            if (r != z)
+            if (!approx_equal(r, z))
                 return 1;
             }
             break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50047.158199.patch
Type: text/x-patch
Size: 1371 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180731/2b52e5f6/attachment.bin>


More information about the cfe-commits mailing list