Mercurial > octave
changeset 24789:a4d4ec566fd7
improve formatting of large values in pr-output functions
* pr-output.cc (make_real_format): Initialize local variables.
Switch to E format if available precision is exceeded. Set int format
based on leading digits.
(make_complex_matrix_format): Also allow switching to E format if
printing in fixed_point_format. Set int format based on leading
digits.
(make_real_matrix_format, make_complex_format,
make_complex_matrix_format, make_range_format):
Initialize local variables.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 22 Feb 2018 15:52:38 -0500 |
parents | 6f04028d5d86 |
children | d331650ce389 |
files | libinterp/corefcn/pr-output.cc |
diffstat | 1 files changed, 24 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc Thu Feb 22 00:07:37 2018 -0500 +++ b/libinterp/corefcn/pr-output.cc Thu Feb 22 15:52:38 2018 -0500 @@ -471,7 +471,7 @@ int prec = std::min (output_precision (), pr_output_traits<T>::digits10); - int fw, ld, rd; + int fw = 0, ld = 0, rd = 0; if (rat_format) { @@ -500,7 +500,12 @@ fw = 1 + digits; if (inf_or_nan && fw < 4) fw = 4; - rd = fw; + + if (int_only) + { + ld = digits; + rd = 0; + } } else { @@ -522,6 +527,7 @@ if (! (rat_format || bank_format || hex_format || bit_format) && (print_e || print_g || print_eng + || ld + rd > pr_output_traits<T>::digits10 || fw > pr_output_traits<T>::max_field_width)) { if (print_g) @@ -553,7 +559,7 @@ fmt.uppercase (); } else if (! bank_format && (inf_or_nan || int_only)) - fmt = float_format (fw, rd); + fmt = float_format (fw, ld); else fmt = float_format (fw, rd, std::ios::fixed); @@ -606,7 +612,7 @@ int prec = std::min (output_precision (), pr_output_traits<T>::digits10); - int fw, ld, rd; + int fw = 0, ld = 0, rd = 0; if (rat_format) { @@ -777,7 +783,7 @@ int prec = std::min (output_precision (), pr_output_traits<T>::digits10); - int i_fw, r_fw, ld, rd; + int i_fw = 0, r_fw = 0, ld = 0, rd = 0; if (rat_format) { @@ -816,7 +822,12 @@ i_fw = 3; r_fw = 4; } - rd = r_fw; + + if (int_only) + { + ld = digits; + rd = 0; + } } else { @@ -862,10 +873,9 @@ if (! (rat_format || bank_format || hex_format || bit_format) && (print_e || print_eng || print_g - || (! Vfixed_point_format - && (ld + rd > pr_output_traits<T>::digits10 - || r_fw > pr_output_traits<T>::max_field_width - || i_fw > pr_output_traits<T>::max_field_width)))) + || ld + rd > pr_output_traits<T>::digits10 + || r_fw > pr_output_traits<T>::max_field_width + || i_fw > pr_output_traits<T>::max_field_width)) { if (print_g) { @@ -912,8 +922,8 @@ } else if (! bank_format && (inf_or_nan || int_only)) { - r_fmt = float_format (r_fw, rd); - i_fmt = float_format (i_fw, rd); + r_fmt = float_format (r_fw, ld); + i_fmt = float_format (i_fw, ld); } else { @@ -992,7 +1002,7 @@ int prec = std::min (output_precision (), pr_output_traits<T>::digits10); - int i_fw, r_fw, ld, rd; + int i_fw = 0, r_fw = 0, ld = 0, rd = 0; if (rat_format) { @@ -1223,7 +1233,7 @@ int prec = std::min (output_precision (), pr_output_traits<T>::digits10); - int fw, ld, rd; + int fw = 0, ld = 0, rd = 0; if (rat_format) {