aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/IO.h
diff options
context:
space:
mode:
authorGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-08-13 22:50:55 -0400
committerGravatar Benoit Jacob <jacob.benoit.1@gmail.com>2009-08-13 22:50:55 -0400
commit1d80f561ad48a96e9852dd8bfdbc400574aa67e5 (patch)
tree1b1153ffe7cd8a178c49a3d2561b558829c1e0c3 /Eigen/src/Core/IO.h
parent99802094e471bb64cc3c3e3d0b2391ba2a1e75a2 (diff)
apply change discussed on the list :
* new default precision "-1" means use the current stream precision * otherwise, save and restore the stream precision
Diffstat (limited to 'Eigen/src/Core/IO.h')
-rw-r--r--Eigen/src/Core/IO.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h
index 38ac3eef3..7cd2b683a 100644
--- a/Eigen/src/Core/IO.h
+++ b/Eigen/src/Core/IO.h
@@ -33,7 +33,7 @@ enum { Raw, AlignCols };
* \brief Stores a set of parameters controlling the way matrices are printed
*
* List of available parameters:
- * - \b precision number of digits for floating point values
+ * - \b precision number of digits for floating point values. The default value -1 means that the current stream precision is used.
* - \b flags can be either Raw (default) or AlignCols which aligns all the columns
* - \b coeffSeparator string printed between two coefficients of the same row
* - \b rowSeparator string printed between two rows
@@ -50,7 +50,7 @@ enum { Raw, AlignCols };
struct IOFormat
{
/** Default contructor, see class IOFormat for the meaning of the parameters */
- IOFormat(int _precision=4, int _flags=Raw,
+ IOFormat(int _precision=-1, int _flags=Raw,
const std::string& _coeffSeparator = " ",
const std::string& _rowSeparator = "\n", const std::string& _rowPrefix="", const std::string& _rowSuffix="",
const std::string& _matPrefix="", const std::string& _matSuffix="")
@@ -134,12 +134,12 @@ std::ostream & ei_print_matrix(std::ostream & s, const Derived& _m, const IOForm
for(int i = 0; i < m.rows(); ++i)
{
std::stringstream sstr;
- sstr.precision(fmt.precision);
+ if(fmt.precision != -1) sstr.precision(fmt.precision);
sstr << m.coeff(i,j);
width = std::max<int>(width, int(sstr.str().length()));
}
}
- s.precision(fmt.precision);
+ std::streamsize old_precision = s.precision(fmt.precision);
s << fmt.matPrefix;
for(int i = 0; i < m.rows(); ++i)
{
@@ -159,6 +159,7 @@ std::ostream & ei_print_matrix(std::ostream & s, const Derived& _m, const IOForm
s << fmt.rowSeparator;
}
s << fmt.matSuffix;
+ s.precision(old_precision);
return s;
}