Mercurial > hg > octave-avbm
changeset 4509:9ec494b3eb5f
[project @ 2003-09-11 19:08:25 by jwe]
author | jwe |
---|---|
date | Thu, 11 Sep 2003 19:08:26 +0000 |
parents | 2bc437206787 |
children | 59eaa51e43d3 |
files | liboctave/CMatrix.cc liboctave/dMatrix.cc src/ChangeLog src/pr-output.cc |
diffstat | 4 files changed, 235 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/CMatrix.cc +++ b/liboctave/CMatrix.cc @@ -993,8 +993,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) info = -1; else if (calc_cond) { @@ -1002,14 +1002,14 @@ char job = '1'; Array<double> rz (2 * nc); double *prz = rz.fortran_vec (); - F77_XFCN (zgecon, ZGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, prz, info)); + F77_XFCN (zgecon, ZGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, prz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in zgecon"); - if ( info != 0) + if (info != 0) info = -1; } @@ -1024,7 +1024,7 @@ (*current_liboctave_error_handler) ("unrecoverable error in zgetri"); - if ( info != 0) + if (info != 0) info = -1; } } @@ -1448,8 +1448,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) { info = -1; retval = ComplexDET (); @@ -1465,15 +1465,15 @@ Array<double> rz (2*nr); double *prz = rz.fortran_vec (); - F77_XFCN (zgecon, ZGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, prz, info)); + F77_XFCN (zgecon, ZGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, prz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in zgecon"); } - if ( info != 0) + if (info != 0) { info = -1; retval = ComplexDET (); @@ -1489,12 +1489,12 @@ while (::abs(d[0]) < 1.) { d[0] = 10. * d[0]; - d[1] = d[1] - 1.; + d[1] = d[1] - 1.0; } while (::abs(d[0]) >= 10.) { d[0] = 0.1 * d[0]; - d[1] = d[1] + 1.; + d[1] = d[1] + 1.0; } } retval = ComplexDET (d); @@ -1593,8 +1593,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) { info = -2; @@ -1609,14 +1609,14 @@ { // Now calculate the condition number for non-singular matrix. char job = '1'; - F77_XFCN (zgecon, ZGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, prz, info)); + F77_XFCN (zgecon, ZGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, prz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in zgecon"); - if ( info != 0) + if (info != 0) info = -2; volatile double rcond_plus_one = rcond + 1.0; @@ -1742,8 +1742,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) { info = -2; @@ -1758,14 +1758,14 @@ { // Now calculate the condition number for non-singular matrix. char job = '1'; - F77_XFCN (zgecon, ZGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, prz, info)); + F77_XFCN (zgecon, ZGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, prz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in zgecon"); - if ( info != 0) + if (info != 0) info = -2; volatile double rcond_plus_one = rcond + 1.0; @@ -2679,7 +2679,7 @@ for (int i = 0; i < ndiag; i++) d.elem (i) = elem (i, i+k); } - else if ( k < 0) + else if (k < 0) { for (int i = 0; i < ndiag; i++) d.elem (i) = elem (i-k, i);
--- a/liboctave/dMatrix.cc +++ b/liboctave/dMatrix.cc @@ -660,8 +660,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) info = -1; else if (calc_cond) { @@ -669,14 +669,14 @@ char job = '1'; Array<int> iz (nc); int *piz = iz.fortran_vec (); - F77_XFCN (dgecon, DGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, piz, info)); + F77_XFCN (dgecon, DGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, piz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in dgecon"); - if ( info != 0) + if (info != 0) info = -1; } @@ -691,7 +691,7 @@ (*current_liboctave_error_handler) ("unrecoverable error in dgetri"); - if ( info != 0) + if (info != 0) info = -1; } } @@ -1113,11 +1113,11 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) { - info = -1; - retval = DET (); + info = -1; + retval = DET (); } else { @@ -1130,15 +1130,15 @@ Array<int> iz (nc); int *piz = iz.fortran_vec (); - F77_XFCN (dgecon, DGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, piz, info)); + F77_XFCN (dgecon, DGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, piz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in dgecon"); } - if ( info != 0) + if (info != 0) { info = -1; retval = DET (); @@ -1154,12 +1154,12 @@ while (fabs(d[0]) < 1.) { d[0] = 10. * d[0]; - d[1] = d[1] - 1.; + d[1] = d[1] - 1.0; } while (fabs(d[0]) >= 10.) { d[0] = 0.1 * d[0]; - d[1] = d[1] + 1.; + d[1] = d[1] + 1.0; } } retval = DET (d); @@ -1229,8 +1229,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info != 0) + rcond = 0.0; + if (info != 0) { info = -2; @@ -1245,14 +1245,14 @@ { // Now calculate the condition number for non-singular matrix. char job = '1'; - F77_XFCN (dgecon, DGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, piz, info)); + F77_XFCN (dgecon, DGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, piz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in dgecon"); - if ( info != 0) + if (info != 0) info = -2; volatile double rcond_plus_one = rcond + 1.0; @@ -1376,8 +1376,8 @@ else { // Throw-away extra info LAPACK gives so as to not change output. - rcond = 0.; - if ( info > 0) + rcond = 0.0; + if (info > 0) { info = -2; @@ -1392,14 +1392,14 @@ { // Now calculate the condition number for non-singular matrix. char job = '1'; - F77_XFCN (dgecon, DGECON, ( &job, nc, tmp_data, nr, anorm, - rcond, pz, piz, info)); + F77_XFCN (dgecon, DGECON, (&job, nc, tmp_data, nr, anorm, + rcond, pz, piz, info)); if (f77_exception_encountered) (*current_liboctave_error_handler) ("unrecoverable error in dgecon"); - if ( info != 0) + if (info != 0) info = -2; volatile double rcond_plus_one = rcond + 1.0; @@ -2196,7 +2196,7 @@ for (int i = 0; i < ndiag; i++) d.elem (i) = elem (i, i+k); } - else if ( k < 0) + else if (k < 0) { for (int i = 0; i < ndiag; i++) d.elem (i) = elem (i-k, i);
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2003-09-11 John W. Eaton <jwe@bevo.che.wisc.edu> + + * pr-output.cc (Fformat): Doc fix. + (current_output_max_field_width, current_output_precision): + New functions. + (float_format::float_format (int, int, int)): Use them to provide + default values for field width and precision. + (print_g): New static variable. + (set_real_format, set_real_matrix_format, set_complex_format) + (set_complex_matrix_format, set_range_format): Handle print_g. + (pr_float, pr_complex): Don't scale if using print_g. + (set_format_style): Accept new "g" and "G" modifiers for short and + long formats and set print_g. + Set default precision and width for short to 5, 10. + Set default precision and width for long to 15, 20. + 2003-09-10 John W. Eaton <jwe@bevo.che.wisc.edu> * OPERATORS/op-m-cs.cc (complex_matrix_conv): Delete function.
--- a/src/pr-output.cc +++ b/src/pr-output.cc @@ -97,17 +97,33 @@ // TRUE means use an e format. static bool print_e = false; +// TRUE means use a g format. +static bool print_g = false; + // TRUE means print E instead of e for exponent field. static bool print_big_e = false; class pr_formatted_float; +static int +current_output_max_field_width (void) +{ + return Voutput_max_field_width; +} + +static int +current_output_precision (void) +{ + return Voutput_precision; +} + class float_format { public: - float_format (int w = -1, int p = -1, int f = 0) + float_format (int w = current_output_max_field_width (), + int p = current_output_precision (), int f = 0) : fw (w), prec (p), fmt (f), up (0), sp (0) { } float_format (const float_format& ff) @@ -309,18 +325,23 @@ } if (! (bank_format || hex_format || bit_format) - && (fw > Voutput_max_field_width || print_e)) + && (fw > Voutput_max_field_width || print_e || print_g)) { - int exp_field = 4; - if (digits > 100) - exp_field++; + if (print_g) + fmt = float_format (); + else + { + int exp_field = 4; + if (digits > 100) + exp_field++; - fw = 2 + prec + exp_field; - if (inf_or_nan && fw < 3) - fw = 3; - fw += sign; + fw = 2 + prec + exp_field; + if (inf_or_nan && fw < 3) + fw = 3; + fw += sign; - fmt = float_format (fw, prec - 1, std::ios::scientific); + fmt = float_format (fw, prec - 1, std::ios::scientific); + } if (print_big_e) fmt.uppercase (); @@ -392,7 +413,7 @@ fw = 8 * sizeof (double); rd = 0; } - else if (Vfixed_point_format) + else if (Vfixed_point_format && ! print_g) { rd = prec; fw = rd + 2; @@ -450,18 +471,24 @@ if (! (bank_format || hex_format || bit_format) && (print_e + || print_g || (! Vfixed_point_format && fw > Voutput_max_field_width))) { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; + if (print_g) + fmt = float_format (); + else + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; - fw = 2 + prec + exp_field; - if (inf_or_nan && fw < 3) - fw = 3; - fw += sign; + fw = 2 + prec + exp_field; + if (inf_or_nan && fw < 3) + fw = 3; + fw += sign; - fmt = float_format (fw, prec - 1, std::ios::scientific); + fmt = float_format (fw, prec - 1, std::ios::scientific); + } if (print_big_e) fmt.uppercase (); @@ -595,19 +622,27 @@ } if (! (bank_format || hex_format || bit_format) - && (r_fw > Voutput_max_field_width || print_e)) + && (r_fw > Voutput_max_field_width || print_e || print_g)) { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; + if (print_g) + { + r_fmt = float_format (); + i_fmt = float_format (); + } + else + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; - i_fw = r_fw = 1 + prec + exp_field; - if (inf_or_nan && i_fw < 3) - i_fw = r_fw = 3; - r_fw += sign; + i_fw = r_fw = 1 + prec + exp_field; + if (inf_or_nan && i_fw < 3) + i_fw = r_fw = 3; + r_fw += sign; - r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); - i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); + r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); + i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); + } if (print_big_e) { @@ -715,7 +750,7 @@ i_fw = 8 * sizeof (double); rd = 0; } - else if (Vfixed_point_format) + else if (Vfixed_point_format && ! print_g) { rd = prec; i_fw = r_fw = rd + 2; @@ -773,19 +808,28 @@ if (! (bank_format || hex_format || bit_format) && (print_e + || print_g || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; + if (print_g) + { + r_fmt = float_format (); + i_fmt = float_format (); + } + else + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; - i_fw = r_fw = 1 + prec + exp_field; - if (inf_or_nan && i_fw < 3) - i_fw = r_fw = 3; - r_fw += sign; + i_fw = r_fw = 1 + prec + exp_field; + if (inf_or_nan && i_fw < 3) + i_fw = r_fw = 3; + r_fw += sign; - r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); - i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); + r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); + i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); + } if (print_big_e) { @@ -895,7 +939,7 @@ fw = sign + digits; rd = fw; } - else if (Vfixed_point_format) + else if (Vfixed_point_format && ! print_g) { rd = prec; fw = rd + 2 + sign; @@ -938,15 +982,21 @@ if (! (bank_format || hex_format || bit_format) && (print_e + || print_g || (! Vfixed_point_format && fw > Voutput_max_field_width))) { - int exp_field = 4; - if (x_max > 100 || x_min > 100) - exp_field++; + if (print_g) + fmt = float_format (); + else + { + int exp_field = 4; + if (x_max > 100 || x_min > 100) + exp_field++; - fw = sign + 2 + prec + exp_field; + fw = sign + 2 + prec + exp_field; - fmt = float_format (fw, prec - 1, std::ios::scientific); + fmt = float_format (fw, prec - 1, std::ios::scientific); + } if (print_big_e) fmt.uppercase (); @@ -1163,7 +1213,7 @@ static inline void pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) { - if (Vfixed_point_format && scale != 1.0) + if (Vfixed_point_format && ! print_g && scale != 1.0) d /= scale; pr_any_float (curr_real_fmt, os, d, fw); @@ -1179,7 +1229,8 @@ pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, int i_fw = 0, double scale = 1.0) { - Complex tmp = (Vfixed_point_format && scale != 1.0) ? c / scale : c; + Complex tmp + = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; double r = tmp.real (); @@ -1230,7 +1281,7 @@ static void pr_scale_header (std::ostream& os, double scale) { - if (Vfixed_point_format && scale != 1.0) + if (Vfixed_point_format && ! print_g && scale != 1.0) { os << " " << std::setw (8) << std::setprecision (1) @@ -1877,6 +1928,7 @@ bit_format = 0; print_e = false; print_big_e = false; + print_g = false; } static void @@ -1912,6 +1964,17 @@ print_e = true; print_big_e = true; } + else if (arg == "g") + { + init_format_state (); + print_g = true; + } + else if (arg == "G") + { + init_format_state (); + print_g = true; + print_big_e = true; + } else { error ("format: unrecognized option `short %s'", @@ -1922,7 +1985,7 @@ else init_format_state (); - set_output_prec_and_fw (3, 8); + set_output_prec_and_fw (5, 10); } else if (arg == "long") { @@ -1941,6 +2004,17 @@ print_e = true; print_big_e = true; } + else if (arg == "g") + { + init_format_state (); + print_g = true; + } + else if (arg == "G") + { + init_format_state (); + print_g = true; + print_big_e = true; + } else { error ("format: unrecognized option `long %s'", @@ -1951,7 +2025,7 @@ else init_format_state (); - set_output_prec_and_fw (15, 24); + set_output_prec_and_fw (15, 20); } else if (arg == "hex") { @@ -2021,8 +2095,9 @@ @table @code\n\ @item short\n\ Octave will try to print numbers with at\n\ -least 3 significant figures within a field that is a maximum of 8\n\ -characters wide.\n\ +least 5 significant figures within a field that is a maximum of 10\n\ +characters wide (not counting additional spacing that is added between\n\ +columns of a matrix).\n\ \n\ If Octave is unable to format a matrix so that columns line up on the\n\ decimal point and all the numbers fit within the maximum field width,\n\ @@ -2030,7 +2105,8 @@ \n\ @item long\n\ Octave will try to print numbers with at least 15 significant figures\n\ -within a field that is a maximum of 24 characters wide.\n\ +within a field that is a maximum of 20 characters wide (not counting\n\ +additional spacing that is added between columns of a matrix).\n\ \n\ As will the @samp{short} format, Octave will switch to an @samp{e}\n\ format if it is unable to format a matrix so that columns line up on the\n\ @@ -2040,14 +2116,52 @@ @itemx short e\n\ The same as @samp{format long} or @samp{format short} but always display\n\ output with an @samp{e} format. For example, with the @samp{short e}\n\ -format, pi is displayed as @code{3.14e+00}.\n\ +format, @code{pi} is displayed as @code{3.14e+00}.\n\ \n\ @item long E\n\ @itemx short E\n\ The same as @samp{format long e} or @samp{format short e} but always\n\ display output with an uppercase @samp{E} format. For example, with\n\ -the @samp{long E} format, pi is displayed as\n\ +the @samp{long E} format, @code{pi} is displayed as\n\ @code{3.14159265358979E+00}.\n\ +@item long g\n\ +@itemx short g\n\ +Choose between normal @samp{long} (or @samp{short}) and and\n\ +@samp{long e} (or @samp{short e}) formats based on the magnitude\n\ +of the number. For example, with the @samp{short g} format,\n\ +@code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ +\n\ +@example\n\ +@group\n\ +ans =\n\ +\n\ + 3.1416\n\ + 9.8696\n\ + 97.409\n\ + 9488.5\n\ + 9.0032e+07\n\ + 8.1058e+15\n\ +@end group\n\ +@end example\n\ +\n\ +@item long G\n\ +@itemx short G\n\ +The same as @samp{format long g} or @samp{format short g} but use an\n\ +uppercase @samp{E} format. For example, with the @samp{short G} format,\n\ +@code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ +\n\ +@example\n\ +@group\n\ +ans =\n\ +\n\ + 3.1416\n\ + 9.8696\n\ + 97.409\n\ + 9488.5\n\ + 9.0032E+07\n\ + 8.1058E+15\n\ +@end group\n\ +@end example\n\ \n\ @item free\n\ @itemx none\n\