diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp index 30d3f1bba..30bba3f07 100644 --- a/test/sparse_basic.cpp +++ b/test/sparse_basic.cpp @@ -658,7 +658,8 @@ void big_sparse_triplet(Index rows, Index cols, double density) { { Index r = internal::random(0,rows-1); Index c = internal::random(0,cols-1); - Scalar v = internal::random(); + // use positive values to prevent numerical cancellation errors in sum + Scalar v = numext::abs(internal::random()); triplets.push_back(TripletType(r,c,v)); sum += v; }