]> git.tdb.fi Git - libs/math.git/commitdiff
Use numeric_limits in Matrix test cases
authorMikko Rasa <tdb@tdb.fi>
Sun, 2 Jun 2019 11:39:58 +0000 (14:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 2 Jun 2019 16:13:09 +0000 (19:13 +0300)
tests/matrix.cpp

index 5b303dbe8cd99f706d4ce4889d766ee71f291657..1b01cbc94e5ab5cd940446d4a85c8748896765ae 100644 (file)
@@ -1,7 +1,9 @@
+#include <limits>
 #include <msp/linal/matrix.h>
 #include <msp/linal/squarematrix.h>
 #include <msp/test/test.h>
 
+using namespace std;
 using namespace Msp;
 
 class MatrixTests: public Test::RegisteredTest<MatrixTests>
@@ -42,9 +44,10 @@ void MatrixTests::multiply()
 template<typename T, unsigned N>
 bool is_identity(const LinAl::Matrix<T, N, N> &m)
 {
+       static const T limit = numeric_limits<T>::epsilon()*4;
        for(unsigned i=0; i<N; ++i)
                for(unsigned j=0; j<N; ++j)
-                       if(abs(T(i==j)-m(i, j))>1e-10)
+                       if(abs(T(i==j)-m(i, j))>limit)
                                return false;
        return true;
 }