Mercurial > octave
comparison libinterp/corefcn/pr-output.cc @ 24785:504869574c89
restore auto switch to E formats octave_print_internal functions
* pr-output.cc (pr_output_traits::max_field_width): New variable.
(make_real_format, make_real_matrix_format, make_complex_format,
make_complex_matrix_format, make_range_format): Switch to E format if
computed field width exceeds max field width for type or if computed
number of digits to display exceeds max meaningful digits for type.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Feb 2018 15:41:52 -0500 |
parents | 4d945f2e5914 |
children | 0aeef407b04e |
comparison
equal
deleted
inserted
replaced
24784:4d945f2e5914 | 24785:504869574c89 |
---|---|
434 | 434 |
435 template <typename> | 435 template <typename> |
436 struct pr_output_traits | 436 struct pr_output_traits |
437 { | 437 { |
438 static const int digits10; | 438 static const int digits10; |
439 static const int max_field_width; | |
439 }; | 440 }; |
440 | 441 |
441 template <> | 442 template <> |
442 struct pr_output_traits<double> | 443 struct pr_output_traits<double> |
443 { | 444 { |
444 static const int digits10; | 445 static const int digits10; |
446 static const int max_field_width; | |
445 }; | 447 }; |
446 | 448 |
447 const int pr_output_traits<double>::digits10 = 16; | 449 const int pr_output_traits<double>::digits10 = 16; |
450 const int pr_output_traits<double>::max_field_width = 21; | |
448 | 451 |
449 template <> | 452 template <> |
450 struct pr_output_traits<float> | 453 struct pr_output_traits<float> |
451 { | 454 { |
452 static const int digits10; | 455 static const int digits10; |
456 static const int max_field_width; | |
453 }; | 457 }; |
454 | 458 |
455 const int pr_output_traits<float>::digits10 = 8; | 459 const int pr_output_traits<float>::digits10 = 8; |
460 const int pr_output_traits<float>::max_field_width = 13; | |
456 | 461 |
457 // FIXME: it would be nice to share more code among these functions,.. | 462 // FIXME: it would be nice to share more code among these functions,.. |
458 | 463 |
459 // Works for double and float. | 464 // Works for double and float. |
460 | 465 |
515 if (inf_or_nan && fw < 4) | 520 if (inf_or_nan && fw < 4) |
516 fw = 4; | 521 fw = 4; |
517 } | 522 } |
518 | 523 |
519 if (! (rat_format || bank_format || hex_format || bit_format) | 524 if (! (rat_format || bank_format || hex_format || bit_format) |
520 && (print_e || print_g || print_eng)) | 525 && (print_e || print_g || print_eng |
526 || fw > pr_output_traits<T>::max_field_width)) | |
521 { | 527 { |
522 if (print_g) | 528 if (print_g) |
523 fmt = float_format (); | 529 fmt = float_format (); |
524 else | 530 else |
525 { | 531 { |
661 if (inf_or_nan && fw < 4) | 667 if (inf_or_nan && fw < 4) |
662 fw = 4; | 668 fw = 4; |
663 } | 669 } |
664 | 670 |
665 if (! (rat_format || bank_format || hex_format || bit_format) | 671 if (! (rat_format || bank_format || hex_format || bit_format) |
666 && (print_e || print_eng || print_g)) | 672 && (print_e || print_eng || print_g |
673 || (! Vfixed_point_format | |
674 && (ld + rd > pr_output_traits<T>::digits10 | |
675 || fw > pr_output_traits<T>::max_field_width)))) | |
667 { | 676 { |
668 if (print_g) | 677 if (print_g) |
669 fmt = float_format (); | 678 fmt = float_format (); |
670 else | 679 else |
671 { | 680 { |
832 r_fw = 4; | 841 r_fw = 4; |
833 } | 842 } |
834 } | 843 } |
835 | 844 |
836 if (! (rat_format || bank_format || hex_format || bit_format) | 845 if (! (rat_format || bank_format || hex_format || bit_format) |
837 && (print_e || print_eng || print_g)) | 846 && (print_e || print_eng || print_g |
847 || (! Vfixed_point_format | |
848 && (ld + rd > pr_output_traits<T>::digits10 | |
849 || r_fw > pr_output_traits<T>::max_field_width | |
850 || i_fw > pr_output_traits<T>::max_field_width)))) | |
838 { | 851 { |
839 if (print_g) | 852 if (print_g) |
840 { | 853 { |
841 r_fmt = float_format (); | 854 r_fmt = float_format (); |
842 i_fmt = float_format (); | 855 i_fmt = float_format (); |
1038 r_fw = 4; | 1051 r_fw = 4; |
1039 } | 1052 } |
1040 } | 1053 } |
1041 | 1054 |
1042 if (! (rat_format || bank_format || hex_format || bit_format) | 1055 if (! (rat_format || bank_format || hex_format || bit_format) |
1043 && (print_e || print_eng || print_g)) | 1056 && (print_e || print_eng || print_g |
1057 || (! Vfixed_point_format | |
1058 && (ld + rd > pr_output_traits<T>::digits10 | |
1059 || r_fw > pr_output_traits<T>::max_field_width | |
1060 || i_fw > pr_output_traits<T>::max_field_width)))) | |
1044 { | 1061 { |
1045 if (print_g) | 1062 if (print_g) |
1046 { | 1063 { |
1047 r_fmt = float_format (); | 1064 r_fmt = float_format (); |
1048 i_fmt = float_format (); | 1065 i_fmt = float_format (); |
1230 | 1247 |
1231 fw = ld + rd + 3; | 1248 fw = ld + rd + 3; |
1232 } | 1249 } |
1233 | 1250 |
1234 if (! (rat_format || bank_format || hex_format || bit_format) | 1251 if (! (rat_format || bank_format || hex_format || bit_format) |
1235 && (print_e || print_eng || print_g)) | 1252 && (print_e || print_eng || print_g |
1253 || (! Vfixed_point_format | |
1254 && (ld + rd > pr_output_traits<T>::digits10 | |
1255 || fw > pr_output_traits<T>::max_field_width)))) | |
1236 { | 1256 { |
1237 if (print_g) | 1257 if (print_g) |
1238 fmt = float_format (); | 1258 fmt = float_format (); |
1239 else | 1259 else |
1240 { | 1260 { |