jeudi 28 juillet 2016

How to avoid embedded `std::complex` when providing `T=std::complex`?

For a Polynomial equation solver, it would be great to template it to have any type available:

template <class number, int degree>
class PolynomialEquation
{
public:

private:
    array<number, degree+1> myEquation;
    array<complex<number>, degree> equationResult;
};

This allows, for example, doublein ℝ to be used for the input, and the result to be std::complex<double> in ℂ (we know that from degree 2 and over, solution to equation usually fall into ℂ, example: x^2+1 ).

But, the input to the equation could also be a std::complex. In this case, the type of myEquation shall be complex, but equationResult should NOT be a std::complex<complex<T>>, but just a normal complex number of type T.

Questions:

How to make the type of equationResult to be the sub-type of std::complex when the equation is provided with std::complex?

Is there an std::is_floating_point equivalent like std::is_complex_number ?

Aucun commentaire:

Enregistrer un commentaire