Mercurial > octave
annotate libinterp/corefcn/pr-output.cc @ 17818:f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
* utils.h, utils.cc (octave_preserve_stream_state): New class.
* debug.cc, pr-output.cc, variables.cc, ov-base-sparse.cc: Use it to
save and restore stream flags, precision, field width, and fill
character.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 31 Oct 2013 17:26:04 -0400 |
parents | 175b392e91fe |
children | 3a0075793fcd |
rev | line source |
---|---|
1 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17415
diff
changeset
|
3 Copyright (C) 1993-2013 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1192 | 24 #include <config.h> |
1 | 25 #endif |
26 | |
1346 | 27 #include <cfloat> |
2825 | 28 #include <cstdio> |
1346 | 29 #include <cstring> |
1343 | 30 |
3503 | 31 #include <iomanip> |
32 #include <iostream> | |
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" |
7231 | 42 #include "lo-math.h" |
2317 | 43 #include "mach-info.h" |
1651 | 44 #include "oct-cmplx.h" |
4153 | 45 #include "quit.h" |
1755 | 46 #include "str-vec.h" |
1 | 47 |
3933 | 48 #include "Cell.h" |
1352 | 49 #include "defun.h" |
50 #include "error.h" | |
2165 | 51 #include "gripes.h" |
1755 | 52 #include "oct-obj.h" |
3685 | 53 #include "oct-stream.h" |
1352 | 54 #include "pager.h" |
55 #include "pr-output.h" | |
1282 | 56 #include "sysdep.h" |
6803 | 57 #include "unwind-prot.h" |
1 | 58 #include "utils.h" |
1352 | 59 #include "variables.h" |
1 | 60 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
61 // 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
|
62 // 'format short'. |
5794 | 63 static bool Vfixed_point_format = false; |
3105 | 64 |
2165 | 65 // The maximum field width for a number printed by the default output |
66 // routines. | |
5794 | 67 static int Voutput_max_field_width = 10; |
2165 | 68 |
69 // The precision of the numbers printed by the default output | |
70 // routines. | |
5794 | 71 static int Voutput_precision = 5; |
2165 | 72 |
5360 | 73 // TRUE means that the dimensions of empty objects should be printed |
2165 | 74 // like this: x = [](2x0). |
5794 | 75 bool Vprint_empty_dimensions = true; |
2165 | 76 |
77 // TRUE means that the rows of big matrices should be split into | |
78 // smaller slices that fit on the screen. | |
5794 | 79 static bool Vsplit_long_rows = true; |
2165 | 80 |
3018 | 81 // TRUE means don't do any fancy formatting. |
2387 | 82 static bool free_format = false; |
1 | 83 |
3018 | 84 // TRUE means print plus sign for nonzero, blank for zero. |
2387 | 85 static bool plus_format = false; |
1 | 86 |
4632 | 87 // First char for > 0, second for < 0, third for == 0. |
88 static std::string plus_format_chars = "+ "; | |
89 | |
6788 | 90 // TRUE means always print in a rational approximation |
91 static bool rat_format = false; | |
92 | |
93 // Used to force the length of the rational approximation string for Frats | |
94 static int rat_string_len = -1; | |
95 | |
3018 | 96 // TRUE means always print like dollars and cents. |
2387 | 97 static bool bank_format = false; |
1282 | 98 |
3018 | 99 // TRUE means print data in hexadecimal format. |
3608 | 100 static int hex_format = 0; |
1282 | 101 |
3018 | 102 // TRUE means print data in binary-bit-pattern format. |
1309 | 103 static int bit_format = 0; |
104 | |
3018 | 105 // 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
|
106 bool Vcompact_format = false; |
1186 | 107 |
3018 | 108 // TRUE means use an e format. |
2387 | 109 static bool print_e = false; |
1 | 110 |
4509 | 111 // TRUE means use a g format. |
112 static bool print_g = false; | |
113 | |
3018 | 114 // TRUE means print E instead of e for exponent field. |
2387 | 115 static bool print_big_e = false; |
1 | 116 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
117 // 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
|
118 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
|
119 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
120 class pr_engineering_float; |
3608 | 121 class pr_formatted_float; |
6788 | 122 class pr_rational_float; |
3608 | 123 |
4509 | 124 static int |
125 current_output_max_field_width (void) | |
126 { | |
127 return Voutput_max_field_width; | |
128 } | |
129 | |
130 static int | |
131 current_output_precision (void) | |
132 { | |
133 return Voutput_precision; | |
134 } | |
135 | |
3608 | 136 class |
137 float_format | |
138 { | |
139 public: | |
140 | |
4509 | 141 float_format (int w = current_output_max_field_width (), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
142 int p = current_output_precision (), int f = 0) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
143 : fw (w), ex (0), prec (p), fmt (f), up (0), sp (0) { } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
144 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
145 float_format (int w, int e, int p, int f) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
146 : fw (w), ex (e), prec (p), fmt (f), up (0), sp (0) { } |
3608 | 147 |
148 float_format (const float_format& ff) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
149 : fw (ff.fw), ex (ff.ex), prec (ff.prec), fmt (ff.fmt), up (ff.up), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
150 sp (ff.sp) { } |
3608 | 151 |
152 float_format& operator = (const float_format& ff) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
153 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
154 if (&ff != this) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
155 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
156 fw = ff.fw; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
157 ex = ff.ex; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
158 prec = ff.prec; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
159 fmt = ff.fmt; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 up = ff.up; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
161 sp = ff.sp; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
162 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
163 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
164 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
165 } |
3608 | 166 |
167 ~float_format (void) { } | |
168 | |
169 float_format& scientific (void) { fmt = std::ios::scientific; return *this; } | |
170 float_format& fixed (void) { fmt = std::ios::fixed; return *this; } | |
171 float_format& general (void) { fmt = 0; return *this; } | |
172 | |
173 float_format& uppercase (void) { up = std::ios::uppercase; return *this; } | |
174 float_format& lowercase (void) { up = 0; return *this; } | |
175 | |
176 float_format& precision (int p) { prec = p; return *this; } | |
177 | |
178 float_format& width (int w) { fw = w; return *this; } | |
179 | |
180 float_format& trailing_zeros (bool tz = true) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
181 { sp = tz ? std::ios::showpoint : 0; return *this; } |
3608 | 182 |
183 friend std::ostream& operator << (std::ostream& os, | |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
184 const pr_engineering_float& pef); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
185 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
186 friend std::ostream& operator << (std::ostream& os, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
187 const pr_formatted_float& pff); |
3608 | 188 |
6788 | 189 friend std::ostream& operator << (std::ostream& os, |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
190 const pr_rational_float& prf); |
6788 | 191 |
3608 | 192 private: |
193 | |
194 // Field width. Zero means as wide as necessary. | |
195 int fw; | |
196 | |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
197 // Exponent Field width. Zero means as wide as necessary. |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
198 int ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
199 |
3608 | 200 // Precision. |
201 int prec; | |
202 | |
203 // Format. | |
204 int fmt; | |
205 | |
206 // E or e. | |
207 int up; | |
208 | |
209 // Show trailing zeros. | |
210 int sp; | |
211 }; | |
212 | |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
213 static int |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
214 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
|
215 { |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
216 if (! print_eng) |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
217 return x; |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
218 else |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
219 return x - 3*static_cast<int> (x/3); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
220 /* The expression above is equivalent to x - (x % 3). |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
221 * According to the ISO specification for C++ the modulo operator is |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
222 * compiler dependent if any of the arguments are negative. Since this |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
223 * function will need to work on negative arguments, and we want to avoid |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
224 * portability issues, we re-implement the modulo function to the desired |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
225 * behavior (truncation). There may be a gnulib replacement. |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
226 * |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
227 * ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, IEC. 2003 . |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
228 * "the binary % operator yields the remainder from the division of the first |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
229 * expression by the second. .... If both operands are nonnegative then the |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
230 * remainder is nonnegative; if not, the sign of the remainder is |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
231 * implementation-defined". */ |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
232 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
233 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
234 static int |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
235 engineering_exponent (const double& x) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
236 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
237 int ex = 0; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
238 if (x != 0) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
239 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
240 double absval = (x < 0.0 ? -x : x); |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
241 int logabsval = static_cast<int> (gnulib::floor (log10 (absval))); |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
242 /* Avoid using modulo function with negative arguments for portability. |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
243 * See extended comment at calc_scale_exp */ |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
244 if (logabsval < 0.0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
245 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
|
246 else |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
247 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
|
248 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
249 return ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
250 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
251 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
252 static int |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
253 num_digits (const double& x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
254 { |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
255 return 1 + (print_eng |
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
256 ? engineering_exponent (x) |
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
257 : static_cast<int> (gnulib::floor (log10 (x)))); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
258 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
259 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
260 class |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
261 pr_engineering_float |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
262 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
263 public: |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
264 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
265 const float_format& f; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
266 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
267 double val; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
268 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
269 int exponent (void) const |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
270 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
271 return engineering_exponent (val); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
272 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
273 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
274 double mantissa (void) const |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
275 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
276 return val / std::pow (10.0, exponent ()); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
277 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
278 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
279 pr_engineering_float (const float_format& f_arg, double val_arg) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
280 : f (f_arg), val (val_arg) { } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
281 }; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
282 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
283 std::ostream& |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
284 operator << (std::ostream& os, const pr_engineering_float& pef) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
285 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
286 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
287 |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
288 if (pef.f.fw >= 0) |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
289 os << std::setw (pef.f.fw - pef.f.ex); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
290 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
291 if (pef.f.prec >= 0) |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
292 os << std::setprecision (pef.f.prec); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
293 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
294 os.flags (static_cast<std::ios::fmtflags> |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
295 (pef.f.fmt | pef.f.up | pef.f.sp)); |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
296 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
297 os << pef.mantissa (); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
298 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
299 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
|
300 if (ex < 0) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
301 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
302 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
|
303 ex = -ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
304 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
305 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
306 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
|
307 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
308 os << std::setw (pef.f.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
|
309 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
310 return os; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
311 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
312 |
3608 | 313 class |
314 pr_formatted_float | |
315 { | |
316 public: | |
317 | |
318 const float_format& f; | |
319 | |
320 double val; | |
321 | |
322 pr_formatted_float (const float_format& f_arg, double val_arg) | |
323 : f (f_arg), val (val_arg) { } | |
324 }; | |
325 | |
326 std::ostream& | |
327 operator << (std::ostream& os, const pr_formatted_float& pff) | |
328 { | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
329 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
330 |
3682 | 331 if (pff.f.fw >= 0) |
3608 | 332 os << std::setw (pff.f.fw); |
333 | |
3682 | 334 if (pff.f.prec >= 0) |
3608 | 335 os << std::setprecision (pff.f.prec); |
336 | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
337 os.flags (static_cast<std::ios::fmtflags> |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
338 (pff.f.fmt | pff.f.up | pff.f.sp)); |
3608 | 339 |
340 os << pff.val; | |
341 | |
342 return os; | |
343 } | |
344 | |
6788 | 345 static inline std::string |
346 rational_approx (double val, int len) | |
347 { | |
348 std::string s; | |
349 | |
350 if (len <= 0) | |
351 len = 10; | |
352 | |
353 if (xisinf (val)) | |
354 s = "1/0"; | |
355 else if (xisnan (val)) | |
356 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
|
357 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
|
358 || val > std::numeric_limits<int>::max () |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
359 || D_NINT (val) == val) |
6788 | 360 { |
361 std::ostringstream buf; | |
362 buf.flags (std::ios::fixed); | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
363 buf << std::setprecision (0) << xround (val); |
6788 | 364 s = buf.str (); |
365 } | |
366 else | |
367 { | |
368 double lastn = 1.; | |
369 double lastd = 0.; | |
370 double n = xround (val); | |
371 double d = 1.; | |
372 double frac = val - n; | |
373 int m = 0; | |
374 | |
375 std::ostringstream buf2; | |
376 buf2.flags (std::ios::fixed); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
377 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
|
378 s = buf2.str (); |
6788 | 379 |
380 while (1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
381 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 double flip = 1. / frac; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
383 double step = xround (flip); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
384 double nextn = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
385 double nextd = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
386 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 // Have we converged to 1/intmax ? |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
388 if (m > 100 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
389 || fabs (frac) < 1 / static_cast<double> (std::numeric_limits<int>::max ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
390 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
391 lastn = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
392 lastd = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
393 break; |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
396 frac = flip - step; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
397 n = n * step + lastn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
398 d = d * step + lastd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
399 lastn = nextn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
400 lastd = nextd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
401 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
402 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
403 buf.flags (std::ios::fixed); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
404 buf << std::setprecision (0) << static_cast<int>(n) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
405 << "/" << static_cast<int>(d); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
406 m++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
407 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
408 if (n < 0 && d < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
410 // Double negative, string can be two characters longer.. |
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
|
411 if (buf.str ().length () > static_cast<unsigned int>(len + 2) && |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
412 m > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
414 } |
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
|
415 else if (buf.str ().length () > static_cast<unsigned int>(len) && |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
416 m > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
417 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
418 |
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
|
419 s = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
420 } |
6788 | 421 |
422 if (lastd < 0.) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
423 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
424 // Move sign to the top |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
425 lastd = - lastd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
426 lastn = - lastn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
427 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
428 buf.flags (std::ios::fixed); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
429 buf << std::setprecision (0) << static_cast<int>(lastn) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
430 << "/" << 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
|
431 s = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
432 } |
6788 | 433 } |
434 | |
435 return s; | |
436 } | |
437 | |
438 class | |
439 pr_rational_float | |
440 { | |
441 public: | |
442 | |
443 const float_format& f; | |
444 | |
445 double val; | |
446 | |
447 pr_rational_float (const float_format& f_arg, double val_arg) | |
448 : f (f_arg), val (val_arg) { } | |
449 }; | |
450 | |
451 std::ostream& | |
452 operator << (std::ostream& os, const pr_rational_float& prf) | |
453 { | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
454 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
455 |
6788 | 456 int fw = (rat_string_len > 0 ? rat_string_len : prf.f.fw); |
457 std::string s = rational_approx (prf.val, fw); | |
458 | |
459 if (fw >= 0) | |
460 os << std::setw (fw); | |
461 | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
462 os.flags (static_cast<std::ios::fmtflags> |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
463 (prf.f.fmt | prf.f.up | prf.f.sp)); |
6788 | 464 |
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
|
465 if (fw > 0 && s.length () > static_cast<unsigned int>(fw)) |
6788 | 466 os << "*"; |
467 else | |
468 os << s; | |
469 | |
470 return os; | |
471 } | |
472 | |
3608 | 473 // Current format for real numbers and the real part of complex |
474 // numbers. | |
475 static float_format *curr_real_fmt = 0; | |
476 | |
477 // Current format for the imaginary part of complex numbers. | |
478 static float_format *curr_imag_fmt = 0; | |
1309 | 479 |
1 | 480 static double |
164 | 481 pr_max_internal (const Matrix& m) |
1 | 482 { |
5275 | 483 octave_idx_type nr = m.rows (); |
484 octave_idx_type nc = m.columns (); | |
1 | 485 |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
486 double result = -std::numeric_limits<double>::max (); |
1 | 487 |
5748 | 488 bool all_inf_or_nan = true; |
489 | |
5275 | 490 for (octave_idx_type j = 0; j < nc; j++) |
491 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 492 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
493 double val = m(i,j); |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
494 if (! xfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
495 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
496 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
497 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
498 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
499 if (val > result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
500 result = val; |
1 | 501 } |
3608 | 502 |
5748 | 503 if (all_inf_or_nan) |
504 result = 0.0; | |
505 | |
1 | 506 return result; |
507 } | |
508 | |
509 static double | |
164 | 510 pr_min_internal (const Matrix& m) |
1 | 511 { |
5275 | 512 octave_idx_type nr = m.rows (); |
513 octave_idx_type nc = m.columns (); | |
1 | 514 |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
515 double result = std::numeric_limits<double>::max (); |
1 | 516 |
5748 | 517 bool all_inf_or_nan = true; |
518 | |
5275 | 519 for (octave_idx_type j = 0; j < nc; j++) |
520 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 521 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
522 double val = m(i,j); |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
523 if (xfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
524 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
525 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
526 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
527 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
528 if (val < result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
529 result = val; |
1 | 530 } |
3608 | 531 |
5748 | 532 if (all_inf_or_nan) |
533 result = 0.0; | |
534 | |
1 | 535 return result; |
536 } | |
537 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
538 // FIXME: it would be nice to share more code among these functions,.. |
1658 | 539 |
1 | 540 static void |
6959 | 541 set_real_format (int digits, bool inf_or_nan, bool int_only, int &fw) |
1 | 542 { |
3608 | 543 static float_format fmt; |
1 | 544 |
2165 | 545 int prec = Voutput_precision; |
1 | 546 |
547 int ld, rd; | |
548 | |
6788 | 549 if (rat_format) |
550 { | |
551 fw = 0; | |
552 rd = 0; | |
553 } | |
554 else if (bank_format) | |
1 | 555 { |
556 fw = digits < 0 ? 4 : digits + 3; | |
5748 | 557 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
558 fw = 4; |
1 | 559 rd = 2; |
560 } | |
1282 | 561 else if (hex_format) |
562 { | |
563 fw = 2 * sizeof (double); | |
564 rd = 0; | |
565 } | |
1309 | 566 else if (bit_format) |
567 { | |
568 fw = 8 * sizeof (double); | |
569 rd = 0; | |
570 } | |
3611 | 571 else if (inf_or_nan || int_only) |
1 | 572 { |
5832 | 573 fw = 1 + digits; |
5748 | 574 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
575 fw = 4; |
3682 | 576 rd = fw; |
1 | 577 } |
578 else | |
579 { | |
580 if (digits > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
581 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
582 ld = digits; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
583 rd = prec > digits ? prec - digits : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
584 digits++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
585 } |
1 | 586 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
587 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
588 ld = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
589 rd = prec > digits ? prec - digits : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 digits = -digits + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
591 } |
1 | 592 |
5832 | 593 fw = 1 + ld + 1 + rd; |
5748 | 594 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
595 fw = 4; |
1 | 596 } |
597 | |
6788 | 598 if (! (rat_format || bank_format || hex_format || bit_format) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
599 && (fw > Voutput_max_field_width || print_e || print_g || print_eng)) |
1 | 600 { |
4509 | 601 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
602 fmt = float_format (); |
4509 | 603 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
604 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
605 // e+ddd |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
606 int ex = 5; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
607 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
608 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
609 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
610 // -ddd. |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
611 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
|
612 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
|
613 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
614 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
|
615 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
616 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
617 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
618 // -d. |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
619 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
|
620 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
|
621 fw = 4; |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
622 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
|
623 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
624 } |
3608 | 625 |
1 | 626 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
627 fmt.uppercase (); |
1 | 628 } |
5086 | 629 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 630 fmt = float_format (fw, rd); |
1 | 631 else |
3608 | 632 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 633 |
3608 | 634 curr_real_fmt = &fmt; |
1 | 635 } |
636 | |
1658 | 637 static void |
638 set_format (double d, int& fw) | |
639 { | |
640 curr_real_fmt = 0; | |
641 curr_imag_fmt = 0; | |
642 | |
643 if (free_format) | |
644 return; | |
645 | |
5389 | 646 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658 | 647 |
3611 | 648 bool int_only = (! inf_or_nan && D_NINT (d) == d); |
1658 | 649 |
650 double d_abs = d < 0.0 ? -d : d; | |
651 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 int digits = (inf_or_nan || d_abs == 0.0) ? 0 : num_digits (d_abs); |
1658 | 653 |
6959 | 654 set_real_format (digits, inf_or_nan, int_only, fw); |
1658 | 655 } |
656 | |
1 | 657 static inline void |
658 set_format (double d) | |
659 { | |
660 int fw; | |
661 set_format (d, fw); | |
662 } | |
663 | |
664 static void | |
6959 | 665 set_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
666 int int_or_inf_or_nan, int& fw) |
1 | 667 { |
3608 | 668 static float_format fmt; |
1 | 669 |
2165 | 670 int prec = Voutput_precision; |
1 | 671 |
672 int ld, rd; | |
673 | |
6788 | 674 if (rat_format) |
675 { | |
676 fw = 9; | |
677 rd = 0; | |
678 } | |
679 else if (bank_format) | |
1 | 680 { |
681 int digits = x_max > x_min ? x_max : x_min; | |
682 fw = digits <= 0 ? 4 : digits + 3; | |
5748 | 683 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
684 fw = 4; |
1 | 685 rd = 2; |
686 } | |
1282 | 687 else if (hex_format) |
688 { | |
689 fw = 2 * sizeof (double); | |
690 rd = 0; | |
691 } | |
1309 | 692 else if (bit_format) |
693 { | |
694 fw = 8 * sizeof (double); | |
695 rd = 0; | |
696 } | |
4509 | 697 else if (Vfixed_point_format && ! print_g) |
3268 | 698 { |
699 rd = prec; | |
700 fw = rd + 2; | |
5748 | 701 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
702 fw = 4; |
3268 | 703 } |
1715 | 704 else if (int_or_inf_or_nan) |
1 | 705 { |
706 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 707 fw = digits <= 0 ? 2 : digits + 1; |
5748 | 708 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
709 fw = 4; |
3682 | 710 rd = fw; |
1 | 711 } |
712 else | |
713 { | |
714 int ld_max, rd_max; | |
715 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
716 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
717 ld_max = x_max; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
718 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
719 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
720 } |
1 | 721 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
723 ld_max = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
724 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
725 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
726 } |
1 | 727 |
728 int ld_min, rd_min; | |
729 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
730 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
731 ld_min = x_min; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
732 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
733 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
734 } |
1 | 735 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
736 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
737 ld_min = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
738 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
739 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
740 } |
1 | 741 |
742 ld = ld_max > ld_min ? ld_max : ld_min; | |
743 rd = rd_max > rd_min ? rd_max : rd_min; | |
744 | |
5832 | 745 fw = 1 + ld + 1 + rd; |
5748 | 746 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
747 fw = 4; |
1 | 748 } |
749 | |
6788 | 750 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 751 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
752 || print_eng || print_g |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 754 { |
4509 | 755 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
756 fmt = float_format (); |
4509 | 757 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
758 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
759 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
760 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
|
761 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
762 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
763 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
764 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
765 fw = 4 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
766 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
|
767 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
768 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
|
769 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
770 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
771 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
772 fw = 2 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
773 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
|
774 fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
775 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
|
776 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
777 } |
3608 | 778 |
1 | 779 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
780 fmt.uppercase (); |
1 | 781 } |
5086 | 782 else if (! bank_format && int_or_inf_or_nan) |
3611 | 783 fmt = float_format (fw, rd); |
1 | 784 else |
3608 | 785 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 786 |
3608 | 787 curr_real_fmt = &fmt; |
1 | 788 } |
789 | |
1658 | 790 static void |
3105 | 791 set_format (const Matrix& m, int& fw, double& scale) |
1658 | 792 { |
793 curr_real_fmt = 0; | |
794 curr_imag_fmt = 0; | |
795 | |
796 if (free_format) | |
797 return; | |
798 | |
2387 | 799 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 800 |
2387 | 801 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 802 |
2387 | 803 Matrix m_abs = m.abs (); |
1658 | 804 double max_abs = pr_max_internal (m_abs); |
805 double min_abs = pr_min_internal (m_abs); | |
806 | |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
807 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
808 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
809 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
810 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
811 scale = (x_max == 0 || int_or_inf_or_nan) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
812 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 813 |
6959 | 814 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw); |
1658 | 815 } |
816 | |
1 | 817 static inline void |
164 | 818 set_format (const Matrix& m) |
1 | 819 { |
820 int fw; | |
3105 | 821 double scale; |
822 set_format (m, fw, scale); | |
1 | 823 } |
824 | |
825 static void | |
6959 | 826 set_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
827 int int_only, int& r_fw, int& i_fw) |
1 | 828 { |
3608 | 829 static float_format r_fmt; |
830 static float_format i_fmt; | |
1 | 831 |
2165 | 832 int prec = Voutput_precision; |
1 | 833 |
834 int ld, rd; | |
835 | |
6788 | 836 if (rat_format) |
837 { | |
838 i_fw = 0; | |
839 r_fw = 0; | |
840 rd = 0; | |
841 } | |
842 else if (bank_format) | |
1 | 843 { |
844 int digits = r_x; | |
845 i_fw = 0; | |
846 r_fw = digits <= 0 ? 4 : digits + 3; | |
5748 | 847 if (inf_or_nan && r_fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
848 r_fw = 4; |
1 | 849 rd = 2; |
850 } | |
1282 | 851 else if (hex_format) |
852 { | |
853 r_fw = 2 * sizeof (double); | |
854 i_fw = 2 * sizeof (double); | |
855 rd = 0; | |
856 } | |
1309 | 857 else if (bit_format) |
858 { | |
859 r_fw = 8 * sizeof (double); | |
860 i_fw = 8 * sizeof (double); | |
861 rd = 0; | |
862 } | |
1658 | 863 else if (inf_or_nan || int_only) |
1 | 864 { |
865 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 866 i_fw = digits <= 0 ? 1 : digits; |
867 r_fw = i_fw + 1; | |
868 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
869 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
870 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
871 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
872 } |
3682 | 873 rd = r_fw; |
1 | 874 } |
875 else | |
876 { | |
877 int ld_max, rd_max; | |
878 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
879 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
880 ld_max = x_max; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
881 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
882 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
883 } |
1 | 884 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
885 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
886 ld_max = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
887 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
888 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
889 } |
1 | 890 |
891 int ld_min, rd_min; | |
892 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
894 ld_min = x_min; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
895 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
896 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
897 } |
1 | 898 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
900 ld_min = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
901 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
902 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
903 } |
1 | 904 |
905 ld = ld_max > ld_min ? ld_max : ld_min; | |
906 rd = rd_max > rd_min ? rd_max : rd_min; | |
907 | |
5945 | 908 i_fw = ld + 1 + rd; |
909 r_fw = i_fw + 1; | |
910 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
911 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
912 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
913 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
914 } |
1 | 915 } |
916 | |
6788 | 917 if (! (rat_format || bank_format || hex_format || bit_format) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
918 && (r_fw > Voutput_max_field_width || print_e || print_eng || print_g)) |
1 | 919 { |
4509 | 920 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
921 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
922 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
923 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
924 } |
4509 | 925 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
926 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
927 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
928 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
|
929 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
930 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
931 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
932 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
933 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
|
934 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
|
935 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
|
936 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
937 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
938 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
939 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
940 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
|
941 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
|
942 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
943 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
944 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
945 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
|
946 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
|
947 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
|
948 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
949 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
950 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
951 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
952 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
|
953 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
|
954 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
955 } |
3608 | 956 |
1 | 957 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
958 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
959 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
960 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
961 } |
1 | 962 } |
5086 | 963 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 964 { |
965 r_fmt = float_format (r_fw, rd); | |
966 i_fmt = float_format (i_fw, rd); | |
967 } | |
1 | 968 else |
969 { | |
3608 | 970 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
971 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 972 } |
973 | |
3608 | 974 curr_real_fmt = &r_fmt; |
975 curr_imag_fmt = &i_fmt; | |
1 | 976 } |
977 | |
1658 | 978 static void |
979 set_format (const Complex& c, int& r_fw, int& i_fw) | |
980 { | |
981 curr_real_fmt = 0; | |
982 curr_imag_fmt = 0; | |
983 | |
984 if (free_format) | |
985 return; | |
986 | |
987 double rp = c.real (); | |
988 double ip = c.imag (); | |
989 | |
2387 | 990 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658 | 991 |
2387 | 992 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658 | 993 |
994 double r_abs = rp < 0.0 ? -rp : rp; | |
995 double i_abs = ip < 0.0 ? -ip : ip; | |
996 | |
16971
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
997 int r_x = (! xfinite (rp) || r_abs == 0.0) ? 0 : num_digits (r_abs); |
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
998 |
259c1f295a1e
Use xfinite to replace some (isinf || isnan) instances in C++ code.
Rik <rik@octave.org>
parents:
16892
diff
changeset
|
999 int i_x = (! xfinite (ip) || i_abs == 0.0) ? 0 : num_digits (i_abs); |
1658 | 1000 |
1001 int x_max, x_min; | |
1002 | |
1003 if (r_x > i_x) | |
1004 { | |
1005 x_max = r_x; | |
1006 x_min = i_x; | |
1007 } | |
1008 else | |
1009 { | |
1010 x_max = i_x; | |
1011 x_min = r_x; | |
1012 } | |
1013 | |
6959 | 1014 set_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, r_fw, i_fw); |
1658 | 1015 } |
1016 | |
1 | 1017 static inline void |
164 | 1018 set_format (const Complex& c) |
1 | 1019 { |
1020 int r_fw, i_fw; | |
1021 set_format (c, r_fw, i_fw); | |
1022 } | |
1023 | |
1024 static void | |
6959 | 1025 set_complex_matrix_format (int x_max, int x_min, int r_x_max, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1026 int r_x_min, bool inf_or_nan, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1 | 1028 { |
3608 | 1029 static float_format r_fmt; |
1030 static float_format i_fmt; | |
1 | 1031 |
2165 | 1032 int prec = Voutput_precision; |
1 | 1033 |
1034 int ld, rd; | |
1035 | |
6788 | 1036 if (rat_format) |
1037 { | |
1038 i_fw = 9; | |
1039 r_fw = 9; | |
1040 rd = 0; | |
1041 } | |
1042 else if (bank_format) | |
1 | 1043 { |
1044 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; | |
1045 i_fw = 0; | |
1046 r_fw = digits <= 0 ? 4 : digits + 3; | |
5945 | 1047 if (inf_or_nan && r_fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1048 r_fw = 4; |
1 | 1049 rd = 2; |
1050 } | |
1282 | 1051 else if (hex_format) |
1052 { | |
1053 r_fw = 2 * sizeof (double); | |
1054 i_fw = 2 * sizeof (double); | |
1055 rd = 0; | |
1056 } | |
1309 | 1057 else if (bit_format) |
1058 { | |
1059 r_fw = 8 * sizeof (double); | |
1060 i_fw = 8 * sizeof (double); | |
1061 rd = 0; | |
1062 } | |
4509 | 1063 else if (Vfixed_point_format && ! print_g) |
3268 | 1064 { |
1065 rd = prec; | |
5945 | 1066 i_fw = rd + 1; |
1067 r_fw = i_fw + 1; | |
1068 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1069 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1070 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1071 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1072 } |
3268 | 1073 } |
1715 | 1074 else if (int_or_inf_or_nan) |
1 | 1075 { |
1076 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 1077 i_fw = digits <= 0 ? 1 : digits; |
1078 r_fw = i_fw + 1; | |
1079 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1080 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1081 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1082 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1083 } |
3682 | 1084 rd = r_fw; |
1 | 1085 } |
1086 else | |
1087 { | |
1088 int ld_max, rd_max; | |
1089 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1090 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1091 ld_max = x_max; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1092 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1093 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1094 } |
1 | 1095 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1096 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1097 ld_max = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1098 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1099 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1100 } |
1 | 1101 |
1102 int ld_min, rd_min; | |
1103 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1104 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1105 ld_min = x_min; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1106 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1107 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1108 } |
1 | 1109 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1110 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1111 ld_min = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1112 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1113 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1114 } |
1 | 1115 |
1116 ld = ld_max > ld_min ? ld_max : ld_min; | |
1117 rd = rd_max > rd_min ? rd_max : rd_min; | |
1118 | |
5945 | 1119 i_fw = ld + 1 + rd; |
1120 r_fw = i_fw + 1; | |
1121 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1122 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1123 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1124 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1125 } |
1 | 1126 } |
1127 | |
6788 | 1128 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1129 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1130 || print_eng || print_g |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1131 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1 | 1132 { |
4509 | 1133 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1134 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1135 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1136 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1137 } |
4509 | 1138 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1139 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1140 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1141 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
|
1142 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1143 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1144 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1145 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1146 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
|
1147 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
|
1148 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
|
1149 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1150 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1151 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1152 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1153 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
|
1154 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
|
1155 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1156 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1157 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1158 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
|
1159 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
|
1160 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
|
1161 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1162 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1163 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1164 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1165 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
|
1166 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
|
1167 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1168 } |
3608 | 1169 |
1 | 1170 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1171 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1172 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1173 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1174 } |
1 | 1175 } |
5086 | 1176 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1177 { |
1178 r_fmt = float_format (r_fw, rd); | |
1179 i_fmt = float_format (i_fw, rd); | |
1180 } | |
1 | 1181 else |
1182 { | |
3608 | 1183 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1184 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1185 } |
1186 | |
3608 | 1187 curr_real_fmt = &r_fmt; |
1188 curr_imag_fmt = &i_fmt; | |
1 | 1189 } |
1190 | |
1658 | 1191 static void |
3105 | 1192 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658 | 1193 { |
1194 curr_real_fmt = 0; | |
1195 curr_imag_fmt = 0; | |
1196 | |
1197 if (free_format) | |
1198 return; | |
1199 | |
1200 Matrix rp = real (cm); | |
1201 Matrix ip = imag (cm); | |
1202 | |
2387 | 1203 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1204 |
2387 | 1205 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
|
1206 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658 | 1207 |
2387 | 1208 Matrix r_m_abs = rp.abs (); |
1658 | 1209 double r_max_abs = pr_max_internal (r_m_abs); |
1210 double r_min_abs = pr_min_internal (r_m_abs); | |
1211 | |
2387 | 1212 Matrix i_m_abs = ip.abs (); |
1658 | 1213 double i_max_abs = pr_max_internal (i_m_abs); |
1214 double i_min_abs = pr_min_internal (i_m_abs); | |
1215 | |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1216 int r_x_max = r_max_abs == 0.0 ? 0 : num_digits (r_max_abs); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1217 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1218 int r_x_min = r_min_abs == 0.0 ? 0 : num_digits (r_min_abs); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1219 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1220 int i_x_max = i_max_abs == 0.0 ? 0 : num_digits (i_max_abs); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1221 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1222 int i_x_min = i_min_abs == 0.0 ? 0 : num_digits (i_min_abs); |
1658 | 1223 |
1224 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; | |
1225 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; | |
1226 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1227 scale = (x_max == 0 || int_or_inf_or_nan) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1228 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 1229 |
6959 | 1230 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1231 int_or_inf_or_nan, r_fw, i_fw); |
1658 | 1232 } |
1233 | |
1 | 1234 static inline void |
164 | 1235 set_format (const ComplexMatrix& cm) |
1 | 1236 { |
1237 int r_fw, i_fw; | |
3105 | 1238 double scale; |
1239 set_format (cm, r_fw, i_fw, scale); | |
1 | 1240 } |
1241 | |
1242 static void | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1243 set_range_format (int x_max, int x_min, int all_ints, int& fw) |
1 | 1244 { |
3608 | 1245 static float_format fmt; |
1 | 1246 |
2165 | 1247 int prec = Voutput_precision; |
1 | 1248 |
1249 int ld, rd; | |
1250 | |
6788 | 1251 if (rat_format) |
1252 { | |
1253 fw = 9; | |
1254 rd = 0; | |
1255 } | |
1256 else if (bank_format) | |
1 | 1257 { |
1258 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
|
1259 fw = digits < 0 ? 5 : digits + 4; |
1 | 1260 rd = 2; |
1261 } | |
1282 | 1262 else if (hex_format) |
1263 { | |
1264 fw = 2 * sizeof (double); | |
1265 rd = 0; | |
1266 } | |
1309 | 1267 else if (bit_format) |
1268 { | |
1269 fw = 8 * sizeof (double); | |
1270 rd = 0; | |
1271 } | |
1658 | 1272 else if (all_ints) |
1 | 1273 { |
1274 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
|
1275 fw = digits + 1; |
3682 | 1276 rd = fw; |
1 | 1277 } |
4509 | 1278 else if (Vfixed_point_format && ! print_g) |
3105 | 1279 { |
1280 rd = prec; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1281 fw = rd + 3; |
3105 | 1282 } |
1 | 1283 else |
1284 { | |
1285 int ld_max, rd_max; | |
1286 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1287 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1288 ld_max = x_max; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1289 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1290 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1291 } |
1 | 1292 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1293 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1294 ld_max = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1295 rd_max = prec > x_max ? prec - x_max : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1296 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1297 } |
1 | 1298 |
1299 int ld_min, rd_min; | |
1300 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1301 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1302 ld_min = x_min; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1303 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1304 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1305 } |
1 | 1306 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1308 ld_min = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1309 rd_min = prec > x_min ? prec - x_min : prec; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1310 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1311 } |
1 | 1312 |
1313 ld = ld_max > ld_min ? ld_max : ld_min; | |
1314 rd = rd_max > rd_min ? rd_max : rd_min; | |
1315 | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1316 fw = ld + rd + 3; |
1 | 1317 } |
1318 | |
6788 | 1319 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1320 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1321 || print_eng || print_g |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1322 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 1323 { |
4509 | 1324 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1325 fmt = float_format (); |
4509 | 1326 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1327 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1328 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1329 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
|
1330 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1331 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1332 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1333 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1334 fw = 5 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1335 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
|
1336 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1337 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1338 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1339 fw = 3 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1340 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
|
1341 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1342 } |
3608 | 1343 |
1 | 1344 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1345 fmt.uppercase (); |
1 | 1346 } |
5086 | 1347 else if (! bank_format && all_ints) |
3611 | 1348 fmt = float_format (fw, rd); |
1 | 1349 else |
3608 | 1350 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1351 |
3608 | 1352 curr_real_fmt = &fmt; |
1 | 1353 } |
1354 | |
1658 | 1355 static void |
3105 | 1356 set_format (const Range& r, int& fw, double& scale) |
1658 | 1357 { |
1358 curr_real_fmt = 0; | |
1359 curr_imag_fmt = 0; | |
1360 | |
1361 if (free_format) | |
1362 return; | |
1363 | |
1364 double r_min = r.base (); | |
1365 double r_max = r.limit (); | |
1366 | |
1367 if (r_max < r_min) | |
1368 { | |
1369 double tmp = r_max; | |
1370 r_max = r_min; | |
1371 r_min = tmp; | |
1372 } | |
1373 | |
2387 | 1374 bool all_ints = r.all_elements_are_ints (); |
1658 | 1375 |
1376 double max_abs = r_max < 0.0 ? -r_max : r_max; | |
1377 double min_abs = r_min < 0.0 ? -r_min : r_min; | |
1378 | |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1379 int x_max = max_abs == 0.0 ? 0 : num_digits (max_abs); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1380 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
1381 int x_min = min_abs == 0.0 ? 0 : num_digits (min_abs); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1382 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1383 scale = (x_max == 0 || all_ints) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1384 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 1385 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1386 set_range_format (x_max, x_min, all_ints, fw); |
1658 | 1387 } |
1388 | |
1 | 1389 static inline void |
164 | 1390 set_format (const Range& r) |
1 | 1391 { |
1392 int fw; | |
3105 | 1393 double scale; |
1394 set_format (r, fw, scale); | |
1 | 1395 } |
1396 | |
1282 | 1397 union equiv |
1398 { | |
1399 double d; | |
1400 unsigned char i[sizeof (double)]; | |
1401 }; | |
1402 | |
1309 | 1403 #define PRINT_CHAR_BITS(os, c) \ |
1404 do \ | |
1405 { \ | |
1406 unsigned char ctmp = c; \ | |
1407 char stmp[9]; \ | |
1488 | 1408 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
1409 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ | |
1410 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ | |
1411 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ | |
1412 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ | |
1413 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ | |
1414 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ | |
1415 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ | |
1309 | 1416 stmp[8] = '\0'; \ |
3013 | 1417 os << stmp; \ |
1309 | 1418 } \ |
1419 while (0) | |
1420 | |
1421 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ | |
1422 do \ | |
1423 { \ | |
1424 unsigned char ctmp = c; \ | |
1425 char stmp[9]; \ | |
1488 | 1426 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
1427 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ | |
1428 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ | |
1429 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ | |
1430 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ | |
1431 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ | |
1432 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ | |
1433 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ | |
1309 | 1434 stmp[8] = '\0'; \ |
3013 | 1435 os << stmp; \ |
1309 | 1436 } \ |
1437 while (0) | |
1438 | |
2522 | 1439 static void |
3608 | 1440 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0) |
1 | 1441 { |
529 | 1442 if (fmt) |
1 | 1443 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1444 // Unless explicitly asked for, always print in big-endian format |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1445 // for hex and bit formats. |
5544 | 1446 // |
1447 // {bit,hex}_format == 1: print big-endian | |
1448 // {bit,hex}_format == 2: print native | |
1449 | |
1282 | 1450 if (hex_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1451 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1452 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1453 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1454 equiv tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1455 tmp.d = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1456 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1457 // Unless explicitly asked for, always print in big-endian format. |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1458 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1459 // FIXME: will bad things happen if we are |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1460 // interrupted before resetting the format flags and fill |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1461 // character? |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1462 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1463 oct_mach_info::float_format flt_fmt = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1464 oct_mach_info::native_float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1465 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1466 os.fill ('0'); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1467 os.flags (std::ios::right | std::ios::hex); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1468 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1469 if (hex_format > 1 |
17415
3856298f1ff8
eliminate unimplemented vax and cray floating point formats
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1470 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1471 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1472 for (size_t i = 0; i < sizeof (double); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1473 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1474 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1475 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1476 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1477 for (int i = sizeof (double) - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1478 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1479 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1480 } |
1309 | 1481 else if (bit_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1482 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1483 equiv tmp; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1484 tmp.d = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1485 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1486 oct_mach_info::float_format flt_fmt = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1487 oct_mach_info::native_float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1488 |
17415
3856298f1ff8
eliminate unimplemented vax and cray floating point formats
John W. Eaton <jwe@octave.org>
parents:
17281
diff
changeset
|
1489 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1490 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1491 for (size_t i = 0; i < sizeof (double); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1492 PRINT_CHAR_BITS (os, tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1493 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1494 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1495 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1496 if (bit_format > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1497 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1498 for (size_t i = 0; i < sizeof (double); i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1499 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1500 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1501 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1502 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1503 for (int i = sizeof (double) - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1504 PRINT_CHAR_BITS (os, tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1505 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1506 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1507 } |
6788 | 1508 else if (octave_is_NA (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1509 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1510 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1511 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1512 if (fw > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1513 os << std::setw (fw) << "NA"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1514 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1515 os << "NA"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1516 } |
6788 | 1517 else if (rat_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1518 os << pr_rational_float (*fmt, d); |
1282 | 1519 else if (xisinf (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1520 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1521 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1522 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1523 const char *s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1524 if (d < 0.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1525 s = "-Inf"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1526 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1527 s = "Inf"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1528 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1529 if (fw > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1530 os << std::setw (fw) << s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1531 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1532 os << s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1533 } |
1 | 1534 else if (xisnan (d)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1535 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1536 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1537 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1538 if (fw > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1539 os << std::setw (fw) << "NaN"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1540 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1541 os << "NaN"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1542 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1543 else if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1544 os << pr_engineering_float (*fmt, d); |
1 | 1545 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1546 os << pr_formatted_float (*fmt, d); |
1 | 1547 } |
529 | 1548 else |
1549 os << d; | |
1 | 1550 } |
1551 | |
1552 static inline void | |
3608 | 1553 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
1 | 1554 { |
4509 | 1555 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608 | 1556 d /= scale; |
1557 | |
1 | 1558 pr_any_float (curr_real_fmt, os, d, fw); |
1559 } | |
1560 | |
1561 static inline void | |
3523 | 1562 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1 | 1563 { |
1564 pr_any_float (curr_imag_fmt, os, d, fw); | |
1565 } | |
1566 | |
2522 | 1567 static void |
3608 | 1568 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1569 int i_fw = 0, double scale = 1.0) |
1 | 1570 { |
4509 | 1571 Complex tmp |
1572 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; | |
3608 | 1573 |
1574 double r = tmp.real (); | |
1575 | |
1 | 1576 pr_float (os, r, r_fw); |
3608 | 1577 |
1 | 1578 if (! bank_format) |
1579 { | |
3608 | 1580 double i = tmp.imag (); |
4349 | 1581 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
|
1582 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1583 os << " - "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1584 i = -i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1585 pr_imag_float (os, i, i_fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1586 } |
1 | 1587 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1588 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1589 if (hex_format || bit_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1590 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1591 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1592 os << " + "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1593 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1594 pr_imag_float (os, i, i_fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1595 } |
1 | 1596 os << "i"; |
1597 } | |
1598 } | |
1599 | |
626 | 1600 static void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1601 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
|
1602 bool pr_as_read_syntax) |
626 | 1603 { |
1604 assert (nr == 0 || nc == 0); | |
1605 | |
1606 if (pr_as_read_syntax) | |
1607 { | |
1608 if (nr == 0 && nc == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1609 os << "[]"; |
626 | 1610 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1611 os << "zeros (" << nr << ", " << nc << ")"; |
626 | 1612 } |
1613 else | |
1614 { | |
1615 os << "[]"; | |
4559 | 1616 |
2165 | 1617 if (Vprint_empty_dimensions) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1618 os << "(" << nr << "x" << nc << ")"; |
626 | 1619 } |
1620 } | |
1621 | |
1186 | 1622 static void |
4559 | 1623 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
|
1624 bool pr_as_read_syntax) |
4559 | 1625 { |
1626 assert (dims.any_zero ()); | |
1627 | |
1628 if (pr_as_read_syntax) | |
1629 os << "zeros (" << dims.str (',') << ")"; | |
1630 else | |
1631 { | |
1632 os << "[]"; | |
1633 | |
1634 if (Vprint_empty_dimensions) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1635 os << "(" << dims.str () << ")"; |
4559 | 1636 } |
1637 } | |
1638 | |
1639 static void | |
3523 | 1640 pr_scale_header (std::ostream& os, double scale) |
3105 | 1641 { |
4509 | 1642 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105 | 1643 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1644 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1645 |
3568 | 1646 os << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1647 << std::setw (8) << std::setprecision (1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1648 << std::setiosflags (std::ios::scientific|std::ios::left) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1649 << scale |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1650 << " *\n"; |
3105 | 1651 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1652 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1653 os << "\n"; |
3105 | 1654 } |
1655 } | |
1656 | |
1657 static void | |
5275 | 1658 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
|
1659 octave_idx_type lim, octave_idx_type col, int extra_indent) |
1186 | 1660 { |
2165 | 1661 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1662 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1663 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1664 |
4833 | 1665 if (col != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1666 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1667 if (Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1668 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1669 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1670 os << "\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1671 } |
1186 | 1672 |
5275 | 1673 octave_idx_type num_cols = lim - col; |
1186 | 1674 |
3548 | 1675 os << std::setw (extra_indent) << ""; |
1972 | 1676 |
1186 | 1677 if (num_cols == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1678 os << " Column " << col + 1 << ":\n"; |
1186 | 1679 else if (num_cols == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1680 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
1186 | 1681 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1682 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915 | 1683 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1684 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1685 os << "\n"; |
1186 | 1686 } |
1687 } | |
1688 | |
5030 | 1689 template <class T> |
6018 | 1690 /* static */ inline void |
5030 | 1691 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1692 { |
5030 | 1693 if (val > T (0)) |
4632 | 1694 os << plus_format_chars[0]; |
5030 | 1695 else if (val < T (0)) |
4632 | 1696 os << plus_format_chars[1]; |
3248 | 1697 else |
4632 | 1698 os << plus_format_chars[2]; |
3248 | 1699 } |
1700 | |
1 | 1701 void |
4661 | 1702 octave_print_internal (std::ostream& os, double d, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1703 bool /* pr_as_read_syntax */) |
1 | 1704 { |
1705 if (plus_format) | |
1706 { | |
3608 | 1707 pr_plus_format (os, d); |
1 | 1708 } |
1709 else | |
1710 { | |
1711 set_format (d); | |
1712 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1713 os << d; |
1 | 1714 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1715 pr_float (os, d); |
1 | 1716 } |
1717 } | |
1718 | |
1719 void | |
3608 | 1720 octave_print_internal (std::ostream& os, const Matrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1721 bool pr_as_read_syntax, int extra_indent) |
1 | 1722 { |
5275 | 1723 octave_idx_type nr = m.rows (); |
1724 octave_idx_type nc = m.columns (); | |
1 | 1725 |
2408 | 1726 if (nr == 0 || nc == 0) |
626 | 1727 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1728 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1729 { |
5275 | 1730 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1731 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1732 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1733 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1734 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1735 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1736 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1737 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1738 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1739 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1740 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1741 } |
1 | 1742 } |
1743 else | |
1744 { | |
1745 int fw; | |
3105 | 1746 double scale = 1.0; |
1747 set_format (m, fw, scale); | |
1 | 1748 int column_width = fw + 2; |
5275 | 1749 octave_idx_type total_width = nc * column_width; |
1750 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 1751 |
626 | 1752 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1753 max_width -= 4; |
1972 | 1754 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1755 max_width -= extra_indent; |
1972 | 1756 |
1757 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1758 max_width = 0; |
626 | 1759 |
1 | 1760 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1761 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1762 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1763 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1764 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1765 os << m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1766 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1767 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1768 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1769 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1770 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1771 } |
1 | 1772 |
5275 | 1773 octave_idx_type inc = nc; |
2165 | 1774 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
|
1775 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1776 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1777 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1778 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1779 } |
1 | 1780 |
626 | 1781 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1782 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1783 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
|
1784 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1785 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1786 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1787 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1788 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1789 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1790 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
|
1791 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1792 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1793 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1794 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1795 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1796 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1797 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1798 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1799 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1800 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1801 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1802 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1803 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1804 pr_float (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1805 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1806 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1807 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1808 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1809 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1810 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1811 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1812 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1813 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1814 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1815 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1816 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1817 os << " ...\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1818 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1819 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1820 } |
626 | 1821 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1822 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1823 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1824 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1825 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1826 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1827 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
|
1828 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1829 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1830 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1831 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
|
1832 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1833 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1834 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
|
1835 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1836 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1837 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1838 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
|
1839 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1840 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1841 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1842 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1843 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1844 pr_float (os, m(i,j), fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1845 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1846 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1847 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1848 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1849 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1850 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1851 } |
1 | 1852 } |
1853 } | |
1854 | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1855 void |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1856 octave_print_internal (std::ostream& os, const DiagMatrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1857 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1858 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1859 octave_idx_type nr = m.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1860 octave_idx_type nc = m.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1861 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1862 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1863 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
|
1864 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1865 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1866 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1867 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1868 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1869 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1870 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1871 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1872 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1873 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1874 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1875 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1876 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1877 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1878 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1879 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1880 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1881 int fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1882 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1883 set_format (Matrix (m.diag ()), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1884 int column_width = fw + 2; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1885 octave_idx_type total_width = nc * column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1886 octave_idx_type max_width = command_editor::terminal_cols (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1887 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1888 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1889 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1890 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1891 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1892 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1893 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1894 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1895 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1896 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1897 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1898 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1899 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1900 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1901 os << Matrix (m); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1902 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1903 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1904 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1905 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1906 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1907 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1908 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1909 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1910 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
|
1911 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1912 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1913 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1914 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1915 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1916 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1917 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1918 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1919 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1920 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1921 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1922 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1923 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1924 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1925 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1926 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1927 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
1928 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1929 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1930 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1931 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1932 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1933 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1934 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1935 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1936 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1937 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1938 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1939 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1940 pr_float (os, m(j,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1941 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1942 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1943 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1944 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1945 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1946 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1947 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1948 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1949 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1950 os << ")"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1951 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1952 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1953 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1954 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1955 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1956 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1957 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1958 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1959 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1960 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1961 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1962 // kluge. Get the true width of a number. |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1963 int zero_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1964 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1965 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1966 std::ostringstream tmp_oss; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1967 pr_float (tmp_oss, 0.0, fw, scale); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1968 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1969 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1970 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1971 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
|
1972 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1973 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1974 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1975 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
|
1976 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1977 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1978 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
|
1979 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1980 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1981 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1982 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
|
1983 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1984 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1985 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1986 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1987 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1988 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1989 pr_float (os, m(i,j), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1990 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1991 os << std::setw (zero_fw) << '0'; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1992 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1993 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1996 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1997 } |
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 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2000 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2001 } |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2002 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2003 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
|
2004 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
|
2005 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
|
2006 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2007 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2008 if (nda.is_empty ()) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2009 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
|
2010 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2011 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2012 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2013 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
|
2014 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2015 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
|
2016 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2017 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
|
2018 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2019 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
|
2020 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2021 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
|
2022 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
|
2023 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2024 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
|
2025 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
|
2026 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2027 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
|
2028 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2029 octave_quit (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2030 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2031 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
|
2032 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2033 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
|
2034 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2035 nm += "(:,:,"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2036 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2037 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
|
2038 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2039 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
|
2040 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2041 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
|
2042 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2043 if (k < ndims - 1) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2044 buf << ","; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2045 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2046 buf << ")"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2047 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2048 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2049 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
|
2050 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2051 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2052 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
|
2053 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2054 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
|
2055 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
|
2056 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2057 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
|
2058 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
|
2059 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2060 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
|
2061 = 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
|
2062 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2063 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
|
2064 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2065 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
|
2066 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2067 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2068 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2069 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
|
2070 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
|
2071 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2072 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2073 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
|
2074 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
|
2075 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2076 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2077 } |
4532 | 2078 |
4513 | 2079 void |
2080 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
|
2081 bool pr_as_read_syntax, int extra_indent) |
4513 | 2082 { |
2083 switch (nda.ndims ()) | |
2084 { | |
2085 case 1: | |
2086 case 2: | |
2087 octave_print_internal (os, nda.matrix_value (), | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2088 pr_as_read_syntax, extra_indent); |
4513 | 2089 break; |
2090 | |
2091 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2092 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax); |
4513 | 2093 break; |
2094 } | |
2095 } | |
2096 | |
5030 | 2097 template <> |
6018 | 2098 /* static */ inline void |
6015 | 2099 pr_plus_format<> (std::ostream& os, const Complex& c) |
3248 | 2100 { |
2101 double rp = c.real (); | |
2102 double ip = c.imag (); | |
2103 | |
2104 if (rp == 0.0) | |
2105 { | |
2106 if (ip == 0.0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2107 os << " "; |
3248 | 2108 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2109 os << "i"; |
3248 | 2110 } |
2111 else if (ip == 0.0) | |
3608 | 2112 pr_plus_format (os, rp); |
3248 | 2113 else |
2114 os << "c"; | |
2115 } | |
2116 | |
1 | 2117 void |
3523 | 2118 octave_print_internal (std::ostream& os, const Complex& c, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2119 bool /* pr_as_read_syntax */) |
1 | 2120 { |
2121 if (plus_format) | |
2122 { | |
3608 | 2123 pr_plus_format (os, c); |
1 | 2124 } |
2125 else | |
2126 { | |
2127 set_format (c); | |
2128 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2129 os << c; |
1 | 2130 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2131 pr_complex (os, c); |
1 | 2132 } |
2133 } | |
2134 | |
2135 void | |
3523 | 2136 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
|
2137 bool pr_as_read_syntax, int extra_indent) |
1 | 2138 { |
5275 | 2139 octave_idx_type nr = cm.rows (); |
2140 octave_idx_type nc = cm.columns (); | |
1 | 2141 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2142 if (nr == 0 || nc == 0) |
626 | 2143 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2144 else if (plus_format && ! pr_as_read_syntax) | |
1 | 2145 { |
5275 | 2146 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2147 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2148 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2149 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2150 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2151 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2152 pr_plus_format (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2153 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2154 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2155 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2156 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2157 } |
1 | 2158 } |
2159 else | |
2160 { | |
2161 int r_fw, i_fw; | |
3105 | 2162 double scale = 1.0; |
2163 set_format (cm, r_fw, i_fw, scale); | |
1 | 2164 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
|
2165 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
|
2166 || bit_format) ? 2 : 7; |
5275 | 2167 octave_idx_type total_width = nc * column_width; |
2168 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 2169 |
626 | 2170 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2171 max_width -= 4; |
1972 | 2172 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2173 max_width -= extra_indent; |
1972 | 2174 |
2175 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2176 max_width = 0; |
626 | 2177 |
1 | 2178 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2179 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2180 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2181 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2182 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2183 os << cm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2184 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2185 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2186 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2187 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2188 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2189 } |
1 | 2190 |
5275 | 2191 octave_idx_type inc = nc; |
2165 | 2192 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
|
2193 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2194 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2195 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2196 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2197 } |
1 | 2198 |
626 | 2199 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2201 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
|
2202 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2203 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2204 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2205 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2206 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2207 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2208 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
|
2209 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2210 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2211 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2212 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2213 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2214 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2215 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2216 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2217 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2218 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2219 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2220 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2221 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2222 pr_complex (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2223 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2224 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2225 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2226 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2227 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2228 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2229 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2230 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2231 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2232 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2233 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2234 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2235 os << " ...\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2236 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2237 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2238 } |
626 | 2239 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2240 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2241 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2242 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2243 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2244 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2245 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
|
2246 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2247 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2248 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2249 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
|
2250 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2251 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2252 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
|
2253 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2254 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2255 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2256 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
|
2257 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2258 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2259 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2260 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2261 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2262 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2263 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2264 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2265 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2266 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2267 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2268 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2269 } |
1 | 2270 } |
2271 } | |
2272 | |
2273 void | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2274 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2275 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2276 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2277 octave_idx_type nr = cm.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2278 octave_idx_type nc = cm.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2279 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2280 if (nr == 0 || nc == 0) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2281 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
|
2282 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2283 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2284 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2285 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2286 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2287 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2288 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2289 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2290 pr_plus_format (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2291 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2292 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2293 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2294 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2295 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2296 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2297 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2298 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2299 int r_fw, i_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2300 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2301 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2302 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
|
2303 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
|
2304 || bit_format) ? 2 : 7; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2305 octave_idx_type total_width = nc * column_width; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2306 octave_idx_type max_width = command_editor::terminal_cols (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2307 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2308 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2309 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2310 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2311 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2312 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2313 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2314 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2315 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2316 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2317 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2318 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2319 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2320 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2321 os << ComplexMatrix (cm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2322 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2323 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2324 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2325 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2326 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2327 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2328 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2329 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2330 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
|
2331 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2332 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2333 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2334 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2335 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2336 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2337 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2338 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2339 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2340 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2341 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2342 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2343 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2344 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2345 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2346 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2347 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2348 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2349 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2350 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2351 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2352 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2353 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2354 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2355 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2356 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2357 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2358 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2359 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2360 pr_complex (os, cm(j,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2361 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2362 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2363 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2364 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2365 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2366 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2367 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2368 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2369 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2370 os << ")"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2371 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2372 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2373 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2374 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2375 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2376 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2377 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2378 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2379 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2380 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2381 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2382 // kluge. Get the true width of a number. |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2383 int zero_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2384 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2385 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2386 std::ostringstream tmp_oss; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2387 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2388 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2389 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2390 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2391 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
|
2392 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2393 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2394 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2395 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
|
2396 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2397 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2398 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
|
2399 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2400 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2401 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2402 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
|
2403 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2404 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2405 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2406 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2407 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2408 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2409 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2410 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2411 os << std::setw (zero_fw) << '0'; |
10315
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 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2414 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2415 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2416 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2417 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2418 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2419 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2420 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2421 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2422 void |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2423 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
|
2424 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
|
2425 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2426 octave_idx_type nr = m.rows (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2427 octave_idx_type nc = m.columns (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2428 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2429 if (nr == 0 || nc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2430 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
|
2431 else if (plus_format && ! pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2432 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2433 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2434 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2435 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2436 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2437 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2438 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2439 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2440 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2441 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2442 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2443 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2444 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2445 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2446 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2447 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2448 int fw = 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2449 int column_width = fw + 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2450 octave_idx_type total_width = nc * column_width; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2451 octave_idx_type max_width = command_editor::terminal_cols (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2452 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2453 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2454 max_width -= 4; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2455 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2456 max_width -= extra_indent; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2457 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2458 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2459 max_width = 0; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2460 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2461 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2462 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2463 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2464 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2465 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2466 os << Matrix (m); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2467 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2468 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2469 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2470 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2471 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2472 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2473 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2474 octave_idx_type inc = nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2475 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
|
2476 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2477 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2478 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2479 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2480 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2481 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2482 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2483 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2484 Array<octave_idx_type> pvec = m.pvec (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2485 bool colp = m.is_col_perm (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2486 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2487 os << "eye ("; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2488 if (colp) os << ":, "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2489 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2490 octave_idx_type col = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2491 while (col < nc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2492 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2493 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2494 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2495 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
|
2496 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2497 octave_quit (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2498 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2499 if (j == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2500 os << "[ "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2501 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2502 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2503 if (j > col && j < lim) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2504 os << ", "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2505 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2506 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2507 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2508 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2509 os << pvec (j); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2510 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2511 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2512 col += inc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2513 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2514 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2515 os << " ]"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2516 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2517 os << " ...\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2518 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2519 if (! colp) os << ", :"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2520 os << ")"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2521 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2522 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2523 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2524 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2525 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2526 os << "Permutation Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2527 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2528 os << "\n"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2529 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2530 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
|
2531 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2532 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2533 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2534 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
|
2535 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2536 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2537 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
|
2538 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2539 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2540 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2541 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
|
2542 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2543 octave_quit (); |
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 os << " "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2546 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2547 os << std::setw (fw) << m(i,j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2548 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2549 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2550 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2551 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2552 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2553 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2554 } |
8891
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 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2557 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2558 void |
4513 | 2559 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
|
2560 bool pr_as_read_syntax, int extra_indent) |
4513 | 2561 { |
2562 switch (nda.ndims ()) | |
2563 { | |
2564 case 1: | |
2565 case 2: | |
2566 octave_print_internal (os, nda.matrix_value (), | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2567 pr_as_read_syntax, extra_indent); |
4513 | 2568 break; |
2569 | |
2570 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2571 print_nd_array <ComplexNDArray, Complex, ComplexMatrix> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2572 (os, nda, pr_as_read_syntax); |
4513 | 2573 break; |
2574 } | |
2575 } | |
2576 | |
2577 void | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2578 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2579 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2580 octave_print_internal (os, double (d), pr_as_read_syntax); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2581 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2582 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2583 // 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
|
2584 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2585 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2586 octave_print_internal (std::ostream& os, float d, bool pr_as_read_syntax) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2587 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2588 octave_print_internal (os, double (d), pr_as_read_syntax); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2589 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2590 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2591 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2592 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
|
2593 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
|
2594 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2595 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2596 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2597 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2598 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2599 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
|
2600 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
|
2601 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2602 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2603 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2604 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2605 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2606 octave_print_internal (std::ostream& os, const FloatNDArray& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2607 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
|
2608 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2609 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2610 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2611 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2612 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2613 octave_print_internal (std::ostream& os, const FloatComplex& c, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2614 bool pr_as_read_syntax) |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2615 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2616 octave_print_internal (os, Complex (c), pr_as_read_syntax); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2617 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2618 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2619 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2620 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
|
2621 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
|
2622 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2623 octave_print_internal (os, ComplexMatrix (cm), pr_as_read_syntax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2624 extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2625 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2626 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2627 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2628 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
|
2629 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2630 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2631 octave_print_internal (os, ComplexDiagMatrix (cm), pr_as_read_syntax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2632 extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2633 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2634 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2635 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2636 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2637 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
|
2638 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2639 octave_print_internal (os, ComplexNDArray (nda), pr_as_read_syntax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2640 extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2641 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2642 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2643 void |
3523 | 2644 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
|
2645 bool pr_as_read_syntax, int extra_indent) |
1 | 2646 { |
626 | 2647 double base = r.base (); |
1 | 2648 double increment = r.inc (); |
626 | 2649 double limit = r.limit (); |
5275 | 2650 octave_idx_type num_elem = r.nelem (); |
1 | 2651 |
626 | 2652 if (plus_format && ! pr_as_read_syntax) |
1 | 2653 { |
5275 | 2654 for (octave_idx_type i = 0; i < num_elem; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2655 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2656 octave_quit (); |
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 double val = base + i * increment; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2659 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2660 pr_plus_format (os, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2661 } |
1 | 2662 } |
2663 else | |
2664 { | |
10987
eec74ee00b32
eliminate some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2665 int fw = 0; |
3105 | 2666 double scale = 1.0; |
2667 set_format (r, fw, scale); | |
1 | 2668 |
626 | 2669 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2670 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2671 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2672 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2673 os << base << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2674 if (increment != 1.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2675 os << increment << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2676 os << limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2677 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2678 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2679 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2680 pr_float (os, base, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2681 os << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2682 if (increment != 1.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2683 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2684 pr_float (os, increment, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2685 os << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2686 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2687 pr_float (os, limit, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2688 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2689 } |
626 | 2690 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2691 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2692 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2693 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2694 int column_width = fw + 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2695 octave_idx_type total_width = num_elem * column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2696 octave_idx_type max_width = command_editor::terminal_cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2697 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2698 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2700 os << r; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2701 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2702 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2703 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2704 octave_idx_type inc = num_elem; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2705 if (total_width > max_width && Vsplit_long_rows) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2706 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2707 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2708 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2709 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2710 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2711 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2712 max_width -= extra_indent; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2713 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2714 if (max_width < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2715 max_width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2716 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2717 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2718 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2719 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2720 while (col < num_elem) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2721 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2722 octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2723 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2724 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
|
2725 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2726 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2727 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2728 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2729 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
|
2730 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2731 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2732 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2733 double val; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2734 if (i == 0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2735 val = base; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2736 else |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2737 val = base + i * increment; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2738 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2739 if (i == num_elem - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2740 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2741 // 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
|
2742 if ((increment > 0 && val >= limit) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2743 || (increment < 0 && val <= limit)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2744 val = limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2745 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2746 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2747 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2748 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2749 pr_float (os, val, fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2750 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2751 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2752 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2753 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2754 } |
1 | 2755 } |
2756 } | |
2757 | |
1343 | 2758 void |
3523 | 2759 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
|
2760 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2761 int extra_indent) |
3215 | 2762 { |
2763 Matrix tmp (bm); | |
2764 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); | |
2765 } | |
2766 | |
2767 void | |
4513 | 2768 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
|
2769 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2770 int extra_indent) |
4513 | 2771 { |
2772 switch (nda.ndims ()) | |
2773 { | |
2774 case 1: | |
2775 case 2: | |
2776 octave_print_internal (os, nda.matrix_value (), | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2777 pr_as_read_syntax, extra_indent); |
4513 | 2778 break; |
2779 | |
2780 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2781 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
|
2782 boolMatrix> (os, nda, pr_as_read_syntax); |
4513 | 2783 break; |
2784 } | |
2785 } | |
2786 | |
2787 void | |
3523 | 2788 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
|
2789 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2790 int /* extra_indent FIXME */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2791 bool pr_as_string) |
1343 | 2792 { |
1572 | 2793 if (pr_as_string) |
2794 { | |
5275 | 2795 octave_idx_type nstr = chm.rows (); |
1343 | 2796 |
1572 | 2797 if (pr_as_read_syntax && nstr > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2798 os << "[ "; |
1343 | 2799 |
2907 | 2800 if (nstr != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2801 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2802 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
|
2803 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2804 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2805 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2806 std::string row = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2807 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2808 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2809 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2810 os << "\"" << undo_string_escapes (row) << "\""; |
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 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2813 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2814 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2815 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2816 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2817 os << row; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2818 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2819 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2820 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2821 } |
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 } |
1572 | 2824 |
2825 if (pr_as_read_syntax && nstr > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2826 os << " ]"; |
1343 | 2827 } |
1572 | 2828 else |
2829 { | |
2830 os << "sorry, printing char matrices not implemented yet\n"; | |
2831 } | |
1343 | 2832 } |
2833 | |
4513 | 2834 void |
2835 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
|
2836 bool pr_as_read_syntax, int extra_indent, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2837 bool pr_as_string) |
4513 | 2838 { |
2839 switch (nda.ndims ()) | |
2840 { | |
2841 case 1: | |
2842 case 2: | |
2843 octave_print_internal (os, nda.matrix_value (), | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2844 pr_as_read_syntax, extra_indent, pr_as_string); |
4513 | 2845 break; |
2846 | |
2847 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2848 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
|
2849 pr_as_read_syntax); |
4513 | 2850 break; |
2851 } | |
2852 } | |
2853 | |
4655 | 2854 void |
4925 | 2855 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
|
2856 bool pr_as_read_syntax, int extra_indent) |
4925 | 2857 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2858 Array<std::string> nda (dim_vector (1, 1), s); |
4925 | 2859 |
2860 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2861 } | |
2862 | |
2863 void | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2864 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
|
2865 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2866 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2867 // FIXME: this mostly duplicates the code in the print_nd_array<> |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2868 // function. Can fix this with std::is_same from C++11. |
4655 | 2869 |
2870 if (nda.is_empty ()) | |
2871 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
2872 else if (nda.length () == 1) | |
2873 { | |
2874 os << nda(0); | |
2875 } | |
2876 else | |
2877 { | |
2878 int ndims = nda.ndims (); | |
2879 | |
2880 dim_vector dims = nda.dims (); | |
2881 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2882 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 2883 |
2884 octave_idx_type m = 1; | |
4655 | 2885 |
2886 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2887 m *= dims(i); |
4655 | 2888 |
5275 | 2889 octave_idx_type nr = dims(0); |
2890 octave_idx_type nc = dims(1); | |
2891 | |
2892 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
|
2893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2894 std::string nm = "ans"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2895 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2896 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2897 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2898 nm += "(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2899 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2900 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2901 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2902 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2903 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2904 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2905 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2906 if (k < ndims - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2907 buf << ","; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2908 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2909 buf << ")"; |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2912 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2913 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2914 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2915 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
|
2916 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2917 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2918 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2919 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2920 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2921 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2922 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2923 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
|
2924 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2925 // 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
|
2926 // in neatly aligned columns... |
10315
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 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2929 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2930 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2931 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2932 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2933 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2934 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2935 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
|
2936 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2937 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
|
2938 os << " " << page(ii,jj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2939 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2940 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2941 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2942 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2943 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2944 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2945 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2946 if (i < m) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2947 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2948 } |
4655 | 2949 } |
2950 } | |
2951 | |
4901 | 2952 template <class T> |
2953 class | |
2954 octave_print_conv | |
2955 { | |
2956 public: | |
2957 typedef T print_conv_type; | |
2958 }; | |
2959 | |
2960 #define PRINT_CONV(T1, T2) \ | |
2961 template <> \ | |
2962 class \ | |
2963 octave_print_conv<T1> \ | |
2964 { \ | |
2965 public: \ | |
2966 typedef T2 print_conv_type; \ | |
2967 } | |
2968 | |
2969 PRINT_CONV (octave_int8, octave_int16); | |
2970 PRINT_CONV (octave_uint8, octave_uint16); | |
2971 | |
2972 #undef PRINT_CONV | |
2973 | |
2974 template <class T> | |
6018 | 2975 /* static */ inline void |
4949 | 2976 pr_int (std::ostream& os, const T& d, int fw = 0) |
2977 { | |
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
|
2978 size_t sz = d.byte_size (); |
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
|
2979 const unsigned char * tmpi = d.iptr (); |
4949 | 2980 |
5544 | 2981 // Unless explicitly asked for, always print in big-endian |
2982 // format for hex and bit formats. | |
2983 // | |
2984 // {bit,hex}_format == 1: print big-endian | |
2985 // {bit,hex}_format == 2: print native | |
2986 | |
4949 | 2987 if (hex_format) |
2988 { | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2989 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2990 |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
2991 os.flags (std::ios::right | std::ios::hex); |
4949 | 2992 |
2993 if (hex_format > 1 || oct_mach_info::words_big_endian ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2994 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2995 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2996 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
|
2997 } |
4949 | 2998 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2999 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3000 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3001 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
|
3002 } |
4949 | 3003 } |
3004 else if (bit_format) | |
3005 { | |
5544 | 3006 if (oct_mach_info::words_big_endian ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3007 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3008 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3009 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3010 } |
4949 | 3011 else |
10315
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 if (bit_format > 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 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3016 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3017 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3018 else |
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 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3021 PRINT_CHAR_BITS (os, tmpi[i]); |
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 } |
4949 | 3024 } |
3025 else | |
3026 { | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3027 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3028 |
4949 | 3029 os << std::setw (fw) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3030 << typename octave_print_conv<T>::print_conv_type (d); |
4949 | 3031 |
3032 if (bank_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3033 os << ".00"; |
4949 | 3034 } |
3035 } | |
3036 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3037 // FIXME: all this mess with abs is an attempt to avoid seeing |
6120 | 3038 // |
3039 // warning: comparison of unsigned expression < 0 is always false | |
3040 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3041 // from GCC. Isn't there a better way? |
6120 | 3042 |
4949 | 3043 template <class T> |
6018 | 3044 /* static */ inline T |
6008 | 3045 abs (T x) |
3046 { | |
6120 | 3047 return x < 0 ? -x : x; |
6008 | 3048 } |
3049 | |
6120 | 3050 #define INSTANTIATE_ABS(T) \ |
12414 | 3051 template /* static */ T abs (T) |
6120 | 3052 |
3053 INSTANTIATE_ABS(signed char); | |
3054 INSTANTIATE_ABS(short); | |
3055 INSTANTIATE_ABS(int); | |
3056 INSTANTIATE_ABS(long); | |
3057 INSTANTIATE_ABS(long long); | |
3058 | |
3059 #define SPECIALIZE_UABS(T) \ | |
3060 template <> \ | |
3061 /* static */ inline unsigned T \ | |
3062 abs (unsigned T x) \ | |
3063 { \ | |
3064 return x; \ | |
3065 } | |
3066 | |
3067 SPECIALIZE_UABS(char) | |
3068 SPECIALIZE_UABS(short) | |
3069 SPECIALIZE_UABS(int) | |
3070 SPECIALIZE_UABS(long) | |
3071 SPECIALIZE_UABS(long long) | |
6008 | 3072 |
7215 | 3073 template void |
3074 pr_int (std::ostream&, const octave_int8&, int); | |
3075 | |
3076 template void | |
3077 pr_int (std::ostream&, const octave_int16&, int); | |
3078 | |
3079 template void | |
3080 pr_int (std::ostream&, const octave_int32&, int); | |
3081 | |
3082 template void | |
3083 pr_int (std::ostream&, const octave_int64&, int); | |
3084 | |
3085 template void | |
3086 pr_int (std::ostream&, const octave_uint8&, int); | |
3087 | |
3088 template void | |
3089 pr_int (std::ostream&, const octave_uint16&, int); | |
3090 | |
3091 template void | |
3092 pr_int (std::ostream&, const octave_uint32&, int); | |
3093 | |
3094 template void | |
3095 pr_int (std::ostream&, const octave_uint64&, int); | |
3096 | |
6008 | 3097 template <class T> |
4901 | 3098 void |
7215 | 3099 octave_print_internal_template (std::ostream& os, const octave_int<T>& val, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3100 bool) |
7215 | 3101 { |
3102 if (plus_format) | |
3103 { | |
3104 pr_plus_format (os, val); | |
3105 } | |
3106 else | |
3107 { | |
3108 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3109 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val); |
7215 | 3110 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3111 pr_int (os, val); |
7215 | 3112 } |
3113 } | |
3114 | |
3115 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ | |
3116 OCTINTERP_API void \ | |
3117 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \ | |
3118 { \ | |
3119 octave_print_internal_template (os, val, dummy); \ | |
3120 } | |
3121 | |
3122 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
3123 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
3124 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
3125 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
3126 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
3127 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
3128 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
3129 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
3130 | |
3131 template <class T> | |
3132 /* static */ inline void | |
3133 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
|
3134 bool pr_as_read_syntax, int extra_indent) |
4901 | 3135 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3136 // FIXME: this mostly duplicates the code in the print_nd_array<> |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
3137 // function. Can fix this with std::is_same from C++11. |
4901 | 3138 |
3139 if (nda.is_empty ()) | |
3140 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
3141 else if (nda.length () == 1) | |
7215 | 3142 octave_print_internal_template (os, nda(0), pr_as_read_syntax); |
4949 | 3143 else if (plus_format && ! pr_as_read_syntax) |
4901 | 3144 { |
3145 int ndims = nda.ndims (); | |
3146 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3147 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
4949 | 3148 |
4901 | 3149 dim_vector dims = nda.dims (); |
3150 | |
5275 | 3151 octave_idx_type m = 1; |
4901 | 3152 |
3153 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3154 m *= dims(i); |
4901 | 3155 |
5275 | 3156 octave_idx_type nr = dims(0); |
3157 octave_idx_type nc = dims(1); | |
3158 | |
3159 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
|
3160 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3161 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3162 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3163 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3164 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3165 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3166 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3167 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3168 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3169 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3170 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3171 if (k < ndims - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3172 buf << ","; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3173 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3174 buf << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3175 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3176 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3177 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3178 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3179 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3180 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3181 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3182 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3183 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3184 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
|
3185 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3186 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3187 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3188 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3189 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3190 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3191 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3192 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
|
3193 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3194 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
|
3195 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3196 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
|
3197 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3198 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3199 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3200 pr_plus_format (os, page(ii,jj)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3201 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3202 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3203 if ((ii < nr - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3204 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3205 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3206 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3207 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3208 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3209 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3210 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3211 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3212 } |
4949 | 3213 } |
3214 else | |
3215 { | |
3216 int ndims = nda.ndims (); | |
3217 | |
3218 dim_vector dims = nda.dims (); | |
3219 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3220 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 3221 |
3222 octave_idx_type m = 1; | |
4949 | 3223 |
3224 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3225 m *= dims(i); |
4949 | 3226 |
5275 | 3227 octave_idx_type nr = dims(0); |
3228 octave_idx_type nc = dims(1); | |
4949 | 3229 |
3230 int fw = 0; | |
3231 if (hex_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3232 fw = 2 * nda(0).byte_size (); |
4949 | 3233 else if (bit_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3234 fw = nda(0).nbits (); |
4949 | 3235 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3236 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3237 bool isneg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3238 int digits = 0; |
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 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
|
3241 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3242 int new_digits |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3243 = static_cast<int> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3244 (gnulib::floor (log10 (double (abs (nda(i).value ()))) + 1.0)); |
10315
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 if (new_digits > digits) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3247 digits = new_digits; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3248 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3249 if (! isneg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3250 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
|
3251 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3252 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3253 fw = digits + isneg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3254 } |
4949 | 3255 |
6788 | 3256 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 3257 octave_idx_type total_width = nc * column_width; |
4949 | 3258 int max_width = command_editor::terminal_cols () - extra_indent; |
5275 | 3259 octave_idx_type inc = nc; |
4949 | 3260 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
|
3261 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3262 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3263 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3264 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3265 } |
4949 | 3266 |
5275 | 3267 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
|
3268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3269 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3270 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3271 std::string nm = "ans(:,:,"; |
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 std::ostringstream buf; |
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 (int k = 2; k < ndims; k++) |
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 buf << ra_idx(k) + 1; |
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 if (k < ndims - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3280 buf << ","; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3281 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3282 buf << ")"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3283 } |
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 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3286 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3287 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3288 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3289 os << "\n"; |
10315
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 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3292 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
|
3293 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3294 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3295 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3296 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3297 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3298 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3299 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3300 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
|
3301 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3302 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3303 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3304 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3305 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3306 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3307 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
|
3308 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3309 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
|
3310 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3311 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3312 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3313 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
|
3314 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3315 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3316 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3317 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3318 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3319 os << "]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3320 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3321 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3322 { |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3323 octave_preserve_stream_state stream_state (os); |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3324 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3325 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3326 octave_idx_type n_cols = page.cols (); |
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 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
|
3329 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3330 octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols; |
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 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
|
3333 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3334 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3335 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
|
3336 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3337 os << std::setw (extra_indent) << ""; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3338 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3339 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
|
3340 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3341 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3342 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3343 pr_int (os, page(ii,jj), fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3344 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3345 if ((ii < n_rows - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3346 os << "\n"; |
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 } |
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3351 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3352 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3353 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3354 increment_index (ra_idx, dims, 2); |
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 } |
4901 | 3357 } |
3358 } | |
3359 | |
7215 | 3360 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
3361 OCTINTERP_API void \ | |
3362 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \ | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3363 bool pr_as_read_syntax, int extra_indent) \ |
7215 | 3364 { \ |
3365 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ | |
3366 } | |
3367 | |
3368 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
3369 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
3370 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
3371 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
3372 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
3373 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
3374 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
3375 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 3376 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7896
diff
changeset
|
3377 void |
3933 | 3378 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928 | 3379 { |
3933 | 3380 panic_impossible (); |
3928 | 3381 } |
3382 | |
6788 | 3383 DEFUN (rats, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3384 "-*- texinfo -*-\n\ |
6788 | 3385 @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\ |
3386 Convert @var{x} into a rational approximation represented as a string.\n\ | |
3387 You can convert the string back into a matrix as follows:\n\ | |
3388 \n\ | |
3389 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3390 @group\n\ |
14360
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3391 r = rats (hilb (4));\n\ |
97883071e8e4
doc: Correct off-by-1 spacings in all .cc docstrings
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
3392 x = str2num (r)\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3393 @end group\n\ |
6788 | 3394 @end example\n\ |
3395 \n\ | |
3396 The optional second argument defines the maximum length of the string\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8930
diff
changeset
|
3397 representing the elements of @var{x}. By default @var{len} is 9.\n\ |
6788 | 3398 @seealso{format, rat}\n\ |
3399 @end deftypefn") | |
3400 { | |
3401 octave_value retval; | |
6803 | 3402 |
6788 | 3403 int nargin = args.length (); |
3404 | |
7896 | 3405 if (nargin < 1 || nargin > 2 || nargout > 1) |
3406 print_usage (); | |
3407 else | |
6788 | 3408 { |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
3409 unwind_protect frame; |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
3410 |
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9758
diff
changeset
|
3411 frame.protect_var (rat_string_len); |
7896 | 3412 |
3413 rat_string_len = 9; | |
3414 | |
3415 if (nargin == 2) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3416 rat_string_len = args(1).nint_value (); |
7896 | 3417 |
3418 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3419 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3420 octave_value arg = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3421 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3422 if (arg.is_numeric_type ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3423 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3424 frame.protect_var (rat_format); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3425 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3426 rat_format = true; |
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 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3429 args(0).print (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3430 std::string s = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3431 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3432 std::list<std::string> lst; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3433 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3434 size_t n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3435 size_t s_len = s.length (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3436 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3437 while (n < s_len) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3438 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3439 size_t m = s.find ('\n', n); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3440 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3441 if (m == std::string::npos) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3442 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3443 lst.push_back (s.substr (n)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3444 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3445 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3446 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3447 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3448 lst.push_back (s.substr (n, m - n)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3449 n = m + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3450 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3451 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3452 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3453 retval = string_vector (lst); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3454 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3455 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12414
diff
changeset
|
3456 error ("rats: X must be numeric"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3457 } |
6788 | 3458 } |
3459 | |
3460 return retval; | |
3461 } | |
3462 | |
3685 | 3463 DEFUN (disp, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3464 "-*- texinfo -*-\n\ |
3685 | 3465 @deftypefn {Built-in Function} {} disp (@var{x})\n\ |
10840 | 3466 Display the value of @var{x}. For example:\n\ |
3685 | 3467 \n\ |
3468 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3469 @group\n\ |
3685 | 3470 disp (\"The value of pi is:\"), disp (pi)\n\ |
3471 \n\ | |
3472 @print{} the value of pi is:\n\ | |
3473 @print{} 3.1416\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3474 @end group\n\ |
3685 | 3475 @end example\n\ |
3476 \n\ | |
3477 @noindent\n\ | |
3478 Note that the output from @code{disp} always ends with a newline.\n\ | |
3479 \n\ | |
3480 If an output value is requested, @code{disp} prints nothing and\n\ | |
3481 returns the formatted output in a string.\n\ | |
5642 | 3482 @seealso{fdisp}\n\ |
3483 @end deftypefn") | |
3685 | 3484 { |
9643
85dd3a2c9355
avoid returning undefined values from disp & fdisp
Jaroslav Hajek <highegg@gmail.com>
parents:
9629
diff
changeset
|
3485 octave_value_list retval; |
3685 | 3486 |
3487 int nargin = args.length (); | |
3488 | |
3489 if (nargin == 1 && nargout < 2) | |
3490 { | |
3491 if (nargout == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3492 args(0).print (octave_stdout); |
3685 | 3493 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3494 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3495 octave_value arg = args(0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3496 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3497 arg.print (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3498 retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3499 } |
3685 | 3500 } |
3501 else | |
5823 | 3502 print_usage (); |
3685 | 3503 |
3504 return retval; | |
3505 } | |
3506 | |
3507 DEFUN (fdisp, args, , | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3508 "-*- texinfo -*-\n\ |
3685 | 3509 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\ |
10840 | 3510 Display the value of @var{x} on the stream @var{fid}. For example:\n\ |
3685 | 3511 \n\ |
3512 @example\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3513 @group\n\ |
4869 | 3514 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\ |
3685 | 3515 \n\ |
3516 @print{} the value of pi is:\n\ | |
3517 @print{} 3.1416\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
9039
diff
changeset
|
3518 @end group\n\ |
3685 | 3519 @end example\n\ |
3520 \n\ | |
3521 @noindent\n\ | |
4869 | 3522 Note that the output from @code{fdisp} always ends with a newline.\n\ |
5642 | 3523 @seealso{disp}\n\ |
3524 @end deftypefn") | |
3685 | 3525 { |
9643
85dd3a2c9355
avoid returning undefined values from disp & fdisp
Jaroslav Hajek <highegg@gmail.com>
parents:
9629
diff
changeset
|
3526 octave_value_list retval; |
3685 | 3527 |
3528 int nargin = args.length (); | |
3529 | |
3530 if (nargin == 2) | |
3531 { | |
3532 int fid = octave_stream_list::get_file_number (args (0)); | |
3533 | |
3534 octave_stream os = octave_stream_list::lookup (fid, "fdisp"); | |
3535 | |
3536 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3537 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3538 std::ostream *osp = os.output_stream (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3539 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3540 if (osp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3541 args(1).print (*osp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3542 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12414
diff
changeset
|
3543 error ("fdisp: stream FID not open for writing"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3544 } |
3685 | 3545 } |
3546 else | |
5823 | 3547 print_usage (); |
3685 | 3548 |
3549 return retval; | |
3550 } | |
3551 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3552 /* |
9629 | 3553 %!test |
3554 %! format short | |
3555 %! fd = tmpfile (); | |
3556 %! for r = [0, Inf -Inf, NaN] | |
3557 %! for i = [0, Inf -Inf, NaN] | |
3558 %! fdisp (fd, complex (r, i)); | |
3559 %! endfor | |
3560 %! endfor | |
3561 %! fclose (fd); | |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3562 |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3563 %!test |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3564 %! foo.real = pi * ones (3,20,3); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3565 %! 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
|
3566 %! foo.char = repmat ("- Hello World -", [3, 20]); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3567 %! 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
|
3568 %! 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
|
3569 %! 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
|
3570 %! format loose; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3571 %! 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
|
3572 %! format compact; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3573 %! compact = disp (foo.(fields{f})); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3574 %! 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
|
3575 %! assert (expected, compact); |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3576 %! endfor |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3577 */ |
9629 | 3578 |
1 | 3579 static void |
3580 init_format_state (void) | |
3581 { | |
2387 | 3582 free_format = false; |
3583 plus_format = false; | |
6788 | 3584 rat_format = false; |
2387 | 3585 bank_format = false; |
3608 | 3586 hex_format = 0; |
1309 | 3587 bit_format = 0; |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3588 Vcompact_format = false; |
2387 | 3589 print_e = false; |
3590 print_big_e = false; | |
4509 | 3591 print_g = false; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3592 print_eng = false; |
1 | 3593 } |
3594 | |
3595 static void | |
3596 set_output_prec_and_fw (int prec, int fw) | |
3597 { | |
5794 | 3598 Voutput_precision = prec; |
3599 Voutput_max_field_width = fw; | |
1 | 3600 } |
3601 | |
1755 | 3602 static void |
3603 set_format_style (int argc, const string_vector& argv) | |
1 | 3604 { |
1755 | 3605 int idx = 1; |
3606 | |
1899 | 3607 if (--argc > 0) |
1 | 3608 { |
3523 | 3609 std::string arg = argv[idx++]; |
2584 | 3610 |
1755 | 3611 if (arg == "short") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3612 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3613 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3614 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3615 arg = argv[idx++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3616 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3617 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3618 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3619 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3620 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3621 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3622 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3623 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3624 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3625 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3626 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3627 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3628 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3629 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3630 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3631 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3632 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3633 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3634 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3635 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3636 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3637 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3638 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3639 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3640 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3641 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3642 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3643 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3644 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3645 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
3646 error ("format: unrecognized option 'short %s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3647 arg.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3648 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3649 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3650 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3651 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3652 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3653 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3654 set_output_prec_and_fw (5, 10); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3655 } |
1755 | 3656 else if (arg == "long") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3657 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3658 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3659 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3660 arg = argv[idx++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3661 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3662 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3663 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3664 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3665 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3666 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3667 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3668 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3669 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3670 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3671 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3672 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3673 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3674 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3675 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3676 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3677 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3678 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3679 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3680 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3681 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3682 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3683 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3684 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3685 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3686 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3687 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3688 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3689 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3690 { |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
3691 error ("format: unrecognized option 'long %s'", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3692 arg.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3693 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3694 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3695 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3696 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3697 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3698 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3699 set_output_prec_and_fw (15, 20); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3700 } |
1755 | 3701 else if (arg == "hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3702 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3703 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3704 hex_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3705 } |
1755 | 3706 else if (arg == "native-hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3707 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3708 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3709 hex_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3710 } |
1755 | 3711 else if (arg == "bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3712 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3713 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3714 bit_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3715 } |
1755 | 3716 else if (arg == "native-bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3717 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3718 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3719 bit_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3720 } |
1755 | 3721 else if (arg == "+" || arg == "plus") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3722 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3723 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3724 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3725 arg = argv[idx++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3726 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3727 if (arg.length () == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3728 plus_format_chars = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3729 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3730 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3731 error ("format: invalid option for plus format"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3732 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3733 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3734 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3735 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3736 plus_format_chars = "+ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3737 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3738 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3739 plus_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3740 } |
6788 | 3741 else if (arg == "rat") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3742 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3743 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3744 rat_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3745 } |
1755 | 3746 else if (arg == "bank") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3747 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3748 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3749 bank_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3750 } |
1755 | 3751 else if (arg == "free") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3752 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3753 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3754 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3755 } |
1755 | 3756 else if (arg == "none") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3757 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3758 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3759 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3760 } |
1755 | 3761 else if (arg == "compact") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3762 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3763 Vcompact_format = true; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3764 } |
1755 | 3765 else if (arg == "loose") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3766 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3767 Vcompact_format = false; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3768 } |
1 | 3769 else |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
3770 error ("format: unrecognized format state '%s'", arg.c_str ()); |
1 | 3771 } |
3772 else | |
3773 { | |
3774 init_format_state (); | |
3775 set_output_prec_and_fw (5, 10); | |
3776 } | |
3777 } | |
3778 | |
8746
5dd06f19e9be
handle commands in the lexer
John W. Eaton <jwe@octave.org>
parents:
8625
diff
changeset
|
3779 DEFUN (format, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3780 "-*- texinfo -*-\n\ |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11570
diff
changeset
|
3781 @deftypefn {Command} {} format\n\ |
11547 | 3782 @deftypefnx {Command} {} format options\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3783 Reset or specify the format of the output produced by @code{disp} and\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3784 Octave's normal echoing mechanism. This command only affects the display\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3785 of numbers but not how they are stored or computed. To change the internal\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3786 representation from the default double use one of the conversion functions\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3787 such as @code{single}, @code{uint8}, @code{int64}, etc.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3788 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3789 By default, Octave displays 5 significant digits in a human readable form\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3790 (option @samp{short} paired with @samp{loose} format for matrices).\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3791 If @code{format} is invoked without any options, this default format\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3792 is restored.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3793 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3794 Valid formats for floating point numbers are listed in the following\n\ |
3372 | 3795 table.\n\ |
3796 \n\ | |
3797 @table @code\n\ | |
3798 @item short\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3799 Fixed point format with 5 significant figures in a field that is a maximum\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3800 of 10 characters wide. (default).\n\ |
3372 | 3801 \n\ |
3802 If Octave is unable to format a matrix so that columns line up on the\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3803 decimal point and all numbers fit within the maximum field width then\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3804 it switches to an exponential @samp{e} format.\n\ |
3372 | 3805 \n\ |
3806 @item long\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3807 Fixed point format with 15 significant figures in a field that is a maximum\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3808 of 20 characters wide.\n\ |
3372 | 3809 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3810 As with the @samp{short} format, Octave will switch to an exponential\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3811 @samp{e} format if it is unable to format a matrix properly using the\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3812 current format.\n\ |
3372 | 3813 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3814 @item short e\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3815 @itemx long e\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3816 Exponential format. The number to be represented is split between a mantissa\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3817 and an exponent (power of 10). The mantissa has 5 significant digits in the\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3818 short format and 15 digits in the long format.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3819 For example, with the @samp{short e} format, @code{pi} is displayed as\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3820 @code{3.1416e+00}.\n\ |
3372 | 3821 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3822 @item short E\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3823 @itemx long E\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3824 Identical to @samp{short e} or @samp{long e} but displays an uppercase\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3825 @samp{E} to indicate the exponent.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3826 For example, with the @samp{long E} format, @code{pi} is displayed as\n\ |
3372 | 3827 @code{3.14159265358979E+00}.\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3828 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3829 @item short g\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3830 @itemx long g\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3831 Optimally choose between fixed point and exponential format based on\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3832 the magnitude of the number.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3833 For example, with the @samp{short g} format,\n\ |
4509 | 3834 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
3835 \n\ | |
3836 @example\n\ | |
3837 @group\n\ | |
3838 ans =\n\ | |
3839 \n\ | |
3840 9.8696\n\ | |
3841 97.409\n\ | |
3842 9488.5\n\ | |
3843 9.0032e+07\n\ | |
3844 8.1058e+15\n\ | |
3845 @end group\n\ | |
3846 @end example\n\ | |
3847 \n\ | |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3848 @item short eng\n\ |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3849 @itemx long eng\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3850 Identical to @samp{short e} or @samp{long e} but displays the value\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3851 using an engineering format, where the exponent is divisible by 3. For\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3852 example, with the @samp{short eng} format, @code{10 * pi} is displayed as\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3853 @code{31.4159e+00}.\n\ |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3854 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3855 @item long G\n\ |
4509 | 3856 @itemx short G\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3857 Identical to @samp{short g} or @samp{long g} but displays an uppercase\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3858 @samp{E} to indicate the exponent.\n\ |
3372 | 3859 \n\ |
17170
d6499c14021c
doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents:
16971
diff
changeset
|
3860 @item free\n\ |
3372 | 3861 @itemx none\n\ |
3862 Print output in free format, without trying to line up columns of\n\ | |
3863 matrices on the decimal point. This also causes complex numbers to be\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3864 formatted as numeric pairs like this @samp{(0.60419, 0.60709)} instead\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3865 of like this @samp{0.60419 + 0.60709i}.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3866 @end table\n\ |
529 | 3867 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3868 The following formats affect all numeric output (floating point and\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3869 integer types).\n\ |
3372 | 3870 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3871 @table @code\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3872 @item +\n\ |
4632 | 3873 @itemx + @var{chars}\n\ |
3874 @itemx plus\n\ | |
3875 @itemx plus @var{chars}\n\ | |
3372 | 3876 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ |
3877 matrix elements. This format can be very useful for examining the\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3878 structure of a large sparse matrix.\n\ |
3372 | 3879 \n\ |
4632 | 3880 The optional argument @var{chars} specifies a list of 3 characters to use\n\ |
3881 for printing values greater than zero, less than zero and equal to zero.\n\ | |
3882 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\ | |
3883 is displayed as\n\ | |
3884 \n\ | |
3885 @example\n\ | |
3886 @group\n\ | |
3887 ans =\n\ | |
3888 \n\ | |
3889 +.-\n\ | |
3890 -.+\n\ | |
3891 @end group\n\ | |
3892 @end example\n\ | |
3893 \n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3894 @item bank\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3895 Print in a fixed format with two digits to the right of the decimal\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3896 point.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3897 \n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3898 @item native-hex\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3899 Print the hexadecimal representation of numbers as they are stored in\n\ |
3372 | 3900 memory. For example, on a workstation which stores 8 byte real values\n\ |
3901 in IEEE format with the least significant byte first, the value of\n\ | |
10846
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3902 @code{pi} when printed in @code{native-hex} format is\n\ |
a4f482e66b65
Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents:
10840
diff
changeset
|
3903 @code{400921fb54442d18}.\n\ |
3372 | 3904 \n\ |
4833 | 3905 @item hex\n\ |
3906 The same as @code{native-hex}, but always print the most significant\n\ | |
3907 byte first.\n\ | |
10840 | 3908 \n\ |
4833 | 3909 @item native-bit\n\ |
3372 | 3910 Print the bit representation of numbers as stored in memory.\n\ |
3911 For example, the value of @code{pi} is\n\ | |
3912 \n\ | |
3913 @example\n\ | |
3914 @group\n\ | |
3915 01000000000010010010000111111011\n\ | |
3916 01010100010001000010110100011000\n\ | |
3917 @end group\n\ | |
3918 @end example\n\ | |
3919 \n\ | |
3920 (shown here in two 32 bit sections for typesetting purposes) when\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3921 printed in native-bit format on a workstation which stores 8 byte real values\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3922 in IEEE format with the least significant byte first.\n\ |
10840 | 3923 \n\ |
4833 | 3924 @item bit\n\ |
3925 The same as @code{native-bit}, but always print the most significant\n\ | |
3926 bits first.\n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3927 \n\ |
6788 | 3928 @item rat\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3929 Print a rational approximation, i.e., values are approximated\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3930 as the ratio of small integers.\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3931 For example, with the @samp{rat} format,\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3932 @code{pi} is displayed as @code{355/113}.\n\ |
3372 | 3933 @end table\n\ |
3934 \n\ | |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3935 The following two options affect the display of all matrices.\n\ |
3372 | 3936 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3937 @table @code\n\ |
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3938 @item compact\n\ |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3939 Remove blank lines around column number labels and between\n\ |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3940 matrices producing more compact output with more data per page.\n\ |
10840 | 3941 \n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3942 @item loose\n\ |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3943 Insert blank lines above and below column number labels and between matrices\n\ |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3944 to produce a more readable output with less data per page. (default).\n\ |
9305
52b4d82e5b4f
Update documentation for 'format'
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
3945 @end table\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3946 @seealso{fixed_point_format, output_max_field_width, output_precision, split_long_rows, rats}\n\ |
11547 | 3947 @end deftypefn") |
529 | 3948 { |
2086 | 3949 octave_value_list retval; |
529 | 3950 |
1755 | 3951 int argc = args.length () + 1; |
3952 | |
1968 | 3953 string_vector argv = args.make_argv ("format"); |
1755 | 3954 |
3955 if (error_state) | |
3956 return retval; | |
529 | 3957 |
3958 set_format_style (argc, argv); | |
3959 | |
3960 return retval; | |
3961 } | |
3962 | |
5794 | 3963 DEFUN (fixed_point_format, args, nargout, |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3964 "-*- texinfo -*-\n\ |
10840 | 3965 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\ |
5794 | 3966 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
3967 @deftypefnx {Built-in Function} {} fixed_point_format (@var{new_val}, \"local\")\n\ |
5794 | 3968 Query or set the internal variable that controls whether Octave will\n\ |
3969 use a scaled format to print matrix values such that the largest\n\ | |
3970 element may be written with a single leading digit with the scaling\n\ | |
10840 | 3971 factor is printed on the first line of output. For example:\n\ |
3321 | 3972 \n\ |
3973 @example\n\ | |
3974 @group\n\ | |
3975 octave:1> logspace (1, 7, 5)'\n\ | |
3976 ans =\n\ | |
3977 \n\ | |
3978 1.0e+07 *\n\ | |
3979 \n\ | |
3980 0.00000\n\ | |
3981 0.00003\n\ | |
3982 0.00100\n\ | |
3983 0.03162\n\ | |
3984 1.00000\n\ | |
3985 @end group\n\ | |
3986 @end example\n\ | |
3987 \n\ | |
3988 @noindent\n\ | |
3989 Notice that first value appears to be zero when it is actually 1. For\n\ | |
3990 this reason, you should be careful when setting\n\ | |
3991 @code{fixed_point_format} to a nonzero value.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
3992 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
3993 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
3994 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
3995 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3996 @seealso{format, output_max_field_width, output_precision}\n\ |
5794 | 3997 @end deftypefn") |
3998 { | |
3999 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
4000 } | |
4001 | |
4002 DEFUN (print_empty_dimensions, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4003 "-*- texinfo -*-\n\ |
10840 | 4004 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\ |
5794 | 4005 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4006 @deftypefnx {Built-in Function} {} print_empty_dimensions (@var{new_val}, \"local\")\n\ |
7001 | 4007 Query or set the internal variable that controls whether the\n\ |
3321 | 4008 dimensions of empty matrices are printed along with the empty matrix\n\ |
4009 symbol, @samp{[]}. For example, the expression\n\ | |
4010 \n\ | |
4011 @example\n\ | |
4012 zeros (3, 0)\n\ | |
4013 @end example\n\ | |
4014 \n\ | |
4015 @noindent\n\ | |
4016 will print\n\ | |
4017 \n\ | |
4018 @example\n\ | |
4019 ans = [](3x0)\n\ | |
4020 @end example\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4021 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4022 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4023 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4024 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4025 @seealso{format}\n\ |
5794 | 4026 @end deftypefn") |
4027 { | |
4028 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
4029 } | |
4030 | |
4031 DEFUN (split_long_rows, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4032 "-*- texinfo -*-\n\ |
10840 | 4033 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\ |
5794 | 4034 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4035 @deftypefnx {Built-in Function} {} split_long_rows (@var{new_val}, \"local\")\n\ |
5794 | 4036 Query or set the internal variable that controls whether rows of a matrix\n\ |
4037 may be split when displayed to a terminal window. If the rows are split,\n\ | |
4038 Octave will display the matrix in a series of smaller pieces, each of\n\ | |
4039 which can fit within the limits of your terminal width and each set of\n\ | |
4040 rows is labeled so that you can easily see which columns are currently\n\ | |
4041 being displayed. For example:\n\ | |
3321 | 4042 \n\ |
6670 | 4043 @example\n\ |
3321 | 4044 @group\n\ |
4045 octave:13> rand (2,10)\n\ | |
4046 ans =\n\ | |
4047 \n\ | |
4048 Columns 1 through 6:\n\ | |
4049 \n\ | |
4050 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ | |
4051 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ | |
4052 \n\ | |
4053 Columns 7 through 10:\n\ | |
4054 \n\ | |
4055 0.90174 0.11854 0.72313 0.73326\n\ | |
4056 0.44672 0.94303 0.56564 0.82150\n\ | |
4057 @end group\n\ | |
6670 | 4058 @end example\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4059 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4060 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4061 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4062 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4063 @seealso{format}\n\ |
5794 | 4064 @end deftypefn") |
4065 { | |
4066 return SET_INTERNAL_VARIABLE (split_long_rows); | |
4067 } | |
4068 | |
4069 DEFUN (output_max_field_width, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4070 "-*- texinfo -*-\n\ |
10840 | 4071 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\ |
5794 | 4072 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4073 @deftypefnx {Built-in Function} {} output_max_field_width (@var{new_val}, \"local\")\n\ |
5794 | 4074 Query or set the internal variable that specifies the maximum width\n\ |
4075 of a numeric output field.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4076 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4077 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4078 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4079 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4080 @seealso{format, fixed_point_format, output_precision}\n\ |
5794 | 4081 @end deftypefn") |
4082 { | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
4083 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_max_field_width, 0, |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
4084 std::numeric_limits<int>::max ()); |
5794 | 4085 } |
4086 | |
4087 DEFUN (output_precision, args, nargout, | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
4088 "-*- texinfo -*-\n\ |
10840 | 4089 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\ |
5794 | 4090 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\ |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4091 @deftypefnx {Built-in Function} {} output_precision (@var{new_val}, \"local\")\n\ |
5794 | 4092 Query or set the internal variable that specifies the minimum number of\n\ |
4093 significant figures to display for numeric output.\n\ | |
13951
79aa00a94e9e
doc: Document "local" option for configuration variables.
Rik <octave@nomad.inbox5.com>
parents:
13129
diff
changeset
|
4094 \n\ |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4095 When called from inside a function with the @qcode{\"local\"} option, the\n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4096 variable is changed locally for the function and any subroutines it calls. \n\ |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17170
diff
changeset
|
4097 The original variable value is restored when exiting the function.\n\ |
12191
c2a9fd508db4
pr-output.cc: fix @seealso lists
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
4098 @seealso{format, fixed_point_format, output_max_field_width}\n\ |
5794 | 4099 @end deftypefn") |
4100 { | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
4101 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
4102 std::numeric_limits<int>::max ()); |
5794 | 4103 } |