Skip to content
Snippets Groups Projects
Verified Commit 46075a6c authored by Ansgar Burchardt's avatar Ansgar Burchardt
Browse files

dotproducttest.cc: avoid `sqrt(-1.0f)`

On clang-7 with libc++ this results in a small error for the imaginary
unit which gets computed as `I = (-4.37114e-08,1)`.  This results in a
too large error in the tests.

Closes: #51
parent 65edec67
No related branches found
No related tags found
1 merge request!254dotproducttest.cc: avoid `sqrt(-1.0f)`
......@@ -9,6 +9,24 @@
#include <dune/common/test/testsuite.hh>
#include <dune/common/hybridutilities.hh>
template<typename T>
struct Sign
{
static T complexSign()
{ return T(1.0); }
static T sqrtComplexSign()
{ return T(1.0); }
};
template<typename T>
struct Sign< std::complex<T> >
{
static std::complex<T> complexSign()
{ return std::complex<T>(-1.0); }
static std::complex<T> sqrtComplexSign()
{ return std::complex<T>(0.0, 1.0); }
};
// scalar ordering doesn't work for complex numbers
template <class RealBlockVector, class ComplexBlockVector>
Dune::TestSuite DotProductTest(const size_t numBlocks,const size_t blockSizeOrCapacity) {
......@@ -21,11 +39,8 @@ Dune::TestSuite DotProductTest(const size_t numBlocks,const size_t blockSizeOrCa
static_assert(std::is_same< typename Dune::FieldTraits<rt>::real_type, rt>::value,
"DotProductTest requires real data type for first block vector!");
const bool secondBlockIsComplex = !std::is_same< typename Dune::FieldTraits<ct>::real_type, ct>::value;
const ct complexSign = secondBlockIsComplex ? -1. : 1.;
// avoid constructor ct(0.,1.)
const ct I = secondBlockIsComplex ? std::sqrt(ct(-1.)) : ct(1.); // imaginary unit
const ct complexSign = Sign<ct>::complexSign();
const ct I = Sign<ct>::sqrtComplexSign();
typedef typename RealBlockVector::size_type size_type;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment