Mercurial > hg > octave-shane
changeset 11439:c2f44cba24c9
improve display of percentage full when printing sparse matrices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 04 Jan 2011 16:57:19 -0500 |
parents | 9e8497537319 |
children | bfbe441f3706 |
files | src/ChangeLog src/ov-base-sparse.cc |
diffstat | 2 files changed, 30 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-01-04 John W. Eaton <jwe@octave.org> + + * ov-base-sparse.cc (octave_base_sparse<T>::print_raw): Improve + display of percentage full. Bug #32011. + 2011-01-04 John W. Eaton <jwe@octave.org> * ov-typeinfo.cc (Ftypeinfo): Return cell array of character
--- a/src/ov-base-sparse.cc +++ b/src/ov-base-sparse.cc @@ -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";