changeset 27454:43ece0b8318b

Fix display of complex values when fixed_point_format is true (bug #56961). * pr-output.cc (pr_imag_float): Add code to scale input "val" in the same way that pr_float() does. * pr-output.cc (pr_float (..., const std::complex<T>& cval)): Remove code to do scaling here.
author Rik <rik@octave.org>
date Sat, 28 Sep 2019 05:19:40 -0700
parents 05f84e5cb08a
children cfe08c0e2c6d
files libinterp/corefcn/pr-output.cc
diffstat 1 files changed, 8 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/pr-output.cc	Sat Sep 28 04:20:49 2019 -0700
+++ b/libinterp/corefcn/pr-output.cc	Sat Sep 28 05:19:40 2019 -0700
@@ -124,8 +124,7 @@
   // compiler dependent if any of the arguments are negative.  Since
   // this function will need to work on negative arguments, and we want
   // to avoid portability issues, we re-implement the modulo function to
-  // the desired behavior (truncation).  There may be a gnulib
-  // replacement.
+  // the desired behavior (truncation).  There may be a gnulib replacement.
 
   // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO,
   // IEC. 2003 . "the binary % operator yields the remainder from the
@@ -1479,6 +1478,11 @@
 static inline void
 pr_imag_float (std::ostream& os, const float_display_format& fmt, T val)
 {
+  double scale = fmt.scale_factor ();
+
+  if (Vfixed_point_format && ! (print_g || print_e) && scale != 1)
+    val /= scale;
+
   pr_any_float (os, fmt.imag_format (), val);
 }
 
@@ -1487,24 +1491,13 @@
 pr_float (std::ostream& os, const float_display_format& fmt,
           const std::complex<T>& cval)
 {
-  // FIXME: should we range check this value?  It is stored as a double
-  // to simplify the implementation, but should always correspond to the
-  // type of value we are displaying.
-
-  double dscale = fmt.scale_factor ();
-  T scale = static_cast<T> (dscale);
-
-  std::complex<T> tmp
-    = ((Vfixed_point_format && ! (print_g || print_e) && scale != 1)
-       ? cval / scale : cval);
-
-  T r = tmp.real ();
+  T r = cval.real ();
 
   pr_float (os, fmt, r);
 
   if (! bank_format)
     {
-      T i = tmp.imag ();
+      T i = cval.imag ();
       if (! (hex_format || bit_format) && lo_ieee_signbit (i))
         {
           os << " - ";