diff 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
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Wed Feb 21 08:24:41 2018 -0500
+++ b/libinterp/corefcn/pr-output.cc	Wed Feb 21 15:41:52 2018 -0500
@@ -436,23 +436,28 @@
 struct pr_output_traits
 {
   static const int digits10;
+  static const int max_field_width;
 };
 
 template <>
 struct pr_output_traits<double>
 {
   static const int digits10;
+  static const int max_field_width;
 };
 
 const int pr_output_traits<double>::digits10 = 16;
+const int pr_output_traits<double>::max_field_width = 21;
 
 template <>
 struct pr_output_traits<float>
 {
   static const int digits10;
+  static const int max_field_width;
 };
 
 const int pr_output_traits<float>::digits10 = 8;
+const int pr_output_traits<float>::max_field_width = 13;
 
 // FIXME: it would be nice to share more code among these functions,..
 
@@ -517,7 +522,8 @@
     }
 
   if (! (rat_format || bank_format || hex_format || bit_format)
-      && (print_e || print_g || print_eng))
+      && (print_e || print_g || print_eng
+          || fw > pr_output_traits<T>::max_field_width))
     {
       if (print_g)
         fmt = float_format ();
@@ -663,7 +669,10 @@
     }
 
   if (! (rat_format || bank_format || hex_format || bit_format)
-      && (print_e || print_eng || print_g))
+      && (print_e || print_eng || print_g
+          || (! Vfixed_point_format
+              && (ld + rd > pr_output_traits<T>::digits10
+                  || fw > pr_output_traits<T>::max_field_width))))
     {
       if (print_g)
         fmt = float_format ();
@@ -834,7 +843,11 @@
     }
 
   if (! (rat_format || bank_format || hex_format || bit_format)
-      && (print_e || print_eng || print_g))
+      && (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))))
     {
       if (print_g)
         {
@@ -1040,7 +1053,11 @@
     }
 
   if (! (rat_format || bank_format || hex_format || bit_format)
-      && (print_e || print_eng || print_g))
+      && (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))))
     {
       if (print_g)
         {
@@ -1232,7 +1249,10 @@
     }
 
   if (! (rat_format || bank_format || hex_format || bit_format)
-      && (print_e || print_eng || print_g))
+      && (print_e || print_eng || print_g
+          || (! Vfixed_point_format
+              && (ld + rd > pr_output_traits<T>::digits10
+                  || fw > pr_output_traits<T>::max_field_width))))
     {
       if (print_g)
         fmt = float_format ();