What is the simplest way to replace all Eigen::MatrixXd
s and Eigen::VectorXd
s with Vectors and Matrices that have long double
elements?
Every basic floating point variable in my code is of type long double
. Also, everytime I use a matrix or vector, I use the following typedefs.
typedef Eigen::VectorXd Vec;
typedef Eigen::MatrixXd Mat;
What's the best thing to switch these typedefs to? What happens if I leave them as they are?
Simply define your own typedefs based on Eigen's own global matrix typedefs.
If you use
Eigen::MatrixXd
and fill it with elements of typelong double
, those values will be narrowed to fit into thedouble
elements of the matrix, which results in a loss of precision or, in the worst case, overflow errors. However, on many architectures double-precision floating point arithmetic is done in 80-bit extended precision, so the results may be the same. You surely shouldn't rely on this! For more see, e.g., long double vs double.