Mercurial > octave
comparison libinterp/corefcn/pr-output.cc @ 24787:168d5b43c840
store scale factor in float_display_format object
* pr-flt-fmt.h (float_display_format::m_scale): New data member.
(float_display_format::scale_factor): New function.
* pr-output.h, pr-output.cc: Store scale factor in format object.
Don't pass scale factor separately in function argument lists.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Feb 2018 22:32:55 -0500 |
parents | 0aeef407b04e |
children | 6f04028d5d86 |
comparison
equal
deleted
inserted
replaced
24786:0aeef407b04e | 24787:168d5b43c840 |
---|---|
463 | 463 |
464 // Works for double and float. | 464 // Works for double and float. |
465 | 465 |
466 template <typename T> | 466 template <typename T> |
467 static inline float_display_format | 467 static inline float_display_format |
468 make_real_format (int digits, bool inf_or_nan, | 468 make_real_format (int digits, bool inf_or_nan, bool int_only) |
469 bool int_only) | |
470 { | 469 { |
471 float_format fmt; | 470 float_format fmt; |
472 | 471 |
473 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 472 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
474 | 473 |
598 template <typename T> | 597 template <typename T> |
599 static inline float_display_format | 598 static inline float_display_format |
600 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan, | 599 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
601 int int_or_inf_or_nan) | 600 int int_or_inf_or_nan) |
602 { | 601 { |
602 T scale = ((x_max == 0 || int_or_inf_or_nan) | |
603 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | |
604 | |
603 float_format fmt; | 605 float_format fmt; |
604 | 606 |
605 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 607 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
606 | 608 |
607 int fw, ld, rd; | 609 int fw, ld, rd; |
718 else if (! bank_format && int_or_inf_or_nan) | 720 else if (! bank_format && int_or_inf_or_nan) |
719 fmt = float_format (fw, rd); | 721 fmt = float_format (fw, rd); |
720 else | 722 else |
721 fmt = float_format (fw, rd, std::ios::fixed); | 723 fmt = float_format (fw, rd, std::ios::fixed); |
722 | 724 |
723 return float_display_format (fmt); | 725 return float_display_format (scale, fmt); |
724 } | 726 } |
725 | 727 |
726 template <typename MT, typename ELT_T> | 728 template <typename MT> |
727 static inline float_display_format | 729 static inline float_display_format |
728 make_format_internal (const MT& m, ELT_T& scale) | 730 make_matrix_format (const MT& m) |
729 { | 731 { |
730 assert (m.ndims () == 2); | 732 assert (m.ndims () == 2); |
731 | 733 |
732 if (free_format) | 734 if (free_format) |
733 return float_display_format (); | 735 return float_display_format (); |
735 bool inf_or_nan = m.any_element_is_inf_or_nan (); | 737 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
736 | 738 |
737 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); | 739 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
738 | 740 |
739 MT m_abs = m.abs (); | 741 MT m_abs = m.abs (); |
742 | |
743 typedef typename MT::element_type ELT_T; | |
744 | |
740 ELT_T max_abs = pr_max_internal (m_abs); | 745 ELT_T max_abs = pr_max_internal (m_abs); |
741 ELT_T min_abs = pr_min_internal (m_abs); | 746 ELT_T min_abs = pr_min_internal (m_abs); |
742 | 747 |
743 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); | 748 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); |
744 | 749 |
745 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); | 750 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); |
746 | 751 |
747 scale = ((x_max == 0 || int_or_inf_or_nan) | |
748 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | |
749 | |
750 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan, | 752 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan, |
751 int_or_inf_or_nan); | 753 int_or_inf_or_nan); |
752 } | 754 } |
753 | 755 |
756 template <> | |
754 float_display_format | 757 float_display_format |
755 make_format (const Matrix& m, double& scale) | 758 make_format (const Matrix& m) |
756 { | 759 { |
757 return make_format_internal<Matrix, double> (m, scale); | 760 return make_matrix_format (m); |
758 } | 761 } |
759 | 762 |
763 template <> | |
760 float_display_format | 764 float_display_format |
761 make_format (const FloatMatrix& m, float& scale) | 765 make_format (const FloatMatrix& m) |
762 { | 766 { |
763 return make_format_internal<FloatMatrix, float> (m, scale); | 767 return make_matrix_format (m); |
764 } | 768 } |
765 | 769 |
766 template <typename T> | 770 template <typename T> |
767 static inline float_display_format | 771 static inline float_display_format |
768 make_complex_format (int x_max, int x_min, int r_x, | 772 make_complex_format (int x_max, int x_min, int r_x, |
978 static inline float_display_format | 982 static inline float_display_format |
979 make_complex_matrix_format (int x_max, int x_min, int r_x_max, | 983 make_complex_matrix_format (int x_max, int x_min, int r_x_max, |
980 int r_x_min, bool inf_or_nan, | 984 int r_x_min, bool inf_or_nan, |
981 int int_or_inf_or_nan) | 985 int int_or_inf_or_nan) |
982 { | 986 { |
987 T scale = ((x_max == 0 || int_or_inf_or_nan) | |
988 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | |
989 | |
983 float_format r_fmt; | 990 float_format r_fmt; |
984 float_format i_fmt; | 991 float_format i_fmt; |
985 | 992 |
986 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 993 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
987 | 994 |
1138 { | 1145 { |
1139 r_fmt = float_format (r_fw, rd, std::ios::fixed); | 1146 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1140 i_fmt = float_format (i_fw, rd, std::ios::fixed); | 1147 i_fmt = float_format (i_fw, rd, std::ios::fixed); |
1141 } | 1148 } |
1142 | 1149 |
1143 return float_display_format (r_fmt, i_fmt); | 1150 return float_display_format (scale, r_fmt, i_fmt); |
1144 } | 1151 } |
1145 | 1152 |
1146 template <typename CMT, typename RMT, typename ELT_T> | 1153 template <typename CMT> |
1147 static inline float_display_format | 1154 static inline float_display_format |
1148 make_format_internal (const CMT& cm, ELT_T& scale) | 1155 make_complex_matrix_format (const CMT& cm) |
1149 { | 1156 { |
1150 if (free_format) | 1157 if (free_format) |
1151 return float_display_format (); | 1158 return float_display_format (); |
1159 | |
1160 typedef typename CMT::real_matrix_type RMT; | |
1161 typedef typename CMT::real_elt_type ELT_T; | |
1152 | 1162 |
1153 RMT rp = real (cm); | 1163 RMT rp = real (cm); |
1154 RMT ip = imag (cm); | 1164 RMT ip = imag (cm); |
1155 | 1165 |
1156 bool inf_or_nan = cm.any_element_is_inf_or_nan (); | 1166 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1175 int i_x_min = (i_min_abs == 0 ? 0 : num_digits (i_min_abs)); | 1185 int i_x_min = (i_min_abs == 0 ? 0 : num_digits (i_min_abs)); |
1176 | 1186 |
1177 int x_max = (r_x_max > i_x_max ? r_x_max : i_x_max); | 1187 int x_max = (r_x_max > i_x_max ? r_x_max : i_x_max); |
1178 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min); | 1188 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min); |
1179 | 1189 |
1180 scale = ((x_max == 0 || int_or_inf_or_nan) | |
1181 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | |
1182 | |
1183 return make_complex_matrix_format<ELT_T> (x_max, x_min, r_x_max, r_x_min, | 1190 return make_complex_matrix_format<ELT_T> (x_max, x_min, r_x_max, r_x_min, |
1184 inf_or_nan, int_or_inf_or_nan); | 1191 inf_or_nan, int_or_inf_or_nan); |
1185 } | 1192 } |
1186 | 1193 |
1194 template <> | |
1187 float_display_format | 1195 float_display_format |
1188 make_format (const ComplexMatrix& cm, double& scale) | 1196 make_format (const ComplexMatrix& cm) |
1189 { | 1197 { |
1190 return make_format_internal<ComplexMatrix, Matrix, double> (cm, scale); | 1198 return make_complex_matrix_format (cm); |
1191 } | 1199 } |
1192 | 1200 |
1201 template <> | |
1193 float_display_format | 1202 float_display_format |
1194 make_format (const FloatComplexMatrix& cm, float& scale) | 1203 make_format (const FloatComplexMatrix& cm) |
1195 { | 1204 { |
1196 return make_format_internal<FloatComplexMatrix, FloatMatrix, float> (cm, scale); | 1205 return make_complex_matrix_format (cm); |
1206 } | |
1207 | |
1208 template <> | |
1209 float_display_format | |
1210 make_format (const boolNDArray&) | |
1211 { | |
1212 return float_display_format (float_format (1, 1)); | |
1197 } | 1213 } |
1198 | 1214 |
1199 template <typename T> | 1215 template <typename T> |
1200 static inline float_display_format | 1216 static inline float_display_format |
1201 make_range_format (int x_max, int x_min, int all_ints) | 1217 make_range_format (int x_max, int x_min, int all_ints) |
1202 { | 1218 { |
1219 double scale = ((x_max == 0 || all_ints) | |
1220 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | |
1221 | |
1203 float_format fmt; | 1222 float_format fmt; |
1204 | 1223 |
1205 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); | 1224 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1206 | 1225 |
1207 int fw, ld, rd; | 1226 int fw, ld, rd; |
1306 else if (! bank_format && all_ints) | 1325 else if (! bank_format && all_ints) |
1307 fmt = float_format (fw, rd); | 1326 fmt = float_format (fw, rd); |
1308 else | 1327 else |
1309 fmt = float_format (fw, rd, std::ios::fixed); | 1328 fmt = float_format (fw, rd, std::ios::fixed); |
1310 | 1329 |
1311 return float_display_format (fmt); | 1330 return float_display_format (scale, fmt); |
1312 } | 1331 } |
1313 | 1332 |
1333 template <> | |
1314 float_display_format | 1334 float_display_format |
1315 make_format (const Range& r, double& scale) | 1335 make_format (const Range& r) |
1316 { | 1336 { |
1317 if (free_format) | 1337 if (free_format) |
1318 return float_display_format (); | 1338 return float_display_format (); |
1319 | 1339 |
1320 double r_min = r.base (); | 1340 double r_min = r.base (); |
1333 double min_abs = (r_min < 0 ? -r_min : r_min); | 1353 double min_abs = (r_min < 0 ? -r_min : r_min); |
1334 | 1354 |
1335 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); | 1355 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); |
1336 | 1356 |
1337 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); | 1357 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); |
1338 | |
1339 scale = ((x_max == 0 || all_ints) | |
1340 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); | |
1341 | 1358 |
1342 return make_range_format<double> (x_max, x_min, all_ints); | 1359 return make_range_format<double> (x_max, x_min, all_ints); |
1343 } | 1360 } |
1344 | 1361 |
1345 template <typename T> | 1362 template <typename T> |
1496 os << pr_formatted_float<T> (fmt, val); | 1513 os << pr_formatted_float<T> (fmt, val); |
1497 } | 1514 } |
1498 | 1515 |
1499 template <typename T> | 1516 template <typename T> |
1500 static inline void | 1517 static inline void |
1501 pr_float (std::ostream& os, const float_display_format& fmt, T val, | 1518 pr_float (std::ostream& os, const float_display_format& fmt, T val) |
1502 T scale = 1) | 1519 { |
1503 { | 1520 double scale = fmt.scale_factor (); |
1521 | |
1504 if (Vfixed_point_format && ! print_g && scale != 1) | 1522 if (Vfixed_point_format && ! print_g && scale != 1) |
1505 val /= scale; | 1523 val /= scale; |
1506 | 1524 |
1507 pr_any_float (os, fmt.real_format (), val); | 1525 pr_any_float (os, fmt.real_format (), val); |
1508 } | 1526 } |
1515 } | 1533 } |
1516 | 1534 |
1517 template <typename T> | 1535 template <typename T> |
1518 static inline void | 1536 static inline void |
1519 pr_complex (std::ostream& os, const float_display_format& fmt, | 1537 pr_complex (std::ostream& os, const float_display_format& fmt, |
1520 const std::complex<T>& cval, T scale = 1) | 1538 const std::complex<T>& cval) |
1521 { | 1539 { |
1540 // FIXME: should we range check this value? It is stored as a double | |
1541 // to simplify the implementation, but should always correspond to the | |
1542 // type of value we are displaying. | |
1543 | |
1544 double dscale = fmt.scale_factor (); | |
1545 T scale = static_cast<T> (dscale); | |
1546 | |
1522 std::complex<T> tmp | 1547 std::complex<T> tmp |
1523 = ((Vfixed_point_format && ! print_g && scale != 1) | 1548 = ((Vfixed_point_format && ! print_g && scale != 1) |
1524 ? cval / scale : cval); | 1549 ? cval / scale : cval); |
1525 | 1550 |
1526 T r = tmp.real (); | 1551 T r = tmp.real (); |
1586 if (Vprint_empty_dimensions) | 1611 if (Vprint_empty_dimensions) |
1587 os << '(' << dims.str () << ')'; | 1612 os << '(' << dims.str () << ')'; |
1588 } | 1613 } |
1589 } | 1614 } |
1590 | 1615 |
1591 template <typename T> | |
1592 static inline void | 1616 static inline void |
1593 pr_scale_header (std::ostream& os, T scale) | 1617 pr_scale_header (std::ostream& os, double scale) |
1594 { | 1618 { |
1595 if (Vfixed_point_format && ! print_g && scale != 1) | 1619 if (Vfixed_point_format && ! print_g && scale != 1) |
1596 { | 1620 { |
1597 octave::preserve_stream_state stream_state (os); | 1621 octave::preserve_stream_state stream_state (os); |
1598 | 1622 |
1647 os << plus_format_chars[0]; | 1671 os << plus_format_chars[0]; |
1648 else if (val < T (0)) | 1672 else if (val < T (0)) |
1649 os << plus_format_chars[1]; | 1673 os << plus_format_chars[1]; |
1650 else | 1674 else |
1651 os << plus_format_chars[2]; | 1675 os << plus_format_chars[2]; |
1652 } | |
1653 | |
1654 template <> | |
1655 float_display_format | |
1656 make_format (const Range& rng) | |
1657 { | |
1658 double scale = 0; | |
1659 return make_format (rng, scale); | |
1660 } | |
1661 | |
1662 template <> | |
1663 float_display_format | |
1664 make_format (const NDArray& nda) | |
1665 { | |
1666 double scale = 0; | |
1667 return make_format (Matrix (nda), scale); | |
1668 } | |
1669 | |
1670 template <> | |
1671 float_display_format | |
1672 make_format (const FloatNDArray& nda) | |
1673 { | |
1674 float scale = 0; | |
1675 return make_format (FloatMatrix (nda), scale); | |
1676 } | |
1677 | |
1678 template <> | |
1679 float_display_format | |
1680 make_format (const ComplexNDArray& nda) | |
1681 { | |
1682 double scale = 0; | |
1683 return make_format (ComplexMatrix (nda), scale); | |
1684 } | |
1685 | |
1686 template <> | |
1687 float_display_format | |
1688 make_format (const FloatComplexNDArray& nda) | |
1689 { | |
1690 float scale = 0; | |
1691 return make_format (FloatComplexMatrix (nda), scale); | |
1692 } | |
1693 | |
1694 template <> | |
1695 float_display_format | |
1696 make_format (const boolNDArray&) | |
1697 { | |
1698 return float_display_format (float_format (1, 1)); | |
1699 } | 1676 } |
1700 | 1677 |
1701 // FIXME: all this mess with abs is an attempt to avoid seeing | 1678 // FIXME: all this mess with abs is an attempt to avoid seeing |
1702 // | 1679 // |
1703 // warning: comparison of unsigned expression < 0 is always false | 1680 // warning: comparison of unsigned expression < 0 is always false |
1901 print_empty_matrix (os, nr, nc, pr_as_read_syntax); | 1878 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1902 else if (plus_format && ! pr_as_read_syntax) | 1879 else if (plus_format && ! pr_as_read_syntax) |
1903 pr_plus_format_matrix (os, m); | 1880 pr_plus_format_matrix (os, m); |
1904 else | 1881 else |
1905 { | 1882 { |
1906 typename MT::element_type scale = 1; | 1883 float_display_format fmt = make_format (m); |
1907 float_display_format fmt = make_format (m, scale); | |
1908 int fw = fmt.real_format().fw; | 1884 int fw = fmt.real_format().fw; |
1909 int column_width = fw + 2; | 1885 int column_width = fw + 2; |
1910 octave_idx_type total_width = nc * column_width; | 1886 octave_idx_type total_width = nc * column_width; |
1911 octave_idx_type max_width = octave::command_editor::terminal_cols (); | 1887 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
1912 | 1888 |
1974 } | 1950 } |
1975 else | 1951 else |
1976 { | 1952 { |
1977 octave::preserve_stream_state stream_state (os); | 1953 octave::preserve_stream_state stream_state (os); |
1978 | 1954 |
1979 pr_scale_header (os, scale); | 1955 pr_scale_header (os, fmt.scale_factor ()); |
1980 | 1956 |
1981 for (octave_idx_type col = 0; col < nc; col += inc) | 1957 for (octave_idx_type col = 0; col < nc; col += inc) |
1982 { | 1958 { |
1983 octave_idx_type lim = (col + inc < nc ? col + inc : nc); | 1959 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
1984 | 1960 |
1993 { | 1969 { |
1994 octave_quit (); | 1970 octave_quit (); |
1995 | 1971 |
1996 os << " "; | 1972 os << " "; |
1997 | 1973 |
1998 pr_float (os, fmt, m(i,j), scale); | 1974 pr_float (os, fmt, m(i,j)); |
1999 } | 1975 } |
2000 | 1976 |
2001 if (i < nr - 1) | 1977 if (i < nr - 1) |
2002 os << "\n"; | 1978 os << "\n"; |
2003 } | 1979 } |
2018 print_empty_matrix (os, nr, nc, pr_as_read_syntax); | 1994 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2019 else if (plus_format && ! pr_as_read_syntax) | 1995 else if (plus_format && ! pr_as_read_syntax) |
2020 pr_plus_format_matrix (os, m); | 1996 pr_plus_format_matrix (os, m); |
2021 else | 1997 else |
2022 { | 1998 { |
2023 typename DMT::element_type scale = 1; | |
2024 float_display_format fmt | 1999 float_display_format fmt |
2025 = make_format (typename DMT::full_matrix_type (m.diag ()), scale); | 2000 = make_format (typename DMT::full_matrix_type (m.diag ())); |
2026 int fw = fmt.real_format().fw; | 2001 int fw = fmt.real_format().fw; |
2027 int column_width = fw + 2; | 2002 int column_width = fw + 2; |
2028 octave_idx_type total_width = nc * column_width; | 2003 octave_idx_type total_width = nc * column_width; |
2029 octave_idx_type max_width = octave::command_editor::terminal_cols (); | 2004 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
2030 | 2005 |
2091 | 2066 |
2092 os << "Diagonal Matrix\n"; | 2067 os << "Diagonal Matrix\n"; |
2093 if (! Vcompact_format) | 2068 if (! Vcompact_format) |
2094 os << "\n"; | 2069 os << "\n"; |
2095 | 2070 |
2096 pr_scale_header (os, scale); | 2071 pr_scale_header (os, fmt.scale_factor ()); |
2097 | 2072 |
2098 // kluge. Get the true width of a number. | 2073 // kluge. Get the true width of a number. |
2099 int zero_fw; | 2074 int zero_fw; |
2100 { | 2075 { |
2101 std::ostringstream tmp_oss; | 2076 std::ostringstream tmp_oss; |
2102 typename DMT::element_type zero = 0; | 2077 typename DMT::element_type zero = 0; |
2103 pr_float (tmp_oss, fmt, zero, scale); | 2078 pr_float (tmp_oss, fmt, zero); |
2104 zero_fw = tmp_oss.str ().length (); | 2079 zero_fw = tmp_oss.str ().length (); |
2105 } | 2080 } |
2106 | 2081 |
2107 for (octave_idx_type col = 0; col < nc; col += inc) | 2082 for (octave_idx_type col = 0; col < nc; col += inc) |
2108 { | 2083 { |
2120 octave_quit (); | 2095 octave_quit (); |
2121 | 2096 |
2122 os << " "; | 2097 os << " "; |
2123 | 2098 |
2124 if (i == j) | 2099 if (i == j) |
2125 pr_float (os, fmt, m(i,j), scale); | 2100 pr_float (os, fmt, m(i,j)); |
2126 else | 2101 else |
2127 os << std::setw (zero_fw) << '0'; | 2102 os << std::setw (zero_fw) << '0'; |
2128 | 2103 |
2129 } | 2104 } |
2130 | 2105 |
2314 print_empty_matrix (os, nr, nc, pr_as_read_syntax); | 2289 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2315 else if (plus_format && ! pr_as_read_syntax) | 2290 else if (plus_format && ! pr_as_read_syntax) |
2316 pr_plus_format_matrix (os, cm); | 2291 pr_plus_format_matrix (os, cm); |
2317 else | 2292 else |
2318 { | 2293 { |
2319 typename MT::real_elt_type scale = 1; | 2294 float_display_format fmt = make_format (cm); |
2320 float_display_format fmt = make_format (cm, scale); | |
2321 int r_fw = fmt.real_format().fw; | 2295 int r_fw = fmt.real_format().fw; |
2322 int i_fw = fmt.imag_format().fw; | 2296 int i_fw = fmt.imag_format().fw; |
2323 int column_width = i_fw + r_fw; | 2297 int column_width = i_fw + r_fw; |
2324 column_width += (rat_format || bank_format || hex_format | 2298 column_width += (rat_format || bank_format || hex_format |
2325 || bit_format) ? 2 : 7; | 2299 || bit_format) ? 2 : 7; |
2390 } | 2364 } |
2391 else | 2365 else |
2392 { | 2366 { |
2393 octave::preserve_stream_state stream_state (os); | 2367 octave::preserve_stream_state stream_state (os); |
2394 | 2368 |
2395 pr_scale_header (os, scale); | 2369 pr_scale_header (os, fmt.scale_factor ()); |
2396 | 2370 |
2397 for (octave_idx_type col = 0; col < nc; col += inc) | 2371 for (octave_idx_type col = 0; col < nc; col += inc) |
2398 { | 2372 { |
2399 octave_idx_type lim = (col + inc < nc ? col + inc : nc); | 2373 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
2400 | 2374 |
2409 { | 2383 { |
2410 octave_quit (); | 2384 octave_quit (); |
2411 | 2385 |
2412 os << " "; | 2386 os << " "; |
2413 | 2387 |
2414 pr_complex (os, fmt, cm(i,j), scale); | 2388 pr_complex (os, fmt, cm(i,j)); |
2415 } | 2389 } |
2416 | 2390 |
2417 if (i < nr - 1) | 2391 if (i < nr - 1) |
2418 os << "\n"; | 2392 os << "\n"; |
2419 } | 2393 } |
2434 print_empty_matrix (os, nr, nc, pr_as_read_syntax); | 2408 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2435 else if (plus_format && ! pr_as_read_syntax) | 2409 else if (plus_format && ! pr_as_read_syntax) |
2436 pr_plus_format_matrix (os, cm); | 2410 pr_plus_format_matrix (os, cm); |
2437 else | 2411 else |
2438 { | 2412 { |
2439 typename DMT::real_elt_type scale = 1; | |
2440 float_display_format fmt | 2413 float_display_format fmt |
2441 = make_format (typename DMT::full_matrix_type (cm.diag ()), scale); | 2414 = make_format (typename DMT::full_matrix_type (cm.diag ())); |
2442 int r_fw = fmt.real_format().fw; | 2415 int r_fw = fmt.real_format().fw; |
2443 int i_fw = fmt.imag_format().fw; | 2416 int i_fw = fmt.imag_format().fw; |
2444 int column_width = i_fw + r_fw; | 2417 int column_width = i_fw + r_fw; |
2445 column_width += (rat_format || bank_format || hex_format | 2418 column_width += (rat_format || bank_format || hex_format |
2446 || bit_format) ? 2 : 7; | 2419 || bit_format) ? 2 : 7; |
2510 | 2483 |
2511 os << "Diagonal Matrix\n"; | 2484 os << "Diagonal Matrix\n"; |
2512 if (! Vcompact_format) | 2485 if (! Vcompact_format) |
2513 os << "\n"; | 2486 os << "\n"; |
2514 | 2487 |
2515 pr_scale_header (os, scale); | 2488 pr_scale_header (os, fmt.scale_factor ()); |
2516 | 2489 |
2517 // kluge. Get the true width of a number. | 2490 // kluge. Get the true width of a number. |
2518 int zero_fw; | 2491 int zero_fw; |
2519 { | 2492 { |
2520 std::ostringstream tmp_oss; | 2493 std::ostringstream tmp_oss; |
2521 typename DMT::element_type zero = 0; | 2494 typename DMT::element_type zero = 0; |
2522 pr_complex (tmp_oss, fmt, zero, scale); | 2495 pr_complex (tmp_oss, fmt, zero); |
2523 zero_fw = tmp_oss.str ().length (); | 2496 zero_fw = tmp_oss.str ().length (); |
2524 } | 2497 } |
2525 | 2498 |
2526 for (octave_idx_type col = 0; col < nc; col += inc) | 2499 for (octave_idx_type col = 0; col < nc; col += inc) |
2527 { | 2500 { |
2539 octave_quit (); | 2512 octave_quit (); |
2540 | 2513 |
2541 os << " "; | 2514 os << " "; |
2542 | 2515 |
2543 if (i == j) | 2516 if (i == j) |
2544 pr_complex (os, fmt, cm(i,j), scale); | 2517 pr_complex (os, fmt, cm(i,j)); |
2545 else | 2518 else |
2546 os << std::setw (zero_fw) << '0'; | 2519 os << std::setw (zero_fw) << '0'; |
2547 } | 2520 } |
2548 | 2521 |
2549 if (i < nr - 1) | 2522 if (i < nr - 1) |
2775 | 2748 |
2776 if (plus_format && ! pr_as_read_syntax) | 2749 if (plus_format && ! pr_as_read_syntax) |
2777 pr_plus_format_matrix (os, r); | 2750 pr_plus_format_matrix (os, r); |
2778 else | 2751 else |
2779 { | 2752 { |
2780 double scale = 1; | 2753 float_display_format fmt = make_format (r); |
2781 float_display_format fmt = make_format (r, scale); | |
2782 | 2754 |
2783 if (pr_as_read_syntax) | 2755 if (pr_as_read_syntax) |
2784 { | 2756 { |
2785 if (free_format) | 2757 if (free_format) |
2786 { | 2758 { |
2828 max_width -= extra_indent; | 2800 max_width -= extra_indent; |
2829 | 2801 |
2830 if (max_width < 0) | 2802 if (max_width < 0) |
2831 max_width = 0; | 2803 max_width = 0; |
2832 | 2804 |
2833 pr_scale_header (os, scale); | 2805 pr_scale_header (os, fmt.scale_factor ()); |
2834 | 2806 |
2835 octave_idx_type col = 0; | 2807 octave_idx_type col = 0; |
2836 while (col < num_elem) | 2808 while (col < num_elem) |
2837 { | 2809 { |
2838 octave_idx_type lim = (col + inc < num_elem ? col + inc : num_elem); | 2810 octave_idx_type lim = (col + inc < num_elem ? col + inc : num_elem); |
2860 val = limit; | 2832 val = limit; |
2861 } | 2833 } |
2862 | 2834 |
2863 os << " "; | 2835 os << " "; |
2864 | 2836 |
2865 pr_float (os, fmt, val, scale); | 2837 pr_float (os, fmt, val); |
2866 } | 2838 } |
2867 | 2839 |
2868 col += inc; | 2840 col += inc; |
2869 } | 2841 } |
2870 } | 2842 } |