# HG changeset patch # User John W. Eaton # Date 1294178239 18000 # Node ID c2f44cba24c9d9c58471a1446dfc733ee4df40f9 # Parent 9e8497537319a16db4d344e1940f7a52716a14cd improve display of percentage full when printing sparse matrices diff -r 9e8497537319 -r c2f44cba24c9 src/ChangeLog --- a/src/ChangeLog Tue Jan 04 14:09:16 2011 -0500 +++ b/src/ChangeLog Tue Jan 04 16:57:19 2011 -0500 @@ -1,3 +1,8 @@ +2011-01-04 John W. Eaton + + * ov-base-sparse.cc (octave_base_sparse::print_raw): Improve + display of percentage full. Bug #32011. + 2011-01-04 John W. Eaton * ov-typeinfo.cc (Ftypeinfo): Return cell array of character diff -r 9e8497537319 -r c2f44cba24c9 src/ov-base-sparse.cc --- a/src/ov-base-sparse.cc Tue Jan 04 14:09:16 2011 -0500 +++ b/src/ov-base-sparse.cc Tue Jan 04 16:57:19 2011 -0500 @@ -321,7 +321,31 @@ double dnel = matrix.numel (); if (dnel > 0) - os << " [" << std::setprecision (2) << (nz / dnel * 100) << "%]"; + { + double pct = (nz / dnel * 100); + + int prec = 2; + + // Display at least 2 significant figures and up to 4 as we + // approach 100%. Avoid having limited precision of the display + // result in reporting 100% for matrices that are not actually + // 100% full. + + if (pct == 100) + prec = 3; + else + { + if (pct > 99.9) + prec = 4; + else if (pct > 99) + prec = 3; + + if (pct > 99.99) + pct = 99.99; + } + + os << " [" << std::setprecision (prec) << pct << "%]"; + } os << ")\n";