Mercurial > octave
annotate libinterp/corefcn/pr-output.cc @ 24784:4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
* pr-flt-fmt.h, pr-flt-fmt.cc (Voutput_max_field_width,
output_max_field_width): Delete. Eliminate all uses.
(set_output_prec): Rename from set_output_prec_and_fw. Change all uses.
(Foutput_max_field_width): Always return 20. Don't do anything with
input. Document new behavior.
(Foutput_precision): Limit value to be in the range 0 to 16.
(class float_format): Always set width to 0.
* pr-output.h, pr-output.cc (pr_output_traits): New template.
(make_real_format): Limit output precision.
(octave_print_real_matrix_internal,
octave_print_real_diag_matrix_internal,
octave_print_complex_matrix_internal,
octave_print_complex_diag_matrix_internal): New template functions.
Use them to define float and double versions of octave_print_internal
for real and complex matrix and diag matrix functions.
(octave_print_internal): Define separate versions for float and float
complex N-d arrays.
(Fformat): Update doc string.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 21 Feb 2018 08:24:41 -0500 |
parents | 0eb41237424e |
children | 504869574c89 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1993-2017 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23829
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23829
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
1 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23829
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
1 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
1 | 25 #endif |
26 | |
23662
bd77ab816e43
eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents:
23619
diff
changeset
|
27 #include <cmath> |
1343 | 28 |
3503 | 29 #include <iomanip> |
30 #include <iostream> | |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
31 #include <limits> |
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
32 #include <list> |
5765 | 33 #include <sstream> |
1728 | 34 #include <string> |
35 | |
4655 | 36 #include "Array-util.h" |
453 | 37 #include "CMatrix.h" |
1 | 38 #include "Range.h" |
2926 | 39 #include "cmd-edit.h" |
1352 | 40 #include "dMatrix.h" |
2891 | 41 #include "lo-mappers.h" |
2317 | 42 #include "mach-info.h" |
1651 | 43 #include "oct-cmplx.h" |
4153 | 44 #include "quit.h" |
1 | 45 |
3933 | 46 #include "Cell.h" |
1352 | 47 #include "defun.h" |
48 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21066
diff
changeset
|
49 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
50 #include "ovl.h" |
3685 | 51 #include "oct-stream.h" |
20925
667861ffffab
Extracted header class octave-preserve-stream-state from utils.{cc/h}.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20915
diff
changeset
|
52 #include "octave-preserve-stream-state.h" |
1352 | 53 #include "pager.h" |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
54 #include "parse.h" |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
55 #include "pr-flt-fmt.h" |
1352 | 56 #include "pr-output.h" |
1282 | 57 #include "sysdep.h" |
6803 | 58 #include "unwind-prot.h" |
1 | 59 #include "utils.h" |
1352 | 60 #include "variables.h" |
1 | 61 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
62 // TRUE means use a scaled fixed point format for 'format long' and |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
63 // 'format short'. |
5794 | 64 static bool Vfixed_point_format = false; |
3105 | 65 |
5360 | 66 // TRUE means that the dimensions of empty objects should be printed |
2165 | 67 // like this: x = [](2x0). |
5794 | 68 bool Vprint_empty_dimensions = true; |
2165 | 69 |
70 // TRUE means that the rows of big matrices should be split into | |
71 // smaller slices that fit on the screen. | |
5794 | 72 static bool Vsplit_long_rows = true; |
2165 | 73 |
3018 | 74 // TRUE means don't do any fancy formatting. |
2387 | 75 static bool free_format = false; |
1 | 76 |
3018 | 77 // TRUE means print plus sign for nonzero, blank for zero. |
2387 | 78 static bool plus_format = false; |
1 | 79 |
4632 | 80 // First char for > 0, second for < 0, third for == 0. |
19232
97eea1e2d9ff
pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
81 static std::string plus_format_chars = "+- "; |
4632 | 82 |
6788 | 83 // TRUE means always print in a rational approximation |
84 static bool rat_format = false; | |
85 | |
86 // Used to force the length of the rational approximation string for Frats | |
87 static int rat_string_len = -1; | |
88 | |
3018 | 89 // TRUE means always print like dollars and cents. |
2387 | 90 static bool bank_format = false; |
1282 | 91 |
3018 | 92 // TRUE means print data in hexadecimal format. |
3608 | 93 static int hex_format = 0; |
1282 | 94 |
3018 | 95 // TRUE means print data in binary-bit-pattern format. |
1309 | 96 static int bit_format = 0; |
97 | |
3018 | 98 // TRUE means don't put newlines around the column number headers. |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
99 bool Vcompact_format = false; |
1186 | 100 |
3018 | 101 // TRUE means use an e format. |
2387 | 102 static bool print_e = false; |
1 | 103 |
4509 | 104 // TRUE means use a g format. |
105 static bool print_g = false; | |
106 | |
3018 | 107 // TRUE means print E instead of e for exponent field. |
2387 | 108 static bool print_big_e = false; |
1 | 109 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
110 // TRUE means use an engineering format. |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
111 static bool print_eng = false; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
112 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
113 static int |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
114 calc_scale_exp (const int& x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
115 { |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
116 if (! print_eng) |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
117 return x; |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
118 else |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
119 return x - 3*static_cast<int> (x/3); |
20946 | 120 |
121 // The expression above is equivalent to x - (x % 3). | |
122 | |
123 // According to the ISO specification for C++ the modulo operator is | |
124 // compiler dependent if any of the arguments are negative. Since | |
125 // this function will need to work on negative arguments, and we want | |
126 // to avoid portability issues, we re-implement the modulo function to | |
127 // the desired behavior (truncation). There may be a gnulib | |
128 // replacement. | |
129 | |
130 // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, | |
131 // IEC. 2003 . "the binary % operator yields the remainder from the | |
132 // division of the first expression by the second. .... If both | |
133 // operands are nonnegative then the remainder is nonnegative; if not, | |
134 // the sign of the remainder is implementation-defined". | |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
135 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
136 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
137 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
138 static inline int |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
139 engineering_exponent (T x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
140 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
141 int ex = 0; |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
142 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
143 if (x != 0) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
144 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
145 T absval = (x < 0 ? -x : x); |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
146 int logabsval = static_cast<int> (std::floor (log10 (absval))); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
147 |
20946 | 148 // Avoid using modulo function with negative arguments for |
149 // portability. See extended comment at calc_scale_exp | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
150 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
151 if (logabsval < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
152 ex = logabsval - 2 + ((-logabsval + 2) % 3); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
153 else |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
154 ex = logabsval - (logabsval % 3); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
155 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
156 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
157 return ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
158 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
159 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
160 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
161 static inline int |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
162 num_digits (T x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
163 { |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
164 return 1 + (print_eng |
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
165 ? engineering_exponent (x) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
166 : static_cast<int> (std::floor (log10 (x)))); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
167 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
168 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
169 template <typename T> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
170 int |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
171 pr_engineering_float<T>::exponent (void) const |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
172 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
173 return engineering_exponent (m_val); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
174 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
175 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
176 template <typename T> |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
177 T |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
178 pr_engineering_float<T>::mantissa (void) const |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
179 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
180 return m_val / std::pow (static_cast<T> (10), exponent ()); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
181 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
182 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
183 template <typename T> |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
184 std::ostream& |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
185 operator << (std::ostream& os, const pr_engineering_float<T>& pef) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
186 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
187 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
188 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
189 float_format real_fmt = pef.m_ff; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
190 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
191 if (real_fmt.fw >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
192 os << std::setw (real_fmt.fw - real_fmt.ex); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
193 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
194 if (real_fmt.prec >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
195 os << std::setprecision (real_fmt.prec); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
196 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
197 os.flags (static_cast<std::ios::fmtflags> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
198 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
199 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
200 os << pef.mantissa (); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
201 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
202 int ex = pef.exponent (); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
203 if (ex < 0) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
204 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
205 os << std::setw (0) << "e-"; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
206 ex = -ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
207 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
208 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
209 os << std::setw (0) << "e+"; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
210 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
211 os << std::setw (real_fmt.ex - 2) << std::setfill ('0') << ex; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
212 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
213 return os; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
214 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
215 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
216 template <typename T> |
3608 | 217 std::ostream& |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
218 operator << (std::ostream& os, const pr_formatted_float<T>& pff) |
3608 | 219 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
220 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
221 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
222 float_format real_fmt = pff.m_ff; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
223 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
224 if (real_fmt.fw >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
225 os << std::setw (real_fmt.fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
226 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
227 if (real_fmt.prec >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
228 os << std::setprecision (real_fmt.prec); |
3608 | 229 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
230 os.flags (static_cast<std::ios::fmtflags> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
231 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
232 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
233 os << pff.m_val; |
3608 | 234 |
235 return os; | |
236 } | |
237 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
238 template <typename T> |
6788 | 239 static inline std::string |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
240 rational_approx (T val, int len) |
6788 | 241 { |
242 std::string s; | |
243 | |
244 if (len <= 0) | |
245 len = 10; | |
246 | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
247 if (octave::math::isinf (val)) |
6788 | 248 s = "1/0"; |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
249 else if (octave::math::isnan (val)) |
6788 | 250 s = "0/0"; |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
251 else if (val < std::numeric_limits<int>::min () |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
252 || val > std::numeric_limits<int>::max () |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
253 || octave::math::x_nint (val) == val) |
6788 | 254 { |
255 std::ostringstream buf; | |
256 buf.flags (std::ios::fixed); | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
257 buf << std::setprecision (0) << octave::math::round (val); |
6788 | 258 s = buf.str (); |
259 } | |
260 else | |
261 { | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
262 T lastn = 1; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
263 T lastd = 0; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
264 T n = octave::math::round (val); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
265 T d = 1; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
266 T frac = val - n; |
6788 | 267 int m = 0; |
268 | |
269 std::ostringstream buf2; | |
270 buf2.flags (std::ios::fixed); | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
271 buf2 << std::setprecision (0) << static_cast<int> (n); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
272 s = buf2.str (); |
6788 | 273 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
274 while (true) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
276 T flip = 1 / frac; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
277 T step = octave::math::round (flip); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
278 T nextn = n; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
279 T nextd = d; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
281 // Have we converged to 1/intmax ? |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
282 if (std::abs (flip) > static_cast<T> (std::numeric_limits<int>::max ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
283 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 lastn = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 lastd = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
289 frac = flip - step; |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
290 n = step * n + lastn; |
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
291 d = step * d + lastd; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 lastn = nextn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 lastd = nextd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
295 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 buf.flags (std::ios::fixed); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
297 buf << std::setprecision (0) << static_cast<int> (n) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
298 << '/' << static_cast<int> (d); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 m++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 if (n < 0 && d < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 // Double negative, string can be two characters longer.. |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
304 if (buf.str ().length () > static_cast<unsigned int> (len + 2)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
307 else if (buf.str ().length () > static_cast<unsigned int> (len)) |
19363
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
308 break; |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
309 |
21747
61f3575250e4
rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents:
21743
diff
changeset
|
310 if (std::abs (n) > std::numeric_limits<int>::max () |
61f3575250e4
rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents:
21743
diff
changeset
|
311 || std::abs (d) > std::numeric_limits<int>::max ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
314 s = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 } |
6788 | 316 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
317 if (lastd < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
318 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
319 // Move sign to the top |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
320 lastd = - lastd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
321 lastn = - lastn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
322 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
323 buf.flags (std::ios::fixed); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
324 buf << std::setprecision (0) << static_cast<int> (lastn) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
325 << '/' << static_cast<int> (lastd); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
326 s = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
327 } |
6788 | 328 } |
329 | |
330 return s; | |
331 } | |
332 | |
19363
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
333 /* |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
334 %!assert (rats (2.0005, 9), "4001/2000") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
335 %!assert (rats (-2.0005, 10), "-4001/2000") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
336 %!assert (strtrim (rats (2.0005, 30)), "4001/2000") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
337 %!assert (pi - str2num (rats (pi, 30)), 0, 4 * eps) |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
338 %!assert (e - str2num (rats (e, 30)), 0, 4 * eps) |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
339 %!assert (rats (123, 2), " *") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
340 |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
341 %!test |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
342 %! v = 1 / double (intmax); |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
343 %! err = v - str2num (rats(v, 12)); |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
344 %! assert (err, 0, 4 * eps); |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
345 */ |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
346 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
347 template <typename T> |
6788 | 348 std::ostream& |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
349 operator << (std::ostream& os, const pr_rational_float<T>& prf) |
6788 | 350 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
351 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
352 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
353 float_format real_fmt = prf.m_ff; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
354 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
355 int fw = (rat_string_len > 0 ? rat_string_len : real_fmt.fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
356 std::string s = rational_approx (prf.m_val, fw); |
6788 | 357 |
358 if (fw >= 0) | |
359 os << std::setw (fw); | |
360 | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
361 os.flags (static_cast<std::ios::fmtflags> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
362 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
363 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
364 if (fw > 0 && s.length () > static_cast<unsigned int> (fw)) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
365 os << '*'; |
6788 | 366 else |
367 os << s; | |
368 | |
369 return os; | |
370 } | |
371 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
372 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
373 static inline T |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
374 pr_max_internal (const MArray<T>& m) |
1 | 375 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
376 // We expect a 2-d array. |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
377 assert (m.ndims () == 2); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
378 |
5275 | 379 octave_idx_type nr = m.rows (); |
380 octave_idx_type nc = m.columns (); | |
1 | 381 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
382 T result = std::numeric_limits<T>::lowest (); |
1 | 383 |
5748 | 384 bool all_inf_or_nan = true; |
385 | |
5275 | 386 for (octave_idx_type j = 0; j < nc; j++) |
387 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 388 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
389 T val = m(i,j); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
390 if (! octave::math::isfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
391 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
392 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
393 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
394 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
395 if (val > result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 result = val; |
1 | 397 } |
3608 | 398 |
5748 | 399 if (all_inf_or_nan) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
400 result = 0; |
5748 | 401 |
1 | 402 return result; |
403 } | |
404 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
405 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
406 static inline T |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
407 pr_min_internal (const MArray<T>& m) |
1 | 408 { |
5275 | 409 octave_idx_type nr = m.rows (); |
410 octave_idx_type nc = m.columns (); | |
1 | 411 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
412 T result = std::numeric_limits<T>::max (); |
1 | 413 |
5748 | 414 bool all_inf_or_nan = true; |
415 | |
5275 | 416 for (octave_idx_type j = 0; j < nc; j++) |
417 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 418 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
419 T val = m(i,j); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
420 if (! octave::math::isfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
421 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
422 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
423 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
425 if (val < result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
426 result = val; |
1 | 427 } |
3608 | 428 |
5748 | 429 if (all_inf_or_nan) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
430 result = 0; |
5748 | 431 |
1 | 432 return result; |
433 } | |
434 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
435 template <typename> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
436 struct pr_output_traits |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
437 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
438 static const int digits10; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
439 }; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
440 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
441 template <> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
442 struct pr_output_traits<double> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
443 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
444 static const int digits10; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
445 }; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
446 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
447 const int pr_output_traits<double>::digits10 = 16; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
448 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
449 template <> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
450 struct pr_output_traits<float> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
451 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
452 static const int digits10; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
453 }; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
454 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
455 const int pr_output_traits<float>::digits10 = 8; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
456 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
457 // FIXME: it would be nice to share more code among these functions,.. |
1658 | 458 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
459 // Works for double and float. |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
460 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
461 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
462 static inline float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
463 make_real_format (int digits, bool inf_or_nan, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
464 bool int_only, int& fw) |
1 | 465 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
466 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
467 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
468 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 469 |
470 int ld, rd; | |
471 | |
6788 | 472 if (rat_format) |
473 { | |
474 fw = 0; | |
475 rd = 0; | |
476 } | |
477 else if (bank_format) | |
1 | 478 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
479 fw = (digits < 0 ? 5 : digits + 4); |
17847
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
480 if (inf_or_nan && fw < 5) |
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
481 fw = 5; |
1 | 482 rd = 2; |
483 } | |
1282 | 484 else if (hex_format) |
485 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
486 fw = 2 * sizeof (T); |
1282 | 487 rd = 0; |
488 } | |
1309 | 489 else if (bit_format) |
490 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
491 fw = 8 * sizeof (T); |
1309 | 492 rd = 0; |
493 } | |
3611 | 494 else if (inf_or_nan || int_only) |
1 | 495 { |
5832 | 496 fw = 1 + digits; |
5748 | 497 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 fw = 4; |
3682 | 499 rd = fw; |
1 | 500 } |
501 else | |
502 { | |
503 if (digits > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
504 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
505 ld = digits; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
506 rd = (prec > digits ? prec - digits : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
507 } |
1 | 508 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
510 ld = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
511 rd = (prec > digits ? prec - digits : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 } |
1 | 513 |
5832 | 514 fw = 1 + ld + 1 + rd; |
5748 | 515 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
516 fw = 4; |
1 | 517 } |
518 | |
6788 | 519 if (! (rat_format || bank_format || hex_format || bit_format) |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
520 && (print_e || print_g || print_eng)) |
1 | 521 { |
4509 | 522 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
523 fmt = float_format (); |
4509 | 524 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
526 // e+ddd |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
527 int ex = 5; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
528 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
529 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
530 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
531 // -ddd. |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
532 fw = 5 + prec + ex; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
533 if (inf_or_nan && fw < 6) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
534 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
535 fmt = float_format (fw, ex, prec - 1, std::ios::fixed); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
536 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
537 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
538 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
539 // -d. |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
540 fw = 3 + prec + ex; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
541 if (inf_or_nan && fw < 4) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
542 fw = 4; |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
543 fmt = float_format (fw, ex, prec - 1, std::ios::scientific); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
544 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
545 } |
3608 | 546 |
1 | 547 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
548 fmt.uppercase (); |
1 | 549 } |
5086 | 550 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 551 fmt = float_format (fw, rd); |
1 | 552 else |
3608 | 553 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 554 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
555 return float_display_format (fmt); |
1 | 556 } |
557 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
558 // Works for double and float. |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
559 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
560 template <typename T> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
561 float_display_format |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
562 make_format (T val, int& fw) |
1658 | 563 { |
564 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
565 return float_display_format (); |
1658 | 566 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
567 bool inf_or_nan = (octave::math::isinf (val) || octave::math::isnan (val)); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
568 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
569 bool int_only = (! inf_or_nan && octave::math::x_nint (val) == val); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
570 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
571 T val_abs = (val < 0 ? -val : val); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
572 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
573 int digits = (inf_or_nan || val_abs == 0) ? 0 : num_digits (val_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
574 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
575 return make_real_format<T> (digits, inf_or_nan, int_only, fw); |
1 | 576 } |
577 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
578 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
579 static inline float_display_format |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
580 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
581 int int_or_inf_or_nan, int& fw) |
1 | 582 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
583 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
584 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
585 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 586 |
587 int ld, rd; | |
588 | |
6788 | 589 if (rat_format) |
590 { | |
591 fw = 9; | |
592 rd = 0; | |
593 } | |
594 else if (bank_format) | |
1 | 595 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
596 int digits = (x_max > x_min ? x_max : x_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
597 fw = (digits <= 0 ? 5 : digits + 4); |
17847
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
598 if (inf_or_nan && fw < 5) |
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
599 fw = 5; |
1 | 600 rd = 2; |
601 } | |
1282 | 602 else if (hex_format) |
603 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
604 fw = 2 * sizeof (T); |
1282 | 605 rd = 0; |
606 } | |
1309 | 607 else if (bit_format) |
608 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
609 fw = 8 * sizeof (T); |
1309 | 610 rd = 0; |
611 } | |
4509 | 612 else if (Vfixed_point_format && ! print_g) |
3268 | 613 { |
614 rd = prec; | |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
615 fw = rd + 3; |
5748 | 616 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
617 fw = 4; |
3268 | 618 } |
1715 | 619 else if (int_or_inf_or_nan) |
1 | 620 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
621 int digits = (x_max > x_min ? x_max : x_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
622 fw = (digits <= 0 ? 2 : digits + 1); |
5748 | 623 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
624 fw = 4; |
3682 | 625 rd = fw; |
1 | 626 } |
627 else | |
628 { | |
629 int ld_max, rd_max; | |
630 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
631 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
632 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
633 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
634 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
635 } |
1 | 636 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
637 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
638 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
639 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
640 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
641 } |
1 | 642 |
643 int ld_min, rd_min; | |
644 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
645 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
646 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
647 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
648 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
649 } |
1 | 650 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
651 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
652 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
653 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
654 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
655 } |
1 | 656 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
657 ld = (ld_max > ld_min ? ld_max : ld_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
658 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 659 |
5832 | 660 fw = 1 + ld + 1 + rd; |
5748 | 661 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
662 fw = 4; |
1 | 663 } |
664 | |
6788 | 665 if (! (rat_format || bank_format || hex_format || bit_format) |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
666 && (print_e || print_eng || print_g)) |
1 | 667 { |
4509 | 668 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
669 fmt = float_format (); |
4509 | 670 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
671 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
672 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
673 if (x_max > 100 || x_min > 100) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
674 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
675 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
676 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
677 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
678 fw = 4 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
679 if (inf_or_nan && fw < 6) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
680 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
681 fmt = float_format (fw, ex, prec - 1, std::ios::fixed); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
682 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
683 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
684 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
685 fw = 2 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
686 if (inf_or_nan && fw < 4) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
687 fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
688 fmt = float_format (fw, prec - 1, std::ios::scientific); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
689 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
690 } |
3608 | 691 |
1 | 692 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
693 fmt.uppercase (); |
1 | 694 } |
5086 | 695 else if (! bank_format && int_or_inf_or_nan) |
3611 | 696 fmt = float_format (fw, rd); |
1 | 697 else |
3608 | 698 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 699 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
700 return float_display_format (fmt); |
1 | 701 } |
702 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
703 template <typename MT, typename ELT_T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
704 static inline float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
705 make_format_internal (const MT& m, int& fw, ELT_T& scale) |
1658 | 706 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
707 assert (m.ndims () == 2); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
708 |
1658 | 709 if (free_format) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
710 return float_display_format (); |
1658 | 711 |
2387 | 712 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 713 |
2387 | 714 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 715 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
716 MT m_abs = m.abs (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
717 ELT_T max_abs = pr_max_internal (m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
718 ELT_T min_abs = pr_min_internal (m_abs); |
1658 | 719 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
720 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
721 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
722 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
723 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
724 scale = ((x_max == 0 || int_or_inf_or_nan) |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
725 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
3105 | 726 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
727 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
728 int_or_inf_or_nan, fw); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
729 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
730 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
731 float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
732 make_format (const Matrix& m, int& fw, double& scale) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
733 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
734 return make_format_internal<Matrix, double> (m, fw, scale); |
1 | 735 } |
736 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
737 float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
738 make_format (const FloatMatrix& m, int& fw, float& scale) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
739 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
740 return make_format_internal<FloatMatrix, float> (m, fw, scale); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
741 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
742 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
743 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
744 static inline float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
745 make_complex_format (int x_max, int x_min, int r_x, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
746 bool inf_or_nan, int int_only, int& r_fw, int& i_fw) |
1 | 747 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
748 float_format r_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
749 float_format i_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
750 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
751 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 752 |
753 int ld, rd; | |
754 | |
6788 | 755 if (rat_format) |
756 { | |
757 i_fw = 0; | |
758 r_fw = 0; | |
759 rd = 0; | |
760 } | |
761 else if (bank_format) | |
1 | 762 { |
763 int digits = r_x; | |
764 i_fw = 0; | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
765 r_fw = (digits <= 0 ? 5 : digits + 4); |
17847
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
766 if (inf_or_nan && r_fw < 5) |
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
767 r_fw = 5; |
1 | 768 rd = 2; |
769 } | |
1282 | 770 else if (hex_format) |
771 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
772 r_fw = 2 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
773 i_fw = 2 * sizeof (T); |
1282 | 774 rd = 0; |
775 } | |
1309 | 776 else if (bit_format) |
777 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
778 r_fw = 8 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
779 i_fw = 8 * sizeof (T); |
1309 | 780 rd = 0; |
781 } | |
1658 | 782 else if (inf_or_nan || int_only) |
1 | 783 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
784 int digits = (x_max > x_min ? x_max : x_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
785 i_fw = (digits <= 0 ? 1 : digits); |
5945 | 786 r_fw = i_fw + 1; |
787 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
788 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
789 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
790 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
791 } |
3682 | 792 rd = r_fw; |
1 | 793 } |
794 else | |
795 { | |
796 int ld_max, rd_max; | |
797 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
799 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
800 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
801 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
802 } |
1 | 803 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
804 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
806 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
807 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
808 } |
1 | 809 |
810 int ld_min, rd_min; | |
811 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
812 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
813 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
814 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
815 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
816 } |
1 | 817 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
819 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
820 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
821 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
822 } |
1 | 823 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
824 ld = (ld_max > ld_min ? ld_max : ld_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
825 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 826 |
5945 | 827 i_fw = ld + 1 + rd; |
828 r_fw = i_fw + 1; | |
829 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
830 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
831 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
832 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
833 } |
1 | 834 } |
835 | |
6788 | 836 if (! (rat_format || bank_format || hex_format || bit_format) |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
837 && (print_e || print_eng || print_g)) |
1 | 838 { |
4509 | 839 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
840 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
841 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
842 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
843 } |
4509 | 844 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
846 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
847 if (x_max > 100 || x_min > 100) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
848 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
849 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
850 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
851 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
852 i_fw = 3 + prec + ex; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
853 r_fw = i_fw + 1; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
854 if (inf_or_nan && i_fw < 5) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
855 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
856 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
857 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
858 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
859 r_fmt = float_format (r_fw, ex, prec - 1, std::ios::fixed); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
860 i_fmt = float_format (i_fw, ex, prec - 1, std::ios::fixed); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
861 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
862 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
863 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
864 i_fw = 1 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
865 r_fw = i_fw + 1; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
866 if (inf_or_nan && i_fw < 3) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
867 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
868 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
869 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
870 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
871 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
872 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
873 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
874 } |
3608 | 875 |
1 | 876 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
877 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
878 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 } |
1 | 881 } |
5086 | 882 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 883 { |
884 r_fmt = float_format (r_fw, rd); | |
885 i_fmt = float_format (i_fw, rd); | |
886 } | |
1 | 887 else |
888 { | |
3608 | 889 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
890 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 891 } |
892 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
893 return float_display_format (r_fmt, i_fmt); |
1 | 894 } |
895 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
896 template <typename T> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
897 float_display_format |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
898 make_format (const std::complex<T>& c, int& r_fw, int& i_fw) |
1658 | 899 { |
900 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
901 return float_display_format (); |
1658 | 902 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
903 T rp = c.real (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
904 T ip = c.imag (); |
1658 | 905 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
906 bool inf_or_nan = (octave::math::isinf (c) || octave::math::isnan (c)); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
907 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
908 bool int_only = (octave::math::x_nint (rp) == rp |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
909 && octave::math::x_nint (ip) == ip); |
1658 | 910 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
911 T r_abs = (rp < 0 ? -rp : rp); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
912 T i_abs = (ip < 0 ? -ip : ip); |
1658 | 913 |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
914 int r_x = (! octave::math::isfinite (rp) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
915 || r_abs == 0) ? 0 : num_digits (r_abs); |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
916 |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
917 int i_x = (! octave::math::isfinite (ip) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
918 || i_abs == 0) ? 0 : num_digits (i_abs); |
1658 | 919 |
920 int x_max, x_min; | |
921 | |
922 if (r_x > i_x) | |
923 { | |
924 x_max = r_x; | |
925 x_min = i_x; | |
926 } | |
927 else | |
928 { | |
929 x_max = i_x; | |
930 x_min = r_x; | |
931 } | |
932 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
933 return make_complex_format<T> (x_max, x_min, r_x, inf_or_nan, int_only, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
934 r_fw, i_fw); |
1 | 935 } |
936 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
937 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
938 static inline float_display_format |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
939 make_complex_matrix_format (int x_max, int x_min, int r_x_max, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
940 int r_x_min, bool inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
941 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1 | 942 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
943 float_format r_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
944 float_format i_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
945 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
946 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 947 |
948 int ld, rd; | |
949 | |
6788 | 950 if (rat_format) |
951 { | |
952 i_fw = 9; | |
953 r_fw = 9; | |
954 rd = 0; | |
955 } | |
956 else if (bank_format) | |
1 | 957 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
958 int digits = (r_x_max > r_x_min ? r_x_max : r_x_min); |
1 | 959 i_fw = 0; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
960 r_fw = (digits <= 0 ? 5 : digits + 4); |
17847
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
961 if (inf_or_nan && r_fw < 5) |
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
962 r_fw = 5; |
1 | 963 rd = 2; |
964 } | |
1282 | 965 else if (hex_format) |
966 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
967 r_fw = 2 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
968 i_fw = 2 * sizeof (T); |
1282 | 969 rd = 0; |
970 } | |
1309 | 971 else if (bit_format) |
972 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
973 r_fw = 8 * sizeof (T); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
974 i_fw = 8 * sizeof (T); |
1309 | 975 rd = 0; |
976 } | |
4509 | 977 else if (Vfixed_point_format && ! print_g) |
3268 | 978 { |
979 rd = prec; | |
5945 | 980 i_fw = rd + 1; |
981 r_fw = i_fw + 1; | |
982 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
983 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
984 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
985 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
986 } |
3268 | 987 } |
1715 | 988 else if (int_or_inf_or_nan) |
1 | 989 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
990 int digits = (x_max > x_min ? x_max : x_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
991 i_fw = (digits <= 0 ? 1 : digits); |
5945 | 992 r_fw = i_fw + 1; |
993 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
994 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
995 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
996 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 } |
3682 | 998 rd = r_fw; |
1 | 999 } |
1000 else | |
1001 { | |
1002 int ld_max, rd_max; | |
1003 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1004 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1005 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1006 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1007 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1008 } |
1 | 1009 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1010 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1011 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1012 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1013 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1014 } |
1 | 1015 |
1016 int ld_min, rd_min; | |
1017 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1018 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1019 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1020 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1021 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1022 } |
1 | 1023 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1024 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1025 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1026 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1028 } |
1 | 1029 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1030 ld = (ld_max > ld_min ? ld_max : ld_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1031 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 1032 |
5945 | 1033 i_fw = ld + 1 + rd; |
1034 r_fw = i_fw + 1; | |
1035 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1036 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1037 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1038 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1039 } |
1 | 1040 } |
1041 | |
6788 | 1042 if (! (rat_format || bank_format || hex_format || bit_format) |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1043 && (print_e || print_eng || print_g)) |
1 | 1044 { |
4509 | 1045 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1046 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1047 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1048 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1049 } |
4509 | 1050 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1051 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1052 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1053 if (x_max > 100 || x_min > 100) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1054 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1055 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1056 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1057 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1058 i_fw = 3 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1059 r_fw = i_fw + 1; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1060 if (inf_or_nan && i_fw < 5) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1061 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1062 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1063 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1064 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1065 r_fmt = float_format (r_fw, ex, prec - 1, std::ios::fixed); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1066 i_fmt = float_format (i_fw, ex, prec - 1, std::ios::fixed); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1067 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1068 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1069 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1070 i_fw = 1 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1071 r_fw = i_fw + 1; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1072 if (inf_or_nan && i_fw < 3) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1073 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1074 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1075 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1076 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1077 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1078 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1079 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1080 } |
3608 | 1081 |
1 | 1082 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1083 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1084 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1085 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1086 } |
1 | 1087 } |
5086 | 1088 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1089 { |
1090 r_fmt = float_format (r_fw, rd); | |
1091 i_fmt = float_format (i_fw, rd); | |
1092 } | |
1 | 1093 else |
1094 { | |
3608 | 1095 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1096 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1097 } |
1098 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1099 return float_display_format (r_fmt, i_fmt); |
1 | 1100 } |
1101 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1102 template <typename CMT, typename RMT, typename ELT_T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1103 static inline float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1104 make_format_internal (const CMT& cm, int& r_fw, int& i_fw, ELT_T& scale) |
1658 | 1105 { |
1106 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1107 return float_display_format (); |
1658 | 1108 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1109 RMT rp = real (cm); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1110 RMT ip = imag (cm); |
1658 | 1111 |
2387 | 1112 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1113 |
2387 | 1114 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1115 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658 | 1116 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1117 RMT r_m_abs = rp.abs (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1118 ELT_T r_max_abs = pr_max_internal (r_m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1119 ELT_T r_min_abs = pr_min_internal (r_m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1120 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1121 RMT i_m_abs = ip.abs (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1122 ELT_T i_max_abs = pr_max_internal (i_m_abs); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1123 ELT_T i_min_abs = pr_min_internal (i_m_abs); |
1658 | 1124 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1125 int r_x_max = (r_max_abs == 0 ? 0 : num_digits (r_max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1126 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1127 int r_x_min = (r_min_abs == 0 ? 0 : num_digits (r_min_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1128 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1129 int i_x_max = (i_max_abs == 0 ? 0 : num_digits (i_max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1130 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1131 int i_x_min = (i_min_abs == 0 ? 0 : num_digits (i_min_abs)); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1132 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1133 int x_max = (r_x_max > i_x_max ? r_x_max : i_x_max); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1134 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min); |
1658 | 1135 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1136 scale = ((x_max == 0 || int_or_inf_or_nan) |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1137 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
3105 | 1138 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1139 return make_complex_matrix_format<ELT_T> (x_max, x_min, r_x_max, r_x_min, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1140 inf_or_nan, int_or_inf_or_nan, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1141 r_fw, i_fw); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1142 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1143 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1144 float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1145 make_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1146 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1147 return make_format_internal<ComplexMatrix, Matrix, double> (cm, r_fw, i_fw, scale); |
1658 | 1148 } |
1149 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1150 float_display_format |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1151 make_format (const FloatComplexMatrix& cm, int& r_fw, int& i_fw, float& scale) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1152 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1153 return make_format_internal<FloatComplexMatrix, FloatMatrix, float> (cm, r_fw, i_fw, scale); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1154 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1155 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1156 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1157 static inline float_display_format |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1158 make_range_format (int x_max, int x_min, int all_ints, int& fw) |
1 | 1159 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1160 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1161 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1162 int prec = std::min (output_precision (), pr_output_traits<T>::digits10); |
1 | 1163 |
1164 int ld, rd; | |
1165 | |
6788 | 1166 if (rat_format) |
1167 { | |
1168 fw = 9; | |
1169 rd = 0; | |
1170 } | |
1171 else if (bank_format) | |
1 | 1172 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1173 int digits = (x_max > x_min ? x_max : x_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1174 fw = (digits < 0 ? 5 : digits + 4); |
1 | 1175 rd = 2; |
1176 } | |
1282 | 1177 else if (hex_format) |
1178 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1179 fw = 2 * sizeof (T); |
1282 | 1180 rd = 0; |
1181 } | |
1309 | 1182 else if (bit_format) |
1183 { | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1184 fw = 8 * sizeof (T); |
1309 | 1185 rd = 0; |
1186 } | |
1658 | 1187 else if (all_ints) |
1 | 1188 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1189 int digits = (x_max > x_min ? x_max : x_min); |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1190 fw = digits + 1; |
3682 | 1191 rd = fw; |
1 | 1192 } |
4509 | 1193 else if (Vfixed_point_format && ! print_g) |
3105 | 1194 { |
1195 rd = prec; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1196 fw = rd + 3; |
3105 | 1197 } |
1 | 1198 else |
1199 { | |
1200 int ld_max, rd_max; | |
1201 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1202 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1203 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1204 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1205 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1206 } |
1 | 1207 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1208 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1209 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1210 rd_max = (prec > x_max ? prec - x_max : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1211 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1212 } |
1 | 1213 |
1214 int ld_min, rd_min; | |
1215 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1216 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1217 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1218 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1219 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1220 } |
1 | 1221 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1222 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1223 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1224 rd_min = (prec > x_min ? prec - x_min : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1225 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1226 } |
1 | 1227 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1228 ld = (ld_max > ld_min ? ld_max : ld_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1229 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 1230 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1231 fw = ld + rd + 3; |
1 | 1232 } |
1233 | |
6788 | 1234 if (! (rat_format || bank_format || hex_format || bit_format) |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1235 && (print_e || print_eng || print_g)) |
1 | 1236 { |
4509 | 1237 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1238 fmt = float_format (); |
4509 | 1239 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1240 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1241 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1242 if (x_max > 100 || x_min > 100) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1243 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1244 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1245 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1246 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1247 fw = 5 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1248 fmt = float_format (fw, ex, prec - 1, std::ios::fixed); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1249 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1250 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1251 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1252 fw = 3 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1253 fmt = float_format (fw, prec - 1, std::ios::scientific); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1254 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1255 } |
3608 | 1256 |
1 | 1257 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1258 fmt.uppercase (); |
1 | 1259 } |
5086 | 1260 else if (! bank_format && all_ints) |
3611 | 1261 fmt = float_format (fw, rd); |
1 | 1262 else |
3608 | 1263 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1264 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1265 return float_display_format (fmt); |
1 | 1266 } |
1267 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1268 float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1269 make_format (const Range& r, int& fw, double& scale) |
1658 | 1270 { |
1271 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1272 return float_display_format (); |
1658 | 1273 |
1274 double r_min = r.base (); | |
1275 double r_max = r.limit (); | |
1276 | |
1277 if (r_max < r_min) | |
1278 { | |
1279 double tmp = r_max; | |
1280 r_max = r_min; | |
1281 r_min = tmp; | |
1282 } | |
1283 | |
2387 | 1284 bool all_ints = r.all_elements_are_ints (); |
1658 | 1285 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1286 double max_abs = (r_max < 0 ? -r_max : r_max); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1287 double min_abs = (r_min < 0 ? -r_min : r_min); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1288 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1289 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1290 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1291 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs)); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1292 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1293 scale = ((x_max == 0 || all_ints) |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1294 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1))); |
3105 | 1295 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1296 return make_range_format<double> (x_max, x_min, all_ints, fw); |
1 | 1297 } |
1298 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1299 template <typename T> |
1282 | 1300 union equiv |
1301 { | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1302 T val; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1303 unsigned char i[sizeof (T)]; |
1282 | 1304 }; |
1305 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1306 #define PRINT_CHAR_BITS(os, c) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1307 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1308 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1309 unsigned char ctmp = c; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1310 char stmp[9]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1311 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1312 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1313 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1314 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1315 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1316 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1317 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1318 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1319 stmp[8] = '\0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1320 os << stmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1321 } \ |
1309 | 1322 while (0) |
1323 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1324 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1325 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1326 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1327 unsigned char ctmp = c; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1328 char stmp[9]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1329 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1330 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1331 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1332 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1333 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1334 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1335 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1336 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1337 stmp[8] = '\0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1338 os << stmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1339 } \ |
1309 | 1340 while (0) |
1341 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1342 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1343 static inline void |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1344 pr_any_float (std::ostream& os, const float_format& fmt, T val, int fw = 0) |
1 | 1345 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1346 // Unless explicitly asked for, always print in big-endian format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1347 // for hex and bit formats. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1348 // |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1349 // {bit,hex}_format == 1: print big-endian |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1350 // {bit,hex}_format == 2: print native |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1351 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1352 if (hex_format) |
1 | 1353 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1354 octave::preserve_stream_state stream_state (os); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1355 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1356 equiv<T> tmp; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1357 tmp.val = val; |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1358 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1359 // Unless explicitly asked for, always print in big-endian format. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1360 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1361 // FIXME: will bad things happen if we are |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1362 // interrupted before resetting the format flags and fill |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1363 // character? |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1364 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1365 octave::mach_info::float_format flt_fmt = |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1366 octave::mach_info::native_float_format (); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1367 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1368 os.fill ('0'); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1369 os.flags (std::ios::right | std::ios::hex); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1370 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1371 if (hex_format > 1 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1372 || flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1373 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1374 for (size_t i = 0; i < sizeof (T); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1375 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1376 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1377 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1378 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1379 for (int i = sizeof (T) - 1; i >= 0; i--) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1380 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1381 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1382 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1383 else if (bit_format) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1384 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1385 equiv<T> tmp; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1386 tmp.val = val; |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1387 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1388 octave::mach_info::float_format flt_fmt = |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1389 octave::mach_info::native_float_format (); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1390 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1391 if (flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1392 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1393 for (size_t i = 0; i < sizeof (T); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1394 PRINT_CHAR_BITS (os, tmp.i[i]); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1395 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1396 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1397 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1398 if (bit_format > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1399 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1400 for (size_t i = 0; i < sizeof (T); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1401 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1402 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1403 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1404 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1405 for (int i = sizeof (T) - 1; i >= 0; i--) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1406 PRINT_CHAR_BITS (os, tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1407 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1408 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1409 } |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1410 else if (octave::math::isna (val)) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1411 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1412 octave::preserve_stream_state stream_state (os); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1413 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1414 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1415 os << std::setw (fw) << "NA"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1416 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1417 os << "NA"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1418 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1419 else if (rat_format) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1420 os << pr_rational_float<T> (fmt, val); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1421 else if (octave::math::isinf (val)) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1422 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1423 octave::preserve_stream_state stream_state (os); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1424 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1425 const char *s; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1426 if (val < 0) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1427 s = "-Inf"; |
1 | 1428 else |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1429 s = "Inf"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1430 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1431 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1432 os << std::setw (fw) << s; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1433 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1434 os << s; |
1 | 1435 } |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1436 else if (octave::math::isnan (val)) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1437 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1438 octave::preserve_stream_state stream_state (os); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1439 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1440 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1441 os << std::setw (fw) << "NaN"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1442 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1443 os << "NaN"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1444 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1445 else if (print_eng) |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1446 os << pr_engineering_float<T> (fmt, val); |
529 | 1447 else |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1448 os << pr_formatted_float<T> (fmt, val); |
1 | 1449 } |
1450 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1451 template <typename T> |
1 | 1452 static inline void |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1453 pr_float (std::ostream& os, const float_display_format& fmt, T val, |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1454 int fw = 0, T scale = 1) |
1 | 1455 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1456 if (Vfixed_point_format && ! print_g && scale != 1) |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1457 val /= scale; |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1458 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1459 pr_any_float (os, fmt.real_format (), val, fw); |
1 | 1460 } |
1461 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1462 template <typename T> |
1 | 1463 static inline void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1464 pr_imag_float (std::ostream& os, const float_display_format& fmt, |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1465 T val, int fw = 0) |
1 | 1466 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1467 pr_any_float (os, fmt.imag_format (), val, fw); |
1 | 1468 } |
1469 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1470 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1471 static inline void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1472 pr_complex (std::ostream& os, const float_display_format& fmt, |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1473 const std::complex<T>& cval, int r_fw = 0, int i_fw = 0, |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1474 T scale = 1) |
1 | 1475 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1476 std::complex<T> tmp |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1477 = ((Vfixed_point_format && ! print_g && scale != 1) |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1478 ? cval / scale : cval); |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1479 |
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1480 T r = tmp.real (); |
3608 | 1481 |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1482 pr_float (os, fmt, r, r_fw); |
3608 | 1483 |
1 | 1484 if (! bank_format) |
1485 { | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1486 T i = tmp.imag (); |
4349 | 1487 if (! (hex_format || bit_format) && lo_ieee_signbit (i)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1488 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1489 os << " - "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1490 i = -i; |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1491 pr_imag_float (os, fmt, i, i_fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1492 } |
1 | 1493 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1494 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1495 if (hex_format || bit_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1496 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1497 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1498 os << " + "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1499 |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1500 pr_imag_float (os, fmt, i, i_fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1501 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1502 os << 'i'; |
1 | 1503 } |
1504 } | |
1505 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1506 static inline void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1507 print_empty_matrix (std::ostream& os, octave_idx_type nr, octave_idx_type nc, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1508 bool pr_as_read_syntax) |
626 | 1509 { |
1510 assert (nr == 0 || nc == 0); | |
1511 | |
1512 if (pr_as_read_syntax) | |
1513 { | |
1514 if (nr == 0 && nc == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1515 os << "[]"; |
626 | 1516 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1517 os << "zeros (" << nr << ", " << nc << ')'; |
626 | 1518 } |
1519 else | |
1520 { | |
1521 os << "[]"; | |
4559 | 1522 |
2165 | 1523 if (Vprint_empty_dimensions) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1524 os << '(' << nr << 'x' << nc << ')'; |
626 | 1525 } |
1526 } | |
1527 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1528 static inline void |
4559 | 1529 print_empty_nd_array (std::ostream& os, const dim_vector& dims, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1530 bool pr_as_read_syntax) |
4559 | 1531 { |
1532 assert (dims.any_zero ()); | |
1533 | |
1534 if (pr_as_read_syntax) | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1535 os << "zeros (" << dims.str (',') << ')'; |
4559 | 1536 else |
1537 { | |
1538 os << "[]"; | |
1539 | |
1540 if (Vprint_empty_dimensions) | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1541 os << '(' << dims.str () << ')'; |
4559 | 1542 } |
1543 } | |
1544 | |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1545 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1546 static inline void |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1547 pr_scale_header (std::ostream& os, T scale) |
3105 | 1548 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1549 if (Vfixed_point_format && ! print_g && scale != 1) |
3105 | 1550 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1551 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1552 |
3568 | 1553 os << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1554 << std::setw (8) << std::setprecision (1) |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21583
diff
changeset
|
1555 << std::setiosflags (std::ios::scientific | std::ios::left) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1556 << scale |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1557 << "*\n"; |
3105 | 1558 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1559 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1560 os << "\n"; |
3105 | 1561 } |
1562 } | |
1563 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1564 static inline void |
5275 | 1565 pr_col_num_header (std::ostream& os, octave_idx_type total_width, int max_width, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1566 octave_idx_type lim, octave_idx_type col, int extra_indent) |
1186 | 1567 { |
2165 | 1568 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1569 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1570 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1571 |
4833 | 1572 if (col != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1573 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1574 if (Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1575 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1576 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1577 os << "\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1578 } |
1186 | 1579 |
5275 | 1580 octave_idx_type num_cols = lim - col; |
1186 | 1581 |
3548 | 1582 os << std::setw (extra_indent) << ""; |
1972 | 1583 |
1186 | 1584 if (num_cols == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1585 os << " Column " << col + 1 << ":\n"; |
1186 | 1586 else if (num_cols == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1587 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
1186 | 1588 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1589 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915 | 1590 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1591 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1592 os << "\n"; |
1186 | 1593 } |
1594 } | |
1595 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
1596 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1597 static inline void |
5030 | 1598 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1599 { |
5030 | 1600 if (val > T (0)) |
4632 | 1601 os << plus_format_chars[0]; |
5030 | 1602 else if (val < T (0)) |
4632 | 1603 os << plus_format_chars[1]; |
3248 | 1604 else |
4632 | 1605 os << plus_format_chars[2]; |
3248 | 1606 } |
1607 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1608 template <> |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1609 float_display_format |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1610 make_format (const Range& rng) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1611 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1612 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1613 double scale = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1614 return make_format (rng, fw, scale); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1615 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1616 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1617 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1618 float_display_format |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1619 make_format (const NDArray& nda) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1620 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1621 int fw = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1622 double scale = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1623 return make_format (Matrix (nda), fw, scale); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1624 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1625 |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1626 template <> |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1627 float_display_format |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1628 make_format (const FloatNDArray& nda) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1629 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1630 int fw = 0; |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1631 float scale = 0; |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1632 return make_format (FloatMatrix (nda), fw, scale); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1633 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1634 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1635 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1636 float_display_format |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1637 make_format (const ComplexNDArray& nda) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1638 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1639 int r_fw = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1640 int i_fw = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1641 double scale = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1642 return make_format (ComplexMatrix (nda), r_fw, i_fw, scale); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1643 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1644 |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1645 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1646 float_display_format |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1647 make_format (const FloatComplexNDArray& nda) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1648 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1649 int r_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1650 int i_fw = 0; |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1651 float scale = 0; |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1652 return make_format (FloatComplexMatrix (nda), r_fw, i_fw, scale); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1653 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1654 |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1655 template <> |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1656 float_display_format |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1657 make_format (const boolNDArray&) |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1658 { |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1659 return float_display_format (float_format (1, 1)); |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1660 } |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1661 |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1662 // FIXME: all this mess with abs is an attempt to avoid seeing |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1663 // |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1664 // warning: comparison of unsigned expression < 0 is always false |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1665 // |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1666 // from GCC. Isn't there a better way? |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1667 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1668 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1669 static inline T |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1670 abs (T x) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1671 { |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1672 return x < 0 ? -x : x; |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1673 } |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1674 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1675 #define INSTANTIATE_ABS(T) \ |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1676 template T abs (T) |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1677 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1678 INSTANTIATE_ABS(signed char); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1679 INSTANTIATE_ABS(short); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1680 INSTANTIATE_ABS(int); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1681 INSTANTIATE_ABS(long); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1682 INSTANTIATE_ABS(long long); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1683 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1684 #define SPECIALIZE_UABS(T) \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1685 template <> \ |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1686 inline unsigned T \ |
24747
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1687 abs (unsigned T x) \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1688 { \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1689 return x; \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1690 } |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1691 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1692 SPECIALIZE_UABS(char) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1693 SPECIALIZE_UABS(short) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1694 SPECIALIZE_UABS(int) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1695 SPECIALIZE_UABS(long) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1696 SPECIALIZE_UABS(long long) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1697 |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1698 #define MAKE_INT_MATRIX_FORMAT(TYPE) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1699 template <> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1700 float_display_format \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1701 make_format (const intNDArray<TYPE>& nda) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1702 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1703 bool isneg = false; \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1704 int digits = 0; \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1705 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1706 for (octave_idx_type i = 0; i < nda.numel (); i++) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1707 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1708 int new_digits \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1709 = static_cast<int> \ |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1710 (std::floor (log10 (double (abs (nda(i).value ()))) + 1)); \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1711 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1712 if (new_digits > digits) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1713 digits = new_digits; \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1714 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1715 if (! isneg) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1716 isneg = (abs (nda(i).value ()) != nda(i).value ()); \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1717 } \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1718 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1719 return float_display_format (float_format (digits + isneg, 0, 0)); \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1720 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1721 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1722 MAKE_INT_MATRIX_FORMAT (octave_int8) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1723 MAKE_INT_MATRIX_FORMAT (octave_uint8) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1724 MAKE_INT_MATRIX_FORMAT (octave_int16) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1725 MAKE_INT_MATRIX_FORMAT (octave_uint16) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1726 MAKE_INT_MATRIX_FORMAT (octave_int32) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1727 MAKE_INT_MATRIX_FORMAT (octave_uint32) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1728 MAKE_INT_MATRIX_FORMAT (octave_int64) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1729 MAKE_INT_MATRIX_FORMAT (octave_uint64) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1730 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1731 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1732 float_display_format |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1733 make_format (const double& d) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1734 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1735 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1736 return make_format (d, fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1737 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1738 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1739 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1740 float_display_format |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1741 make_format (const float& f) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1742 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1743 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1744 return make_format (f, fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1745 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1746 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1747 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1748 float_display_format |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1749 make_format (const Complex& c) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1750 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1751 int r_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1752 int i_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1753 return make_format (c, r_fw, i_fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1754 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1755 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1756 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1757 float_display_format |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1758 make_format (const FloatComplex& c) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1759 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1760 int r_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1761 int i_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1762 return make_format (c, r_fw, i_fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1763 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1764 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1765 #define MAKE_INT_SCALAR_FORMAT(TYPE) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1766 template <> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1767 float_display_format \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1768 make_format (const octave_int<TYPE>& val) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1769 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1770 bool isneg = false; \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1771 int digits \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1772 = static_cast<int> \ |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
1773 (std::floor (log10 (double (abs (val.value ()))) + 1)); \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1774 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1775 isneg = (abs (val.value ()) != val.value ()); \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1776 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1777 return float_display_format (float_format (digits + isneg, 0, 0)); \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1778 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1779 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1780 MAKE_INT_SCALAR_FORMAT (int8_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1781 MAKE_INT_SCALAR_FORMAT (uint8_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1782 MAKE_INT_SCALAR_FORMAT (int16_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1783 MAKE_INT_SCALAR_FORMAT (uint16_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1784 MAKE_INT_SCALAR_FORMAT (int32_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1785 MAKE_INT_SCALAR_FORMAT (uint32_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1786 MAKE_INT_SCALAR_FORMAT (int64_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1787 MAKE_INT_SCALAR_FORMAT (uint64_t) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1788 |
1 | 1789 void |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1790 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1791 bool d, bool pr_as_read_syntax) |
1 | 1792 { |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1793 octave_print_internal (os, fmt, octave_uint8 (d), pr_as_read_syntax); |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1794 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1795 |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1796 void |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1797 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax) |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1798 { |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1799 octave_print_internal (os, octave_uint8 (d), pr_as_read_syntax); |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1800 } |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1801 |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1802 void |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1803 octave_print_internal (std::ostream&, const float_display_format&, |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1804 char, bool) |
1 | 1805 { |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1806 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1807 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1808 |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1809 void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1810 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1811 double d, bool pr_as_read_syntax) |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1812 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1813 if (pr_as_read_syntax) |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1814 os << d; |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1815 else if (plus_format) |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1816 pr_plus_format (os, d); |
1 | 1817 else |
1818 { | |
1819 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1820 os << d; |
1 | 1821 else |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1822 pr_float (os, fmt, d); |
1 | 1823 } |
1824 } | |
1825 | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1826 void |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1827 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1828 float d, bool pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1829 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1830 if (pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1831 os << d; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1832 else if (plus_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1833 pr_plus_format (os, d); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1834 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1835 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1836 if (free_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1837 os << d; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1838 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1839 pr_float (os, fmt, d); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1840 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1841 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1842 |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1843 template <typename MT> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
1844 static inline void |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1845 octave_print_free (std::ostream& os, const MT& m, bool pr_as_read_syntax) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1846 { |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1847 octave_idx_type nr = m.rows (); |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1848 octave_idx_type nc = m.columns (); |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1849 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1850 if (pr_as_read_syntax) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1851 os << "[\n"; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1852 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1853 for (octave_idx_type i = 0; i < nr; i++) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1854 { |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1855 for (octave_idx_type j = 0; j < nc; j++) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1856 os << ' ' << m.elem(i,j); |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1857 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1858 if (i < nr - 1) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1859 os << "\n"; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1860 } |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1861 |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1862 if (pr_as_read_syntax) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1863 os << ']'; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1864 } |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1865 |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1866 template <typename MT> |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1867 static inline void |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1868 pr_plus_format_matrix (std::ostream& os, const MT& m) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1869 { |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1870 octave_idx_type nr = m.rows (); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1871 octave_idx_type nc = m.columns (); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1872 |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1873 for (octave_idx_type i = 0; i < nr; i++) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1874 { |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1875 for (octave_idx_type j = 0; j < nc; j++) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1876 { |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1877 octave_quit (); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1878 |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1879 pr_plus_format (os, m(i,j)); |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1880 } |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1881 |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1882 if (i < nr - 1) |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1883 os << "\n"; |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1884 } |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1885 } |
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1886 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1887 template <typename MT> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1888 static void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1889 octave_print_real_matrix_internal (std::ostream& os, const MT& m, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1890 bool pr_as_read_syntax, int extra_indent) |
1 | 1891 { |
5275 | 1892 octave_idx_type nr = m.rows (); |
1893 octave_idx_type nc = m.columns (); | |
1 | 1894 |
2408 | 1895 if (nr == 0 || nc == 0) |
626 | 1896 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1897 else if (plus_format && ! pr_as_read_syntax) | |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
1898 pr_plus_format_matrix (os, m); |
1 | 1899 else |
1900 { | |
23797
755b4c622972
Fix "variable may be used uninitialized" warning reported by gcc.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1901 int fw = 0; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
1902 typename MT::element_type scale = 1; |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
1903 float_display_format fmt = make_format (m, fw, scale); |
1 | 1904 int column_width = fw + 2; |
5275 | 1905 octave_idx_type total_width = nc * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
1906 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
1 | 1907 |
626 | 1908 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1909 max_width -= 4; |
1972 | 1910 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1911 max_width -= extra_indent; |
1972 | 1912 |
1913 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1914 max_width = 0; |
626 | 1915 |
1 | 1916 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1917 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
1918 octave_print_free (os, m, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1919 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1920 } |
1 | 1921 |
5275 | 1922 octave_idx_type inc = nc; |
2165 | 1923 if (total_width > max_width && Vsplit_long_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1924 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1925 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1926 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1927 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1928 } |
1 | 1929 |
626 | 1930 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1931 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1932 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1933 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1934 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1935 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1936 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1937 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1938 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1939 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1940 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1941 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1942 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1943 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1944 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1945 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1946 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1947 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1948 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1949 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1950 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1951 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1952 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
1953 pr_float (os, fmt, m(i,j)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1954 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1955 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1956 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1957 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1958 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1959 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1960 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1961 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1962 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1963 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1964 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1965 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1966 os << " ...\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1967 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1968 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1969 } |
626 | 1970 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1971 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1972 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1973 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1974 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1975 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1976 for (octave_idx_type col = 0; col < nc; col += inc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1977 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1978 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1979 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1980 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1981 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1982 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1983 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1984 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1985 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1986 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1987 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1988 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1989 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1990 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1991 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1992 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
1993 pr_float (os, fmt, m(i,j), fw, scale); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1994 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1995 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1996 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1997 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1998 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1999 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2000 } |
1 | 2001 } |
2002 } | |
2003 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2004 template <typename DMT> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2005 static void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2006 octave_print_real_diag_matrix_internal (std::ostream& os, const DMT& m, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2007 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2008 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2009 octave_idx_type nr = m.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2010 octave_idx_type nc = m.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2011 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2012 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2013 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2014 else if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2015 pr_plus_format_matrix (os, m); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2016 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2017 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2018 int fw; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2019 typename DMT::element_type scale = 1; |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2020 float_display_format fmt = make_format (Matrix (m.diag ()), fw, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2021 int column_width = fw + 2; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2022 octave_idx_type total_width = nc * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
2023 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2024 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2025 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2026 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2027 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2028 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2029 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2030 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2031 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2032 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2033 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2034 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2035 octave_print_free (os, m, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2036 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2037 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2038 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2039 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2040 if (total_width > max_width && Vsplit_long_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2041 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2042 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2043 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2044 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2045 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2046 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2047 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2048 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2049 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2050 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2051 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2052 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2053 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2054 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2055 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2056 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2057 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2058 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2059 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2060 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2061 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2062 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2063 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2064 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2065 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2066 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2067 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2068 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2069 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2070 pr_float (os, fmt, m(j,j)); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2071 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2072 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2073 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2074 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2075 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2076 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2077 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2078 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2079 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2080 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2081 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2082 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2083 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2084 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2085 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2086 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2087 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2088 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2089 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2090 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2091 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
2092 // kluge. Get the true width of a number. |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2093 int zero_fw; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2094 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2095 std::ostringstream tmp_oss; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2096 typename DMT::element_type zero = 0; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2097 pr_float (tmp_oss, fmt, zero, fw, scale); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2098 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2099 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2100 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2101 for (octave_idx_type col = 0; col < nc; col += inc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2102 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2103 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2104 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2105 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2106 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2107 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2108 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2109 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2110 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2111 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2112 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2113 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2114 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2115 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2116 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2117 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2118 if (i == j) |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2119 pr_float (os, fmt, m(i,j), fw, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2120 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2121 os << std::setw (zero_fw) << '0'; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2122 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2123 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2124 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2125 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2126 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2127 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2128 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2129 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2130 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2131 } |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2132 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2133 template <typename NDA_T, typename ELT_T, typename MAT_T> |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
2134 void print_nd_array (std::ostream& os, const NDA_T& nda, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
2135 bool pr_as_read_syntax) |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2136 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2137 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2138 if (nda.isempty ()) |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2139 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2140 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2141 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2142 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2143 int ndims = nda.ndims (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2144 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2145 dim_vector dims = nda.dims (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2146 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2147 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2148 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2149 octave_idx_type m = 1; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2150 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2151 for (int i = 2; i < ndims; i++) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2152 m *= dims(i); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2153 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2154 octave_idx_type nr = dims(0); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2155 octave_idx_type nc = dims(1); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2156 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2157 for (octave_idx_type i = 0; i < m; i++) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2158 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2159 octave_quit (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2160 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2161 std::string nm = "ans"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2162 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2163 if (m > 1) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2164 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2165 nm += "(:,:,"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2166 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2167 std::ostringstream buf; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2168 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2169 for (int k = 2; k < ndims; k++) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2170 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2171 buf << ra_idx(k) + 1; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2172 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2173 if (k < ndims - 1) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2174 buf << ','; |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2175 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2176 buf << ')'; |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2177 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2178 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2179 nm += buf.str (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2180 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2181 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2182 Array<idx_vector> idx (dim_vector (ndims, 1)); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2183 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2184 idx(0) = idx_vector (':'); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2185 idx(1) = idx_vector (':'); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2186 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2187 for (int k = 2; k < ndims; k++) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2188 idx(k) = idx_vector (ra_idx(k)); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2189 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2190 octave_value page |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2191 = MAT_T (Array<ELT_T> (nda.index (idx), dim_vector (nr, nc))); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2192 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2193 if (i != m - 1) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2194 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2195 page.print_with_name (os, nm); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2196 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2197 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2198 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2199 page.print_name_tag (os, nm); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2200 page.print_raw (os); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2201 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2202 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2203 if (i < m) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2204 NDA_T::increment_index (ra_idx, dims, 2); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2205 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2206 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2207 } |
4532 | 2208 |
4513 | 2209 void |
2210 octave_print_internal (std::ostream& os, const NDArray& nda, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2211 bool pr_as_read_syntax, int extra_indent) |
4513 | 2212 { |
2213 switch (nda.ndims ()) | |
2214 { | |
2215 case 1: | |
2216 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2217 octave_print_internal (os, Matrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2218 pr_as_read_syntax, extra_indent); |
4513 | 2219 break; |
2220 | |
2221 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2222 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax); |
4513 | 2223 break; |
2224 } | |
2225 } | |
2226 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2227 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2228 octave_print_internal (std::ostream& os, const FloatNDArray& nda, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2229 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2230 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2231 switch (nda.ndims ()) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2232 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2233 case 1: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2234 case 2: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2235 octave_print_internal (os, FloatMatrix (nda), |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2236 pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2237 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2238 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2239 default: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2240 print_nd_array <FloatNDArray, float, FloatMatrix> (os, nda, pr_as_read_syntax); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2241 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2242 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2243 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2244 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2245 template <typename T> |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2246 static inline void |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2247 pr_plus_format (std::ostream& os, const std::complex<T>& c) |
3248 | 2248 { |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2249 T rp = c.real (); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2250 T ip = c.imag (); |
3248 | 2251 |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2252 if (rp == 0) |
3248 | 2253 { |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2254 if (ip == 0) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2255 os << ' '; |
3248 | 2256 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2257 os << 'i'; |
3248 | 2258 } |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2259 else if (ip == 0) |
3608 | 2260 pr_plus_format (os, rp); |
3248 | 2261 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2262 os << 'c'; |
3248 | 2263 } |
2264 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2265 extern void |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2266 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2267 const Complex& c, bool pr_as_read_syntax) |
1 | 2268 { |
17867
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2269 if (pr_as_read_syntax) |
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2270 os << c; |
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2271 else if (plus_format) |
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2272 pr_plus_format (os, c); |
1 | 2273 else |
2274 { | |
2275 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2276 os << c; |
1 | 2277 else |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2278 pr_complex (os, fmt, c); |
1 | 2279 } |
2280 } | |
2281 | |
2282 void | |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2283 octave_print_internal (std::ostream& os, const float_display_format& fmt, |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2284 const FloatComplex& c, bool pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2285 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2286 if (pr_as_read_syntax) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2287 os << c; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2288 else if (plus_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2289 pr_plus_format (os, c); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2290 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2291 { |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2292 if (free_format) |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2293 os << c; |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2294 else |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2295 pr_complex (os, fmt, c); |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2296 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2297 } |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
2298 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2299 template <typename MT> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2300 static void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2301 octave_print_complex_matrix_internal (std::ostream& os, const MT& cm, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2302 bool pr_as_read_syntax, int extra_indent) |
1 | 2303 { |
5275 | 2304 octave_idx_type nr = cm.rows (); |
2305 octave_idx_type nc = cm.columns (); | |
1 | 2306 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2307 if (nr == 0 || nc == 0) |
626 | 2308 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2309 else if (plus_format && ! pr_as_read_syntax) | |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2310 pr_plus_format_matrix (os, cm); |
1 | 2311 else |
2312 { | |
2313 int r_fw, i_fw; | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2314 typename MT::real_elt_type scale = 1; |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2315 float_display_format fmt = make_format (cm, r_fw, i_fw, scale); |
1 | 2316 int column_width = i_fw + r_fw; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2317 column_width += (rat_format || bank_format || hex_format |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2318 || bit_format) ? 2 : 7; |
5275 | 2319 octave_idx_type total_width = nc * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
2320 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
1 | 2321 |
626 | 2322 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2323 max_width -= 4; |
1972 | 2324 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2325 max_width -= extra_indent; |
1972 | 2326 |
2327 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2328 max_width = 0; |
626 | 2329 |
1 | 2330 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2331 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2332 octave_print_free (os, cm, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2333 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2334 } |
1 | 2335 |
5275 | 2336 octave_idx_type inc = nc; |
2165 | 2337 if (total_width > max_width && Vsplit_long_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2338 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2339 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2340 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2341 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2342 } |
1 | 2343 |
626 | 2344 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2345 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2346 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2347 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2348 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2349 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2350 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2351 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2352 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2353 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2354 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2355 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2356 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2357 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2358 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2359 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2360 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2361 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2362 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2363 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2364 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2365 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2366 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2367 pr_complex (os, fmt, cm(i,j)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2368 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2369 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2370 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2371 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2372 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2373 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2374 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2375 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2376 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2377 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2378 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2379 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2380 os << " ...\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2381 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2382 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2383 } |
626 | 2384 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2385 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2386 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2387 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2388 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2389 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2390 for (octave_idx_type col = 0; col < nc; col += inc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2391 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2392 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2393 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2394 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2395 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2396 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2397 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2398 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2399 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2400 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2401 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2402 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2403 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2404 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2405 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2406 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2407 pr_complex (os, fmt, cm(i,j), r_fw, i_fw, scale); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2408 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2409 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2410 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2411 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2412 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2413 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2414 } |
1 | 2415 } |
2416 } | |
2417 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2418 template <typename DMT> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2419 static void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2420 octave_print_complex_diag_matrix_internal (std::ostream& os, const DMT& cm, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2421 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2422 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2423 octave_idx_type nr = cm.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2424 octave_idx_type nc = cm.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2425 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2426 if (nr == 0 || nc == 0) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2427 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2428 else if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2429 pr_plus_format_matrix (os, cm); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2430 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2431 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2432 int r_fw, i_fw; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2433 typename DMT::real_elt_type scale = 1; |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2434 float_display_format fmt |
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2435 = make_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2436 int column_width = i_fw + r_fw; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2437 column_width += (rat_format || bank_format || hex_format |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2438 || bit_format) ? 2 : 7; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2439 octave_idx_type total_width = nc * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
2440 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2441 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2442 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2443 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2444 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2445 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2446 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2447 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2448 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2449 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2450 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2451 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2452 octave_print_free (os, cm, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2453 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2454 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2455 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2456 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2457 if (total_width > max_width && Vsplit_long_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2458 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2459 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2460 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2461 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2462 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2463 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2464 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2465 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2466 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2467 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2468 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2469 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2470 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2471 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2472 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2473 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2474 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2475 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2476 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2477 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2478 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2479 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2480 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2481 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2482 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2483 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2484 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2485 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2486 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2487 pr_complex (os, fmt, cm(j,j)); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2488 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2489 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2490 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2491 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2492 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2493 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2494 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2495 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2496 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2497 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2498 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2499 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2500 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2501 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2502 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2503 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2504 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2505 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2506 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2507 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2508 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
2509 // kluge. Get the true width of a number. |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2510 int zero_fw; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2511 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2512 std::ostringstream tmp_oss; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2513 typename DMT::element_type zero = 0; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2514 pr_complex (tmp_oss, fmt, zero, r_fw, i_fw, scale); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2515 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2516 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2517 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2518 for (octave_idx_type col = 0; col < nc; col += inc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2519 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2520 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2521 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2522 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2523 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2524 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2525 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2526 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2527 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2528 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2529 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2530 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2531 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2532 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2533 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2534 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2535 if (i == j) |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2536 pr_complex (os, fmt, cm(i,j), r_fw, i_fw, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2537 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2538 os << std::setw (zero_fw) << '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2539 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2540 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2541 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2542 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2543 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2544 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2545 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2546 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2547 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2548 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2549 void |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2550 octave_print_internal (std::ostream& os, const PermMatrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2551 bool pr_as_read_syntax, int extra_indent) |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2552 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2553 octave_idx_type nr = m.rows (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2554 octave_idx_type nc = m.columns (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2555 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2556 if (nr == 0 || nc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2557 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2558 else if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2559 pr_plus_format_matrix (os, m); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2560 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2561 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2562 int fw = 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2563 int column_width = fw + 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2564 octave_idx_type total_width = nc * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
2565 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2566 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2567 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2568 max_width -= 4; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2569 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2570 max_width -= extra_indent; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2571 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2572 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2573 max_width = 0; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2574 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2575 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2576 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2577 octave_print_free (os, m, pr_as_read_syntax); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2578 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2579 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2580 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2581 octave_idx_type inc = nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2582 if (total_width > max_width && Vsplit_long_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2583 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2584 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2585 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2586 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2587 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2588 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2589 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2590 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2591 Array<octave_idx_type> pvec = m.col_perm_vec (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2592 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2593 os << "eye ("; |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2594 os << ":, "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2595 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2596 octave_idx_type col = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2597 while (col < nc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2598 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2599 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2600 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2601 for (octave_idx_type j = col; j < lim; j++) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2602 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2603 octave_quit (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2604 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2605 if (j == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2606 os << "[ "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2607 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2608 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2609 if (j > col && j < lim) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2610 os << ", "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2611 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2612 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2613 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2614 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2615 os << pvec (j); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2616 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2617 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2618 col += inc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2619 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2620 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2621 os << " ]"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2622 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2623 os << " ...\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2624 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2625 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2626 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2627 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2628 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2629 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2630 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2631 os << "Permutation Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2632 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2633 os << "\n"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2634 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2635 for (octave_idx_type col = 0; col < nc; col += inc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2636 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2637 octave_idx_type lim = (col + inc < nc ? col + inc : nc); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2638 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2639 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2640 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2641 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2642 for (octave_idx_type i = 0; i < nr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2643 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2644 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2645 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2646 for (octave_idx_type j = col; j < lim; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2648 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2649 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2650 os << " "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2651 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2652 os << std::setw (fw) << m(i,j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2653 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2654 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2655 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2656 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2657 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2658 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2659 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2660 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2661 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2662 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2663 void |
4513 | 2664 octave_print_internal (std::ostream& os, const ComplexNDArray& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2665 bool pr_as_read_syntax, int extra_indent) |
4513 | 2666 { |
2667 switch (nda.ndims ()) | |
2668 { | |
2669 case 1: | |
2670 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2671 octave_print_internal (os, ComplexMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2672 pr_as_read_syntax, extra_indent); |
4513 | 2673 break; |
2674 | |
2675 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2676 print_nd_array <ComplexNDArray, Complex, ComplexMatrix> |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
2677 (os, nda, pr_as_read_syntax); |
4513 | 2678 break; |
2679 } | |
2680 } | |
2681 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2682 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2683 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2684 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2685 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2686 switch (nda.ndims ()) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2687 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2688 case 1: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2689 case 2: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2690 octave_print_internal (os, FloatComplexMatrix (nda), |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2691 pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2692 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2693 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2694 default: |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2695 print_nd_array <FloatComplexNDArray, FloatComplex, FloatComplexMatrix> |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2696 (os, nda, pr_as_read_syntax); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2697 break; |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2698 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2699 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2700 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2701 // FIXME: write single precision versions of the printing functions. |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2702 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2703 void |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2704 octave_print_internal (std::ostream& os, const Matrix& m, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2705 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2706 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2707 octave_print_real_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2708 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2709 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2710 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2711 octave_print_internal (std::ostream& os, const FloatMatrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2712 bool pr_as_read_syntax, int extra_indent) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2713 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2714 octave_print_real_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2715 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2716 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2717 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2718 octave_print_internal (std::ostream& os, const DiagMatrix& m, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2719 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2720 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2721 octave_print_real_diag_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2722 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2723 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2724 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2725 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2726 bool pr_as_read_syntax, int extra_indent) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2727 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2728 octave_print_real_diag_matrix_internal (os, m, pr_as_read_syntax, extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2729 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2730 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2731 void |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2732 octave_print_internal (std::ostream& os, const ComplexMatrix& cm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2733 bool pr_as_read_syntax, int extra_indent) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2734 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2735 octave_print_complex_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2736 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2737 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2738 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2739 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2740 bool pr_as_read_syntax, int extra_indent) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2741 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2742 octave_print_complex_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2743 } |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2744 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2745 void |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2746 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2747 bool pr_as_read_syntax, int extra_indent) |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2748 { |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2749 octave_print_complex_diag_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2750 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2751 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2752 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2753 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2754 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2755 { |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
2756 octave_print_complex_diag_matrix_internal (os, cm, pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2757 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2758 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2759 void |
3523 | 2760 octave_print_internal (std::ostream& os, const Range& r, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2761 bool pr_as_read_syntax, int extra_indent) |
1 | 2762 { |
626 | 2763 double base = r.base (); |
1 | 2764 double increment = r.inc (); |
626 | 2765 double limit = r.limit (); |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20172
diff
changeset
|
2766 octave_idx_type num_elem = r.numel (); |
1 | 2767 |
626 | 2768 if (plus_format && ! pr_as_read_syntax) |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
2769 pr_plus_format_matrix (os, r); |
1 | 2770 else |
2771 { | |
10987
eec74ee00b32
eliminate some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2772 int fw = 0; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2773 double scale = 1; |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2774 float_display_format fmt = make_format (r, fw, scale); |
1 | 2775 |
626 | 2776 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2777 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2778 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2779 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2780 os << base << " : "; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2781 if (increment != 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2782 os << increment << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2783 os << limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2784 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2785 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2786 { |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2787 pr_float (os, fmt, base, fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2788 os << " : "; |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
2789 if (increment != 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2790 { |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2791 pr_float (os, fmt, increment, fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2792 os << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2793 } |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2794 pr_float (os, fmt, limit, fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2795 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2796 } |
626 | 2797 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2798 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2799 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2800 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2801 int column_width = fw + 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2802 octave_idx_type total_width = num_elem * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
2803 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2804 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2805 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2806 { |
24769
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2807 os << ' '; |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2808 for (octave_idx_type i = 0; i < num_elem; i++) |
e574b957b01b
don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents:
24767
diff
changeset
|
2809 os << ' ' << r.elem(i); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2810 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2811 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2812 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2813 octave_idx_type inc = num_elem; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2814 if (total_width > max_width && Vsplit_long_rows) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2816 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2817 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2818 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2819 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2820 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2821 max_width -= extra_indent; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2822 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2823 if (max_width < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2824 max_width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2825 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2826 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2827 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2828 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2829 while (col < num_elem) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2830 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2831 octave_idx_type lim = (col + inc < num_elem ? col + inc : num_elem); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2832 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2833 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2834 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2835 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2836 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2837 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2838 for (octave_idx_type i = col; i < lim; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2839 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2840 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2841 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2842 double val; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2843 if (i == 0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2844 val = base; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2845 else |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2846 val = base + i * increment; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2847 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2848 if (i == num_elem - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2849 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2850 // See the comments in Range::matrix_value. |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2851 if ((increment > 0 && val >= limit) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2852 || (increment < 0 && val <= limit)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2853 val = limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2854 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2855 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2856 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2857 |
24761
d7c3918955e6
eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents:
24760
diff
changeset
|
2858 pr_float (os, fmt, val, fw, scale); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2859 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2860 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2861 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2862 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2863 } |
1 | 2864 } |
2865 } | |
2866 | |
1343 | 2867 void |
3523 | 2868 octave_print_internal (std::ostream& os, const boolMatrix& bm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2869 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2870 int extra_indent) |
3215 | 2871 { |
21583
d5963a6e29c2
Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents:
21568
diff
changeset
|
2872 uint8NDArray tmp (bm); |
3215 | 2873 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
2874 } | |
2875 | |
2876 void | |
4513 | 2877 octave_print_internal (std::ostream& os, const boolNDArray& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2878 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2879 int extra_indent) |
4513 | 2880 { |
2881 switch (nda.ndims ()) | |
2882 { | |
2883 case 1: | |
2884 case 2: | |
19317
25f535b90e52
Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents:
19255
diff
changeset
|
2885 octave_print_internal (os, boolMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2886 pr_as_read_syntax, extra_indent); |
4513 | 2887 break; |
2888 | |
2889 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2890 print_nd_array<boolNDArray, bool, |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2891 boolMatrix> (os, nda, pr_as_read_syntax); |
4513 | 2892 break; |
2893 } | |
2894 } | |
2895 | |
2896 void | |
3523 | 2897 octave_print_internal (std::ostream& os, const charMatrix& chm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2898 bool pr_as_read_syntax, |
21066
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2899 int /* FIXME: extra_indent */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2900 bool pr_as_string) |
1343 | 2901 { |
1572 | 2902 if (pr_as_string) |
2903 { | |
5275 | 2904 octave_idx_type nstr = chm.rows (); |
1343 | 2905 |
1572 | 2906 if (pr_as_read_syntax && nstr > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2907 os << "[ "; |
1343 | 2908 |
2907 | 2909 if (nstr != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2910 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2911 for (octave_idx_type i = 0; i < nstr; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2912 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2913 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2914 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2915 std::string row = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2916 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2917 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2918 { |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23797
diff
changeset
|
2919 os << '"' << undo_string_escapes (row) << '"'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2920 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2921 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2922 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2923 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2924 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2925 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2926 os << row; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2927 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2928 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2929 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2930 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2931 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2932 } |
1572 | 2933 |
2934 if (pr_as_read_syntax && nstr > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2935 os << " ]"; |
1343 | 2936 } |
1572 | 2937 else |
2938 { | |
2939 os << "sorry, printing char matrices not implemented yet\n"; | |
2940 } | |
1343 | 2941 } |
2942 | |
4513 | 2943 void |
2944 octave_print_internal (std::ostream& os, const charNDArray& nda, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2945 bool pr_as_read_syntax, int extra_indent, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2946 bool pr_as_string) |
4513 | 2947 { |
2948 switch (nda.ndims ()) | |
2949 { | |
2950 case 1: | |
2951 case 2: | |
19318
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
19317
diff
changeset
|
2952 octave_print_internal (os, charMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2953 pr_as_read_syntax, extra_indent, pr_as_string); |
4513 | 2954 break; |
2955 | |
2956 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2957 print_nd_array <charNDArray, char, charMatrix> (os, nda, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2958 pr_as_read_syntax); |
4513 | 2959 break; |
2960 } | |
2961 } | |
2962 | |
4655 | 2963 void |
4925 | 2964 octave_print_internal (std::ostream& os, const std::string& s, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2965 bool pr_as_read_syntax, int extra_indent) |
4925 | 2966 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2967 Array<std::string> nda (dim_vector (1, 1), s); |
4925 | 2968 |
2969 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2970 } | |
2971 | |
2972 void | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2973 octave_print_internal (std::ostream& os, const Array<std::string>& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2974 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2975 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2976 // FIXME: this mostly duplicates the code in the print_nd_array<> |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
2977 // function. Can fix this with std::is_same from C++11. |
4655 | 2978 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2979 if (nda.isempty ()) |
4655 | 2980 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
2981 else if (nda.numel () == 1) |
4655 | 2982 { |
2983 os << nda(0); | |
2984 } | |
2985 else | |
2986 { | |
2987 int ndims = nda.ndims (); | |
2988 | |
2989 dim_vector dims = nda.dims (); | |
2990 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2991 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 2992 |
2993 octave_idx_type m = 1; | |
4655 | 2994 |
2995 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2996 m *= dims(i); |
4655 | 2997 |
5275 | 2998 octave_idx_type nr = dims(0); |
2999 octave_idx_type nc = dims(1); | |
3000 | |
3001 for (octave_idx_type i = 0; i < m; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3002 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3003 std::string nm = "ans"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3004 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3005 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3006 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3007 nm += "(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3008 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3009 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3010 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3011 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3012 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3013 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3014 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3015 if (k < ndims - 1) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3016 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3017 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3018 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3019 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3020 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3021 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3022 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3023 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3024 Array<idx_vector> idx (dim_vector (ndims, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3025 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3026 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3027 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3028 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3029 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3030 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3031 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3032 Array<std::string> page (nda.index (idx), dim_vector (nr, nc)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3033 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3034 // FIXME: need to do some more work to put these |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3035 // in neatly aligned columns... |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3036 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3037 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3038 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3039 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3040 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3041 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3042 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3043 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3044 for (octave_idx_type ii = 0; ii < n_rows; ii++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3045 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3046 for (octave_idx_type jj = 0; jj < n_cols; jj++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3047 os << " " << page(ii,jj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3048 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3049 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3050 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3051 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3052 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3053 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3054 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3055 if (i < m) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3056 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3057 } |
4655 | 3058 } |
3059 } | |
3060 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3061 template <typename T> |
4901 | 3062 class |
3063 octave_print_conv | |
3064 { | |
3065 public: | |
3066 typedef T print_conv_type; | |
3067 }; | |
3068 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3069 #define PRINT_CONV(T1, T2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3070 template <> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3071 class \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3072 octave_print_conv<T1> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3073 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3074 public: \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3075 typedef T2 print_conv_type; \ |
4901 | 3076 } |
3077 | |
3078 PRINT_CONV (octave_int8, octave_int16); | |
3079 PRINT_CONV (octave_uint8, octave_uint16); | |
3080 | |
3081 #undef PRINT_CONV | |
3082 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3083 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3084 static inline void |
4949 | 3085 pr_int (std::ostream& os, const T& d, int fw = 0) |
3086 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14429
diff
changeset
|
3087 size_t sz = d.byte_size (); |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23410
diff
changeset
|
3088 const unsigned char *tmpi = d.iptr (); |
4949 | 3089 |
5544 | 3090 // Unless explicitly asked for, always print in big-endian |
3091 // format for hex and bit formats. | |
3092 // | |
3093 // {bit,hex}_format == 1: print big-endian | |
3094 // {bit,hex}_format == 2: print native | |
3095 | |
4949 | 3096 if (hex_format) |
3097 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3098 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3099 |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3100 os.flags (std::ios::right | std::ios::hex); |
4949 | 3101 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3102 if (hex_format > 1 || octave::mach_info::words_big_endian ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3103 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3104 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3105 os << std::setw (2) << static_cast<int> (tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3106 } |
4949 | 3107 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3108 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3109 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3110 os << std::setw (2) << static_cast<int> (tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3111 } |
4949 | 3112 } |
3113 else if (bit_format) | |
3114 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3115 if (octave::mach_info::words_big_endian ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3116 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3117 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3118 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3119 } |
4949 | 3120 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3121 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3122 if (bit_format > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3123 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3124 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3125 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3126 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3127 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3128 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3129 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3130 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3131 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3132 } |
4949 | 3133 } |
3134 else | |
3135 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3136 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3137 |
4949 | 3138 os << std::setw (fw) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3139 << typename octave_print_conv<T>::print_conv_type (d); |
4949 | 3140 |
3141 if (bank_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3142 os << ".00"; |
4949 | 3143 } |
3144 } | |
3145 | |
7215 | 3146 template void |
3147 pr_int (std::ostream&, const octave_int8&, int); | |
3148 | |
3149 template void | |
3150 pr_int (std::ostream&, const octave_int16&, int); | |
3151 | |
3152 template void | |
3153 pr_int (std::ostream&, const octave_int32&, int); | |
3154 | |
3155 template void | |
3156 pr_int (std::ostream&, const octave_int64&, int); | |
3157 | |
3158 template void | |
3159 pr_int (std::ostream&, const octave_uint8&, int); | |
3160 | |
3161 template void | |
3162 pr_int (std::ostream&, const octave_uint16&, int); | |
3163 | |
3164 template void | |
3165 pr_int (std::ostream&, const octave_uint32&, int); | |
3166 | |
3167 template void | |
3168 pr_int (std::ostream&, const octave_uint64&, int); | |
3169 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3170 template <typename T> |
4901 | 3171 void |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3172 octave_print_internal_template (std::ostream& os, |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3173 const float_display_format& fmt, |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3174 const octave_int<T>& val, bool) |
7215 | 3175 { |
3176 if (plus_format) | |
24781
e6f380f9b2a4
use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents:
24771
diff
changeset
|
3177 pr_plus_format (os, val); |
7215 | 3178 else |
3179 { | |
3180 if (free_format) | |
23534
b6498c088fca
maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
3181 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val); |
7215 | 3182 else |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3183 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3184 float_format r_fmt = fmt.real_format (); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3185 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3186 pr_int (os, val, r_fmt.fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3187 } |
7215 | 3188 } |
3189 } | |
3190 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3191 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3192 OCTINTERP_API void \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3193 octave_print_internal (std::ostream& os, \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3194 const float_display_format& fmt, \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3195 const octave_int<TYPE>& val, bool dummy) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3196 { \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3197 octave_print_internal_template (os, fmt, val, dummy); \ |
7215 | 3198 } |
3199 | |
3200 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
3201 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
3202 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
3203 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
3204 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
3205 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
3206 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
3207 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
3208 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3209 template <typename T> |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3210 static inline void |
7215 | 3211 octave_print_internal_template (std::ostream& os, const intNDArray<T>& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3212 bool pr_as_read_syntax, int extra_indent) |
4901 | 3213 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3214 // FIXME: this mostly duplicates the code in the print_nd_array<> |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
3215 // function. Can fix this with std::is_same from C++11. |
4901 | 3216 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
3217 if (nda.isempty ()) |
4901 | 3218 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20230
diff
changeset
|
3219 else if (nda.numel () == 1) |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3220 octave_print_internal_template (os, float_display_format (), nda(0), |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3221 pr_as_read_syntax); |
4949 | 3222 else if (plus_format && ! pr_as_read_syntax) |
4901 | 3223 { |
3224 int ndims = nda.ndims (); | |
3225 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3226 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
4949 | 3227 |
4901 | 3228 dim_vector dims = nda.dims (); |
3229 | |
5275 | 3230 octave_idx_type m = 1; |
4901 | 3231 |
3232 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3233 m *= dims(i); |
4901 | 3234 |
5275 | 3235 octave_idx_type nr = dims(0); |
3236 octave_idx_type nc = dims(1); | |
3237 | |
3238 for (octave_idx_type i = 0; i < m; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3239 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3240 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3241 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3242 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3243 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3244 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3245 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3246 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3247 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3248 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3249 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3250 if (k < ndims - 1) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3251 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3252 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3253 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3254 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3255 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3256 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3257 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3258 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3259 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3260 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3261 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3262 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3263 Array<idx_vector> idx (dim_vector (ndims, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3264 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3265 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3266 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3267 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3268 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3269 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3270 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3271 Array<T> page (nda.index (idx), dim_vector (nr, nc)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3272 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3273 for (octave_idx_type ii = 0; ii < nr; ii++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3274 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3275 for (octave_idx_type jj = 0; jj < nc; jj++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3277 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3278 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3279 pr_plus_format (os, page(ii,jj)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3280 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3281 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3282 if ((ii < nr - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3283 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3284 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3285 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3286 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3287 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3288 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3289 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3290 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3291 } |
4949 | 3292 } |
3293 else | |
3294 { | |
3295 int ndims = nda.ndims (); | |
3296 | |
3297 dim_vector dims = nda.dims (); | |
3298 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3299 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 3300 |
3301 octave_idx_type m = 1; | |
4949 | 3302 |
3303 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3304 m *= dims(i); |
4949 | 3305 |
5275 | 3306 octave_idx_type nr = dims(0); |
3307 octave_idx_type nc = dims(1); | |
4949 | 3308 |
3309 int fw = 0; | |
3310 if (hex_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3311 fw = 2 * nda(0).byte_size (); |
4949 | 3312 else if (bit_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3313 fw = nda(0).nbits (); |
4949 | 3314 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3315 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3316 bool isneg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3317 int digits = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3318 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3319 for (octave_idx_type i = 0; i < dims.numel (); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3320 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3321 int new_digits |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3322 = static_cast<int> |
24770
39186eac5a05
preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents:
24769
diff
changeset
|
3323 (std::floor (log10 (double (abs (nda(i).value ()))) + 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3324 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3325 if (new_digits > digits) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3326 digits = new_digits; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3327 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3328 if (! isneg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3329 isneg = (abs (nda(i).value ()) != nda(i).value ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3330 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3331 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3332 fw = digits + isneg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3333 } |
4949 | 3334 |
6788 | 3335 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 3336 octave_idx_type total_width = nc * column_width; |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21747
diff
changeset
|
3337 int max_width = octave::command_editor::terminal_cols () - extra_indent; |
5275 | 3338 octave_idx_type inc = nc; |
4949 | 3339 if (total_width > max_width && Vsplit_long_rows) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3340 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3341 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3342 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3343 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3344 } |
4949 | 3345 |
5275 | 3346 for (octave_idx_type i = 0; i < m; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3347 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3348 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3349 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3350 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3351 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3352 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3353 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3354 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3355 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3356 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3357 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3358 if (k < ndims - 1) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3359 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3360 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3361 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3362 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3363 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3364 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3365 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3366 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3367 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3368 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3369 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3370 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3371 Array<idx_vector> idx (dim_vector (ndims, 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3372 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3373 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3374 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3375 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3376 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3377 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3378 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3379 Array<T> page (nda.index (idx), dim_vector (nr, nc)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3380 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3381 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3383 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3384 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3385 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3386 for (octave_idx_type ii = 0; ii < nr; ii++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3388 for (octave_idx_type jj = 0; jj < nc; jj++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3389 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3390 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3391 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3392 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3393 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3394 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3395 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3396 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3397 if (pr_as_read_syntax) |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3398 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3399 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3400 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3401 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3402 octave::preserve_stream_state stream_state (os); |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3404 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3405 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3406 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3407 for (octave_idx_type col = 0; col < n_cols; col += inc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3408 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
3409 octave_idx_type lim = (col + inc < n_cols ? col + inc |
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
3410 : n_cols); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3411 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3412 pr_col_num_header (os, total_width, max_width, lim, col, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3413 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3414 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3415 for (octave_idx_type ii = 0; ii < n_rows; ii++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3416 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3417 os << std::setw (extra_indent) << ""; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3418 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3419 for (octave_idx_type jj = col; jj < lim; jj++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3420 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3421 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3422 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3423 pr_int (os, page(ii,jj), fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3424 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3425 if ((ii < n_rows - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3426 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3427 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3428 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3429 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3430 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3431 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3432 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3433 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3434 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3435 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3436 } |
4901 | 3437 } |
3438 } | |
3439 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3440 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3441 OCTINTERP_API void \ |
7215 | 3442 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3443 bool pr_as_read_syntax, int extra_indent) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3444 { \ |
7215 | 3445 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ |
3446 } | |
3447 | |
3448 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
3449 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
3450 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
3451 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
3452 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
3453 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
3454 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
3455 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 3456 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7896
diff
changeset
|
3457 void |
3933 | 3458 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928 | 3459 { |
3933 | 3460 panic_impossible (); |
3928 | 3461 } |
3462 | |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3463 void |
19620
a1d172bfcb2f
eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents:
19367
diff
changeset
|
3464 octave_print_internal (std::ostream&, const octave_value&, bool) |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3465 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3466 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3467 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3468 |
20915
a3359fe50966
remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents:
20909
diff
changeset
|
3469 DEFUN (rats, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3470 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3471 @deftypefn {} {} rats (@var{x}, @var{len}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3472 Convert @var{x} into a rational approximation represented as a string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3473 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3474 The string can be converted back into a matrix as follows: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3475 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3476 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3477 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3478 r = rats (hilb (4)); |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3479 x = str2num (r) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3480 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3481 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3482 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3483 The optional second argument defines the maximum length of the string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3484 representing the elements of @var{x}. By default @var{len} is 9. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3485 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3486 If the length of the smallest possible rational approximation exceeds |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3487 @var{len}, an asterisk (*) padded with spaces will be returned instead. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3488 @seealso{format, rat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3489 @end deftypefn */) |
6788 | 3490 { |
3491 int nargin = args.length (); | |
3492 | |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3493 if (nargin < 1 || nargin > 2) |
7896 | 3494 print_usage (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3495 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3496 octave_value arg = args(0); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3497 |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
3498 if (! arg.isnumeric ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3499 error ("rats: X must be numeric"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3500 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
3501 octave::unwind_protect frame; |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3502 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3503 frame.protect_var (rat_string_len); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3504 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3505 rat_string_len = 9; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3506 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3507 rat_string_len = args(1).nint_value (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3508 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3509 frame.protect_var (rat_format); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3510 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3511 rat_format = true; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3512 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3513 std::ostringstream buf; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3514 arg.print (buf); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3515 std::string s = buf.str (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3516 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3517 std::list<std::string> lst; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3518 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3519 size_t n = 0; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3520 size_t s_len = s.length (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3521 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3522 while (n < s_len) |
6788 | 3523 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3524 size_t m = s.find ('\n', n); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3525 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3526 if (m == std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3527 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3528 lst.push_back (s.substr (n)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3529 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3530 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3531 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3532 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3533 lst.push_back (s.substr (n, m - n)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3534 n = m + 1; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3535 } |
6788 | 3536 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3537 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3538 return ovl (string_vector (lst)); |
6788 | 3539 } |
3540 | |
3685 | 3541 DEFUN (disp, args, nargout, |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3542 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3543 doc: /* -*- texinfo -*- |
24764
36ca11f78553
Document second calling form of disp().
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
3544 @deftypefn {} {} disp (@var{x}) |
36ca11f78553
Document second calling form of disp().
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
3545 @deftypefnx {} {@var{str} =} disp (@var{x}) |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3546 Display the value of @var{x}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3547 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3548 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3549 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3550 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3551 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3552 disp ("The value of pi is:"), disp (pi) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3553 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3554 @print{} the value of pi is: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3555 @print{} 3.1416 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3556 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3557 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3558 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3559 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3560 Note that the output from @code{disp} always ends with a newline. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3561 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3562 If an output value is requested, @code{disp} prints nothing and returns the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3563 formatted output in a string. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3564 @seealso{fdisp} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3565 @end deftypefn */) |
3685 | 3566 { |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3567 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3568 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3569 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3570 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3571 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3572 octave_value arg = args(0); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3573 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3574 if (nargout == 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3575 arg.print (octave_stdout); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3576 else |
3685 | 3577 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3578 std::ostringstream buf; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3579 arg.print (buf); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
3580 retval = (octave_value (buf.str (), arg.is_dq_string () ? '"' : '\'')); |
3685 | 3581 } |
3582 | |
3583 return retval; | |
3584 } | |
3585 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3586 DEFMETHOD (fdisp, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3587 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3588 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3589 @deftypefn {} {} fdisp (@var{fid}, @var{x}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3590 Display the value of @var{x} on the stream @var{fid}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3591 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3592 For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3593 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3594 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3595 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3596 fdisp (stdout, "The value of pi is:"), fdisp (stdout, pi) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3597 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3598 @print{} the value of pi is: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3599 @print{} 3.1416 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3600 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3601 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3602 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3603 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3604 Note that the output from @code{fdisp} always ends with a newline. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3605 @seealso{disp} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3606 @end deftypefn */) |
3685 | 3607 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
3608 if (args.length () != 2) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3609 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3610 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3611 octave::stream_list& streams = interp.get_stream_list (); |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3612 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3613 int fid = streams.get_file_number (args(0)); |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3614 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3615 octave::stream os = streams.lookup (fid, "fdisp"); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3616 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3617 std::ostream *osp = os.output_stream (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3618 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3619 octave_value arg = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3620 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3621 if (osp) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3622 arg.print (*osp); |
3685 | 3623 else |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3624 error ("fdisp: stream FID not open for writing"); |
3685 | 3625 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3626 return ovl (); |
3685 | 3627 } |
3628 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3629 /* |
9629 | 3630 %!test |
3631 %! format short | |
3632 %! fd = tmpfile (); | |
3633 %! for r = [0, Inf -Inf, NaN] | |
3634 %! for i = [0, Inf -Inf, NaN] | |
3635 %! fdisp (fd, complex (r, i)); | |
3636 %! endfor | |
3637 %! endfor | |
3638 %! fclose (fd); | |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3639 |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3640 %!test |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3641 %! foo.real = pi * ones (3,20,3); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3642 %! foo.complex = pi * ones (3,20,3) + 1i; |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3643 %! foo.char = repmat ("- Hello World -", [3, 20]); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3644 %! foo.cell = {foo.real, foo.complex, foo.char}; |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3645 %! fields = fieldnames (foo); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
3646 %! for f = 1:numel (fields) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
3647 %! format loose; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3648 %! loose = disp (foo.(fields{f})); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
3649 %! format compact; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3650 %! compact = disp (foo.(fields{f})); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3651 %! expected = strrep (loose, "\n\n", "\n"); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
3652 %! assert (expected, compact); |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3653 %! endfor |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3654 */ |
9629 | 3655 |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3656 DEFUN (display, args, , |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3657 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3658 doc: /* -*- texinfo -*- |
23565
3a730821e4a2
doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
3659 @deftypefn {} {} display (@var{obj}) |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3660 Display the contents of the object @var{obj} prepended by its name. |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3661 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3662 The Octave interpreter calls the @code{display} function whenever it needs |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3663 to present a class on-screen. Typically, this would be a statement which |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3664 does not end in a semicolon to suppress output. For example: |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3665 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3666 @example |
23182
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3667 myclass (@dots{}) |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3668 @end example |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3669 |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3670 Or: |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3671 |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3672 @example |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3673 myobj = myclass (@dots{}) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3674 @end example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3675 |
23410
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3676 In general, user-defined classes should overload the @code{disp} method to |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3677 avoid the default output: |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3678 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3679 @example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3680 @group |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3681 myobj = myclass (@dots{}) |
23410
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3682 @result{} myobj = |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3683 |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3684 <class myclass> |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3685 @end group |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3686 @end example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3687 |
23410
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3688 When overloading the @code{display} method instead, one has to take care |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3689 of properly displaying the object's name. This can be done by using the |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3690 @code{inputname} function. |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3691 |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3692 @seealso{disp, class, subsref, subsasgn} |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3693 @end deftypefn */) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3694 { |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3695 int nargin = args.length (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3696 |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3697 // Matlab apparently accepts two arguments with the second set to the |
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3698 // inputname of the first. This is undocumented, but we'll use it. |
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3699 // However, we never call display methods for classes with more than |
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3700 // one argument. |
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3701 |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3702 if (nargin < 1 || nargin > 2) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3703 print_usage (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3704 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3705 std::string name; |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3706 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3707 if (nargin == 2) |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3708 name = args(1).xstring_value ("NAME must be a string"); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3709 else |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3710 { |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3711 string_vector names = args.name_tags (); |
22921
b28801182c08
don't display "ans" for "display (expr)" (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
3712 name = names(0); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3713 } |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3714 |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3715 // We are here because there is no overloaded display method for this |
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3716 // object type. |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3717 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3718 octave_value value = args(0); |
22989
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3719 |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3720 // If print_name_tag displays a newline, then also print one after |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3721 // disp is done. |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3722 |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3723 bool print_newlines = false; |
22921
b28801182c08
don't display "ans" for "display (expr)" (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
3724 if (valid_identifier (name)) |
22989
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3725 print_newlines = value.print_name_tag (octave_stdout, name); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3726 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3727 // Use feval so that dispatch will also work for disp. |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3728 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23059
diff
changeset
|
3729 octave::feval ("disp", ovl (value)); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3730 |
22989
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3731 if (print_newlines) |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3732 octave_stdout << std::endl; |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3733 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3734 return ovl (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3735 } |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3736 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3737 /* |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3738 %!test |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3739 %! str = evalc ("x = 1.1; display (x)"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3740 %! assert (str, "x = 1.1000\n"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3741 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3742 %!test |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3743 %! str = evalc ("display (1.1)"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3744 %! assert (str, " 1.1000\n"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3745 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3746 ## Test input validation |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3747 %!error display () |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3748 %!error display (1,2) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3749 */ |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3750 |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3751 static inline void |
1 | 3752 init_format_state (void) |
3753 { | |
2387 | 3754 free_format = false; |
3755 plus_format = false; | |
6788 | 3756 rat_format = false; |
2387 | 3757 bank_format = false; |
3608 | 3758 hex_format = 0; |
1309 | 3759 bit_format = 0; |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3760 Vcompact_format = false; |
2387 | 3761 print_e = false; |
3762 print_big_e = false; | |
4509 | 3763 print_g = false; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3764 print_eng = false; |
1 | 3765 } |
3766 | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3767 static std::string format_string ("short"); |
24782
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3768 |
0eb41237424e
more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents:
24781
diff
changeset
|
3769 static inline void |
1755 | 3770 set_format_style (int argc, const string_vector& argv) |
1 | 3771 { |
1755 | 3772 int idx = 1; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3773 std::string format; |
1755 | 3774 |
1899 | 3775 if (--argc > 0) |
1 | 3776 { |
3523 | 3777 std::string arg = argv[idx++]; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3778 format = arg; |
2584 | 3779 |
1755 | 3780 if (arg == "short") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3781 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3782 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3783 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3784 arg = argv[idx++]; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3785 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3786 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3787 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3788 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3789 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3790 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3791 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3792 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3793 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3794 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3795 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3796 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3797 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3798 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3799 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3800 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3801 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3802 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3803 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3804 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3805 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3806 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3807 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3808 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3809 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3810 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3811 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3812 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3813 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3814 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3815 error ("format: unrecognized option 'short %s'", arg.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3816 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3817 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3818 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3819 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3820 set_output_prec (5); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3821 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3822 else if (arg == "shorte") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3823 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3824 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3825 print_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3826 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3827 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3828 else if (arg == "shortE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3829 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3830 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3831 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3832 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3833 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3834 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3835 else if (arg == "shortg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3836 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3837 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3838 print_g = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3839 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3840 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3841 else if (arg == "shortG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3842 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3843 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3844 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3845 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3846 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3847 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3848 else if (arg == "shortEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3849 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3850 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3851 print_eng = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3852 set_output_prec (5); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3853 } |
1755 | 3854 else if (arg == "long") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3855 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3856 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3857 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3858 arg = argv[idx++]; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3859 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3860 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3861 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3862 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3863 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3864 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3865 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3866 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3867 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3868 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3869 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3870 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3871 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3872 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3873 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3874 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3875 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3876 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3877 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3878 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3879 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3880 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3881 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3882 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3883 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3884 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3885 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3886 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3887 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3888 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3889 error ("format: unrecognized option 'long %s'", arg.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3890 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3891 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3892 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3893 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3894 set_output_prec (16); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3895 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3896 else if (arg == "longe") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3897 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3898 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3899 print_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3900 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3901 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3902 else if (arg == "longE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3903 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3904 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3905 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3906 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3907 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3908 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3909 else if (arg == "longg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3910 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3911 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3912 print_g = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3913 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3914 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3915 else if (arg == "longG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3916 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3917 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3918 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3919 print_big_e = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3920 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3921 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3922 else if (arg == "longEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3923 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3924 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3925 print_eng = true; |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
3926 set_output_prec (16); |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3927 } |
1755 | 3928 else if (arg == "hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3929 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3930 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3931 hex_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3932 } |
1755 | 3933 else if (arg == "native-hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3934 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3935 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3936 hex_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3937 } |
1755 | 3938 else if (arg == "bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3939 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3940 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3941 bit_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3942 } |
1755 | 3943 else if (arg == "native-bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3944 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3945 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3946 bit_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3947 } |
1755 | 3948 else if (arg == "+" || arg == "plus") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3949 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3950 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3951 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3952 arg = argv[idx++]; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3953 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3954 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3955 if (arg.length () == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3956 plus_format_chars = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3957 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3958 error ("format: invalid option for plus format"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3959 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3960 else |
19232
97eea1e2d9ff
pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
3961 plus_format_chars = "+- "; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3962 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3963 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3964 plus_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3965 } |
6788 | 3966 else if (arg == "rat") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3967 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3968 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3969 rat_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3970 } |
1755 | 3971 else if (arg == "bank") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3972 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3973 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3974 bank_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3975 } |
1755 | 3976 else if (arg == "free") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3977 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3978 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3979 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3980 } |
1755 | 3981 else if (arg == "none") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3982 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3983 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3984 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3985 } |
1755 | 3986 else if (arg == "compact") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3987 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3988 Vcompact_format = true; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3989 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3990 } |
1755 | 3991 else if (arg == "loose") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3992 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3993 Vcompact_format = false; |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3994 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3995 } |
1 | 3996 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3997 error ("format: unrecognized format state '%s'", arg.c_str ()); |
1 | 3998 } |
3999 else | |
4000 { | |
4001 init_format_state (); | |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4002 set_output_prec (5); |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
4003 format = "short"; |
1 | 4004 } |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4005 |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4006 format_string = format; |
1 | 4007 } |
4008 | |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4009 DEFUN (format, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4010 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4011 @deftypefn {} {} format |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4012 @deftypefnx {} {} format options |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4013 @deftypefnx {} {[@var{format}, @var{formatspacing}] =} format |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4014 Reset or specify the format of the output produced by @code{disp} and Octave's |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4015 normal echoing mechanism. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4016 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4017 This command only affects the display of numbers, but not how they are stored |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4018 or computed. To change the internal representation from the default double use |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4019 one of the conversion functions such as @code{single}, @code{uint8}, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4020 @code{int64}, etc. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4021 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4022 By default, Octave displays 5 significant digits in a human readable form |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4023 (option @samp{short} paired with @samp{loose} format for matrices). If |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4024 @code{format} is invoked without any options, this default format is restored. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4025 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4026 Valid formats for floating point numbers are listed in the following |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4027 table. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4028 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4029 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4030 @item short |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4031 Fixed point format with 5 significant figures (default). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4032 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4033 @item long |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4034 Fixed point format with 16 significant figures. |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4035 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4036 As with the @samp{short} format, Octave will switch to an exponential @samp{e} |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4037 format if it is unable to format a matrix properly using the current format. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4038 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4039 @item short e |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4040 @itemx long e |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4041 Exponential format. The number to be represented is split between a mantissa |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4042 and an exponent (power of 10). The mantissa has 5 significant digits in the |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4043 short format. In the long format, double values are displayed with 16 |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4044 significant digits and single values are displayed with 8. For example, |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4045 with the @samp{short e} format, @code{pi} is displayed as @code{3.1416e+00}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4046 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4047 @item short E |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4048 @itemx long E |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4049 Identical to @samp{short e} or @samp{long e} but displays an uppercase @samp{E} |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4050 to indicate the exponent. For example, with the @samp{long E} format, |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4051 @code{pi} is displayed as @code{3.141592653589793E+00}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4052 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4053 @item short g |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4054 @itemx long g |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4055 Optimally choose between fixed point and exponential format based on the |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4056 magnitude of the number. For example, with the @samp{short g} format, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4057 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4058 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4059 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4060 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4061 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4062 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4063 9.8696 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4064 97.409 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4065 9488.5 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4066 9.0032e+07 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4067 8.1058e+15 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4068 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4069 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4070 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4071 @item short eng |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4072 @itemx long eng |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4073 Identical to @samp{short e} or @samp{long e} but displays the value using an |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4074 engineering format, where the exponent is divisible by 3. For example, with |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4075 the @samp{short eng} format, @code{10 * pi} is displayed as @code{31.416e+00}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4076 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4077 @item long G |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4078 @itemx short G |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4079 Identical to @samp{short g} or @samp{long g} but displays an uppercase @samp{E} |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4080 to indicate the exponent. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4081 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4082 @item free |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4083 @itemx none |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4084 Print output in free format, without trying to line up columns of matrices on |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4085 the decimal point. This is a raw format equivalent to the C++ code |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4086 @code{std::cout << @var{variable}}. In general, the result is a presentation |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4087 with 6 significant digits where unnecessary precision (such as trailing zeros |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4088 for integers) is suppressed. Complex numbers are formatted as numeric pairs |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4089 like this @samp{(0.60419, 0.60709)} instead of like this |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4090 @samp{0.60419 + 0.60709i}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4091 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4092 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4093 The following formats affect all numeric output (floating point and integer |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4094 types). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4095 |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4096 @table @asis |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4097 @item @qcode{"+"} |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4098 @itemx @qcode{"+"} @qcode{"@var{chars}"} |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4099 @itemx @code{plus} |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4100 @itemx @code{plus @var{chars}} |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4101 Print a @samp{+} symbol for matrix elements greater than zero, a @samp{-} |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4102 symbol for elements less than zero, and a space for zero matrix elements. This |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4103 format can be useful for examining the sparsity structure of a large matrix. |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4104 For very large matrices the function @code{spy} which plots the sparsity |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4105 pattern will be clearer. |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4106 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4107 The optional argument @var{chars} specifies a list of 3 characters to use for |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4108 printing values greater than zero, less than zero, and equal to zero. For |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4109 example, with the format @qcode{"+" "+-."}, the matrix |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4110 @code{[1, 0, -1; -1, 0, 1]} is displayed as |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4111 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4112 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4113 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4114 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4115 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4116 +.- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4117 -.+ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4118 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4119 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4120 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4121 @item bank |
24771
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4122 Print variable in a format appropriate for a currency (fixed format with two |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4123 digits to the right of the decimal point). Only the real part of a variable is |
d277debe9c2f
doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents:
24770
diff
changeset
|
4124 displayed, as the imaginary part makes no sense for a currency. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4125 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4126 @item native-hex |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4127 Print the hexadecimal representation of numbers as they are stored in memory. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4128 For example, on a workstation which stores 8 byte real values in IEEE format |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4129 with the least significant byte first, the value of @code{pi} when printed in |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4130 @code{native-hex} format is @code{400921fb54442d18}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4131 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4132 @item hex |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4133 The same as @code{native-hex}, but always print the most significant byte |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4134 first. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4135 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4136 @item native-bit |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4137 Print the bit representation of numbers as stored in memory. For example, the |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4138 value of @code{pi} is |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4139 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4140 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4141 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4142 01000000000010010010000111111011 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4143 01010100010001000010110100011000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4144 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4145 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4146 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4147 (shown here in two 32 bit sections for typesetting purposes) when printed in |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4148 native-bit format on a workstation which stores 8 byte real values in IEEE |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4149 format with the least significant byte first. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4150 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4151 @item bit |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4152 The same as @code{native-bit}, but always print the most significant bits |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4153 first. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4154 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4155 @item rat |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4156 Print a rational approximation, i.e., values are approximated as the ratio of |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4157 small integers. For example, with the @samp{rat} format, @code{pi} is |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4158 displayed as @code{355/113}. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4159 @end table |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4160 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4161 The following two options affect the display of all matrices. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4162 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4163 @table @code |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4164 @item compact |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4165 Remove blank lines around column number labels and between matrices producing |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4166 more compact output with more data per page. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4167 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4168 @item loose |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4169 Insert blank lines above and below column number labels and between matrices to |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4170 produce a more readable output with less data per page. (default). |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4171 @end table |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4172 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4173 If called with one or two output arguments, and no inputs, return the current |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4174 format and format spacing. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4175 |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4176 @seealso{fixed_point_format, output_precision, split_long_rows, print_empty_dimensions, rats} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4177 @end deftypefn */) |
529 | 4178 { |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4179 octave_value_list retval (std::min (nargout, 2)); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4180 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4181 if (nargout == 0) |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4182 { |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4183 int argc = args.length () + 1; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4184 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4185 string_vector argv = args.make_argv ("format"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4186 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4187 set_format_style (argc, argv); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4188 } |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4189 else |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4190 { |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4191 if (nargout >= 2) |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
4192 retval(1) = (Vcompact_format ? "compact" : "loose"); |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4193 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4194 retval(0) = format_string; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4195 } |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4196 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4197 return retval; |
529 | 4198 } |
4199 | |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4200 /* |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4201 %!test |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4202 %! [old_fmt, old_spacing] = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4203 %! unwind_protect |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4204 %! ## Test one of the formats |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4205 %! format long; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4206 %! str = disp (pi); |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4207 %! assert (str, " 3.141592653589793\n"); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4208 %! str = disp (single (pi)); |
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4209 %! assert (str, " 3.1415927\n"); |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4210 %! new_fmt = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4211 %! assert (new_fmt, "long"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4212 %! ## Test resetting format |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4213 %! format compact; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4214 %! [~, new_spacing] = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4215 %! assert (new_spacing, "compact"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4216 %! format; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4217 %! [new_fmt, new_spacing] = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4218 %! assert (new_fmt, "short"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4219 %! assert (new_spacing, "loose"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4220 %! unwind_protect_cleanup |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4221 %! format (old_fmt); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4222 %! format (old_spacing); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4223 %! end_unwind_protect |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4224 */ |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4225 |
5794 | 4226 DEFUN (fixed_point_format, args, nargout, |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4227 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4228 @deftypefn {} {@var{val} =} fixed_point_format () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4229 @deftypefnx {} {@var{old_val} =} fixed_point_format (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4230 @deftypefnx {} {} fixed_point_format (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4231 Query or set the internal variable that controls whether Octave will |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4232 use a scaled format to print matrix values. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4233 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4234 The scaled format prints a scaling factor on the first line of output chosen |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4235 such that the largest matrix element can be written with a single leading |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4236 digit. For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4237 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4238 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4239 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4240 logspace (1, 7, 5)' |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4241 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4242 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4243 1.0e+07 * |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4244 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4245 0.00000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4246 0.00003 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4247 0.00100 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4248 0.03162 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4249 1.00000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4250 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4251 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4252 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4253 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4254 Notice that the first value appears to be 0 when it is actually 1. Because |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4255 of the possibility for confusion you should be careful about enabling |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4256 @code{fixed_point_format}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4257 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4258 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4259 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4260 The original variable value is restored when exiting the function. |
24784
4d945f2e5914
eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents:
24782
diff
changeset
|
4261 @seealso{format, output_precision} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4262 @end deftypefn */) |
5794 | 4263 { |
4264 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
4265 } | |
4266 | |
4267 DEFUN (print_empty_dimensions, args, nargout, | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4268 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4269 @deftypefn {} {@var{val} =} print_empty_dimensions () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4270 @deftypefnx {} {@var{old_val} =} print_empty_dimensions (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4271 @deftypefnx {} {} print_empty_dimensions (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4272 Query or set the internal variable that controls whether the dimensions of |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4273 empty matrices are printed along with the empty matrix symbol, @samp{[]}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4274 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4275 For example, the expression |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4276 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4277 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4278 zeros (3, 0) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4279 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4280 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4281 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4282 will print |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4283 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4284 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4285 ans = [](3x0) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4286 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4287 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4288 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4289 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4290 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4291 @seealso{format} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4292 @end deftypefn */) |
5794 | 4293 { |
4294 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
4295 } | |
4296 | |
4297 DEFUN (split_long_rows, args, nargout, | |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4298 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4299 @deftypefn {} {@var{val} =} split_long_rows () |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4300 @deftypefnx {} {@var{old_val} =} split_long_rows (@var{new_val}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4301 @deftypefnx {} {} split_long_rows (@var{new_val}, "local") |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4302 Query or set the internal variable that controls whether rows of a matrix |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4303 may be split when displayed to a terminal window. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4304 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4305 If the rows are split, Octave will display the matrix in a series of smaller |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4306 pieces, each of which can fit within the limits of your terminal width and |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4307 each set of rows is labeled so that you can easily see which columns are |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4308 currently being displayed. For example: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4309 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4310 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4311 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4312 octave:13> rand (2,10) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4313 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4314 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4315 Columns 1 through 6: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4316 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4317 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4318 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4319 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4320 Columns 7 through 10: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4321 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4322 0.90174 0.11854 0.72313 0.73326 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4323 0.44672 0.94303 0.56564 0.82150 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4324 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4325 @end example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4326 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4327 When called from inside a function with the @qcode{"local"} option, the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4328 variable is changed locally for the function and any subroutines it calls. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4329 The original variable value is restored when exiting the function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4330 @seealso{format} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4331 @end deftypefn */) |
5794 | 4332 { |
4333 return SET_INTERNAL_VARIABLE (split_long_rows); | |
4334 } |