changeset 31978:1f7958de177f stable

Fix display of scalar complex variables with mixed Inf/NaN and floating point values (bug #63961) * pr-output.cc (make_complex_scalar_format): Skip using isfinite() to influence field with variables r_x and i_x. * pr-output.cc (make_complex_format): Restrict code path for integers to only take place when "int_only" is true (don't take this path when "inf_or_nan" is true). For case of real values, guarantee a minimum fieldwidth of 3 if "inf_or_nan" is true.
author Rik <rik@octave.org>
date Fri, 07 Apr 2023 12:18:28 -0700
parents 87beb2f167ea
children 1168f6aa35f8 86eb373a6c64
files libinterp/corefcn/pr-output.cc
diffstat 1 files changed, 11 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Thu Apr 06 12:13:26 2023 -0700
+++ b/libinterp/corefcn/pr-output.cc	Fri Apr 07 12:18:28 2023 -0700
@@ -755,7 +755,7 @@
       i_fw = 8 * sizeof (T);
       rd = 0;
     }
-  else if (inf_or_nan || int_only)
+  else if (int_only)
     {
       int digits = (x_max > x_min ? x_max : x_min);
       i_fw = (digits <= 0 ? 1 : digits);
@@ -765,14 +765,9 @@
           i_fw = 3;
           r_fw = 4;
         }
-
-      if (int_only)
-        {
-          ld = digits;
-          rd = 0;
-        }
+      ld = r_fw;
     }
-  else
+  else  // ordinary case of floating point numeric values
     {
       int ld_max, rd_max;
       if (x_max > 0)
@@ -819,6 +814,11 @@
 
       i_fw = ld + 1 + rd;
       r_fw = i_fw + 1;
+      if (inf_or_nan && i_fw < 3)
+        {
+          i_fw = 3;
+          r_fw = 4;
+        }
     }
 
   if (! (rat_format || bank_format || hex_format || bit_format)
@@ -872,7 +872,7 @@
           i_fmt.uppercase ();
         }
     }
-  else if (! bank_format && (inf_or_nan || int_only))
+  else if (! bank_format && int_only)
     {
       r_fmt = float_format (r_fw, ld);
       i_fmt = float_format (i_fw, ld);
@@ -904,11 +904,8 @@
   T r_abs = (rp < 0 ? -rp : rp);
   T i_abs = (ip < 0 ? -ip : ip);
 
-  int r_x = (! octave::math::isfinite (rp)
-             || r_abs == 0) ? 0 : num_digits (r_abs);
-
-  int i_x = (! octave::math::isfinite (ip)
-             || i_abs == 0) ? 0 : num_digits (i_abs);
+  int r_x = (r_abs == 0 ? 0 : num_digits (r_abs));
+  int i_x = (i_abs == 0 ? 0 : num_digits (i_abs));
 
   int x_max, x_min;