[Openmp-commits] [openmp] 702a976 - [OpenMP][Offloading] Change the way to compare floating point values in bug49334.cpp

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Thu Feb 10 15:20:40 PST 2022


Author: Shilei Tian
Date: 2022-02-10T18:20:36-05:00
New Revision: 702a976c125cde4807b7c870518e64b345df2396

URL: https://github.com/llvm/llvm-project/commit/702a976c125cde4807b7c870518e64b345df2396
DIFF: https://github.com/llvm/llvm-project/commit/702a976c125cde4807b7c870518e64b345df2396.diff

LOG: [OpenMP][Offloading] Change the way to compare floating point values in bug49334.cpp

`bug49334.cpp` directly uses `!=` to compare two floating point values,
which is almost wrong.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D119485

Added: 
    

Modified: 
    openmp/libomptarget/test/offloading/bug49334.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/test/offloading/bug49334.cpp b/openmp/libomptarget/test/offloading/bug49334.cpp
index 3ed1d5a035b1c..d034854600ef1 100644
--- a/openmp/libomptarget/test/offloading/bug49334.cpp
+++ b/openmp/libomptarget/test/offloading/bug49334.cpp
@@ -5,7 +5,9 @@
 // UNSUPPORTED: x86_64-pc-linux-gnu
 
 #include <cassert>
+#include <cmath>
 #include <iostream>
+#include <limits>
 #include <memory>
 #include <vector>
 
@@ -57,7 +59,8 @@ class BlockMatrix {
             int currj = j * rowsPerBlock + jj;
             float m_value = matrix[curri + currj * nCols];
             float bm_value = CurrBlock[ii + jj * colsPerBlock];
-            if (bm_value != m_value) {
+            if (std::fabs(bm_value - m_value) >
+                std::numeric_limits<float>::epsilon()) {
               fail++;
             }
           }


        


More information about the Openmp-commits mailing list