changeset 27466:6e8dac65d405

Switch to scientific notation for format short when values are large or small (bug #56971). * pr-output.cc (make_real_format, make_real_matrix_format, make_complex_format, make_complex_matrix_format, make_range_format): Switch to scientific notation when number of significant digits (ld + rd) exceeds 1.5 * output_precision.
author Rik <rik@octave.org>
date Tue, 01 Oct 2019 22:06:01 -0700
parents fdcec1c0842a
children c7a898396151
files libinterp/corefcn/pr-output.cc
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Mon Sep 30 11:29:02 2019 -0700
+++ b/libinterp/corefcn/pr-output.cc	Tue Oct 01 22:06:01 2019 -0700
@@ -417,7 +417,8 @@
   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))
+          || fw > pr_output_traits<T>::max_field_width
+          || ld + rd > (1.5 * prec)))
     {
       if (print_g)
         fmt = float_format (prec, prec);
@@ -599,7 +600,8 @@
       && (print_e || print_eng || print_g
           || (! Vfixed_point_format
               && (ld + rd > pr_output_traits<T>::digits10
-                  || fw > pr_output_traits<T>::max_field_width))))
+                  || fw > pr_output_traits<T>::max_field_width
+                  || ld + rd > (1.5 * prec)))))
     {
       if (print_g)
         fmt = float_format (prec+6, prec);
@@ -785,7 +787,8 @@
       && (print_e || print_eng || print_g
           || 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))
+          || i_fw > pr_output_traits<T>::max_field_width
+          || ld + rd > (1.5 * prec)))
     {
       if (print_g)
         {
@@ -1022,7 +1025,8 @@
           || (! 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))))
+                  || i_fw > pr_output_traits<T>::max_field_width
+                  || ld + rd > (1.5 * prec)))))
     {
       if (print_g)
         {
@@ -1241,7 +1245,8 @@
       && (print_e || print_eng || print_g
           || (! Vfixed_point_format
               && (ld + rd > pr_output_traits<T>::digits10
-                  || fw > pr_output_traits<T>::max_field_width))))
+                  || fw > pr_output_traits<T>::max_field_width
+                  || ld + rd > (1.5 * prec)))))
     {
       if (print_g)
         fmt = float_format (prec+6, prec);