1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1346
|
27 #include <cfloat> |
3124
|
28 #include <cmath> |
2825
|
29 #include <cstdio> |
1346
|
30 #include <cstring> |
1343
|
31 |
3503
|
32 #include <iomanip> |
|
33 #include <iostream> |
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" |
4051
|
42 #include "lo-sstream.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" |
1
|
57 #include "utils.h" |
1352
|
58 #include "variables.h" |
1
|
59 |
3105
|
60 // TRUE means use a scaled fixed point format for `format long' and |
|
61 // `format short'. |
|
62 static bool Vfixed_point_format; |
|
63 |
2165
|
64 // The maximum field width for a number printed by the default output |
|
65 // routines. |
|
66 static int Voutput_max_field_width; |
|
67 |
|
68 // The precision of the numbers printed by the default output |
|
69 // routines. |
|
70 static int Voutput_precision; |
|
71 |
|
72 // TRUE means that the dimensions of empty matrices should be printed |
|
73 // like this: x = [](2x0). |
|
74 static bool Vprint_empty_dimensions; |
|
75 |
|
76 // TRUE means that the rows of big matrices should be split into |
|
77 // smaller slices that fit on the screen. |
|
78 static bool Vsplit_long_rows; |
|
79 |
3018
|
80 // TRUE means don't do any fancy formatting. |
2387
|
81 static bool free_format = false; |
1
|
82 |
3018
|
83 // TRUE means print plus sign for nonzero, blank for zero. |
2387
|
84 static bool plus_format = false; |
1
|
85 |
4632
|
86 // First char for > 0, second for < 0, third for == 0. |
|
87 static std::string plus_format_chars = "+ "; |
|
88 |
3018
|
89 // TRUE means always print like dollars and cents. |
2387
|
90 static bool bank_format = false; |
1282
|
91 |
3018
|
92 // TRUE means print data in hexadecimal format. |
3608
|
93 static int hex_format = 0; |
1282
|
94 |
3018
|
95 // TRUE means print data in binary-bit-pattern format. |
1309
|
96 static int bit_format = 0; |
|
97 |
3018
|
98 // TRUE means don't put newlines around the column number headers. |
2387
|
99 static bool compact_format = false; |
1186
|
100 |
3018
|
101 // TRUE means use an e format. |
2387
|
102 static bool print_e = false; |
1
|
103 |
4509
|
104 // TRUE means use a g format. |
|
105 static bool print_g = false; |
|
106 |
3018
|
107 // TRUE means print E instead of e for exponent field. |
2387
|
108 static bool print_big_e = false; |
1
|
109 |
3608
|
110 class pr_formatted_float; |
|
111 |
4509
|
112 static int |
|
113 current_output_max_field_width (void) |
|
114 { |
|
115 return Voutput_max_field_width; |
|
116 } |
|
117 |
|
118 static int |
|
119 current_output_precision (void) |
|
120 { |
|
121 return Voutput_precision; |
|
122 } |
|
123 |
3608
|
124 class |
|
125 float_format |
|
126 { |
|
127 public: |
|
128 |
4509
|
129 float_format (int w = current_output_max_field_width (), |
|
130 int p = current_output_precision (), int f = 0) |
3608
|
131 : fw (w), prec (p), fmt (f), up (0), sp (0) { } |
|
132 |
|
133 float_format (const float_format& ff) |
|
134 : fw (ff.fw), prec (ff.prec), fmt (ff.fmt), up (ff.up), sp (ff.sp) { } |
|
135 |
|
136 float_format& operator = (const float_format& ff) |
|
137 { |
|
138 if (&ff != this) |
|
139 { |
|
140 fw = ff.fw; |
|
141 prec = ff.prec; |
|
142 fmt = ff.fmt; |
|
143 up = ff.up; |
|
144 sp = ff.sp; |
|
145 } |
|
146 |
|
147 return *this; |
|
148 } |
|
149 |
|
150 ~float_format (void) { } |
|
151 |
|
152 float_format& scientific (void) { fmt = std::ios::scientific; return *this; } |
|
153 float_format& fixed (void) { fmt = std::ios::fixed; return *this; } |
|
154 float_format& general (void) { fmt = 0; return *this; } |
|
155 |
|
156 float_format& uppercase (void) { up = std::ios::uppercase; return *this; } |
|
157 float_format& lowercase (void) { up = 0; return *this; } |
|
158 |
|
159 float_format& precision (int p) { prec = p; return *this; } |
|
160 |
|
161 float_format& width (int w) { fw = w; return *this; } |
|
162 |
|
163 float_format& trailing_zeros (bool tz = true) |
|
164 { sp = tz ? std::ios::showpoint : 0; return *this; } |
|
165 |
|
166 friend std::ostream& operator << (std::ostream& os, |
|
167 const pr_formatted_float& pff); |
|
168 |
|
169 private: |
|
170 |
|
171 // Field width. Zero means as wide as necessary. |
|
172 int fw; |
|
173 |
|
174 // Precision. |
|
175 int prec; |
|
176 |
|
177 // Format. |
|
178 int fmt; |
|
179 |
|
180 // E or e. |
|
181 int up; |
|
182 |
|
183 // Show trailing zeros. |
|
184 int sp; |
|
185 }; |
|
186 |
|
187 class |
|
188 pr_formatted_float |
|
189 { |
|
190 public: |
|
191 |
|
192 const float_format& f; |
|
193 |
|
194 double val; |
|
195 |
|
196 pr_formatted_float (const float_format& f_arg, double val_arg) |
|
197 : f (f_arg), val (val_arg) { } |
|
198 }; |
|
199 |
|
200 std::ostream& |
|
201 operator << (std::ostream& os, const pr_formatted_float& pff) |
|
202 { |
3682
|
203 if (pff.f.fw >= 0) |
3608
|
204 os << std::setw (pff.f.fw); |
|
205 |
3682
|
206 if (pff.f.prec >= 0) |
3608
|
207 os << std::setprecision (pff.f.prec); |
|
208 |
3775
|
209 std::ios::fmtflags oflags = |
|
210 os.flags (static_cast<std::ios::fmtflags> |
|
211 (pff.f.fmt | pff.f.up | pff.f.sp)); |
3608
|
212 |
|
213 os << pff.val; |
|
214 |
|
215 os.flags (oflags); |
|
216 |
|
217 return os; |
|
218 } |
|
219 |
|
220 // Current format for real numbers and the real part of complex |
|
221 // numbers. |
|
222 static float_format *curr_real_fmt = 0; |
|
223 |
|
224 // Current format for the imaginary part of complex numbers. |
|
225 static float_format *curr_imag_fmt = 0; |
1309
|
226 |
1
|
227 static double |
164
|
228 pr_max_internal (const Matrix& m) |
1
|
229 { |
|
230 int nr = m.rows (); |
|
231 int nc = m.columns (); |
|
232 |
3130
|
233 double result = -DBL_MAX; |
1
|
234 |
|
235 for (int j = 0; j < nc; j++) |
|
236 for (int i = 0; i < nr; i++) |
|
237 { |
3608
|
238 double val = m(i,j); |
4025
|
239 if (xisinf (val) || octave_is_NaN_or_NA (val)) |
1
|
240 continue; |
|
241 |
|
242 if (val > result) |
|
243 result = val; |
|
244 } |
3608
|
245 |
1
|
246 return result; |
|
247 } |
|
248 |
|
249 static double |
164
|
250 pr_min_internal (const Matrix& m) |
1
|
251 { |
|
252 int nr = m.rows (); |
|
253 int nc = m.columns (); |
|
254 |
|
255 double result = DBL_MAX; |
|
256 |
|
257 for (int j = 0; j < nc; j++) |
|
258 for (int i = 0; i < nr; i++) |
|
259 { |
3608
|
260 double val = m(i,j); |
4025
|
261 if (xisinf (val) || octave_is_NaN_or_NA (val)) |
1
|
262 continue; |
|
263 |
|
264 if (val < result) |
|
265 result = val; |
|
266 } |
3608
|
267 |
1
|
268 return result; |
|
269 } |
|
270 |
1658
|
271 // XXX FIXME XXX -- it would be nice to share more code among these |
|
272 // functions,.. |
|
273 |
1
|
274 static void |
3611
|
275 set_real_format (bool sign, int digits, bool inf_or_nan, bool int_only, |
1658
|
276 int &fw) |
1
|
277 { |
3608
|
278 static float_format fmt; |
1
|
279 |
2165
|
280 int prec = Voutput_precision; |
1
|
281 |
|
282 int ld, rd; |
|
283 |
|
284 if (bank_format) |
|
285 { |
|
286 fw = digits < 0 ? 4 : digits + 3; |
|
287 if (inf_or_nan && fw < 3) |
|
288 fw = 3; |
|
289 fw += sign; |
|
290 rd = 2; |
|
291 } |
1282
|
292 else if (hex_format) |
|
293 { |
|
294 fw = 2 * sizeof (double); |
|
295 rd = 0; |
|
296 } |
1309
|
297 else if (bit_format) |
|
298 { |
|
299 fw = 8 * sizeof (double); |
|
300 rd = 0; |
|
301 } |
3611
|
302 else if (inf_or_nan || int_only) |
1
|
303 { |
|
304 fw = digits; |
|
305 if (inf_or_nan && fw < 3) |
|
306 fw = 3; |
|
307 fw += sign; |
3682
|
308 rd = fw; |
1
|
309 } |
|
310 else |
|
311 { |
|
312 if (digits > 0) |
|
313 { |
|
314 ld = digits; |
1658
|
315 rd = prec > digits ? prec - digits : prec; |
1
|
316 digits++; |
|
317 } |
|
318 else |
|
319 { |
|
320 ld = 1; |
1658
|
321 rd = prec > digits ? prec - digits : prec; |
1
|
322 digits = -digits + 1; |
|
323 } |
|
324 |
|
325 fw = ld + 1 + rd; |
|
326 if (inf_or_nan && fw < 3) |
|
327 fw = 3; |
|
328 fw += sign; |
|
329 } |
|
330 |
1309
|
331 if (! (bank_format || hex_format || bit_format) |
4509
|
332 && (fw > Voutput_max_field_width || print_e || print_g)) |
1
|
333 { |
4509
|
334 if (print_g) |
|
335 fmt = float_format (); |
|
336 else |
|
337 { |
|
338 int exp_field = 4; |
|
339 if (digits > 100) |
|
340 exp_field++; |
1
|
341 |
4509
|
342 fw = 2 + prec + exp_field; |
|
343 if (inf_or_nan && fw < 3) |
|
344 fw = 3; |
|
345 fw += sign; |
1
|
346 |
4509
|
347 fmt = float_format (fw, prec - 1, std::ios::scientific); |
|
348 } |
3608
|
349 |
1
|
350 if (print_big_e) |
3608
|
351 fmt.uppercase (); |
1
|
352 } |
3611
|
353 else if (inf_or_nan || int_only) |
|
354 fmt = float_format (fw, rd); |
1
|
355 else |
3608
|
356 fmt = float_format (fw, rd, std::ios::fixed); |
1
|
357 |
3608
|
358 curr_real_fmt = &fmt; |
1
|
359 } |
|
360 |
1658
|
361 static void |
|
362 set_format (double d, int& fw) |
|
363 { |
|
364 curr_real_fmt = 0; |
|
365 curr_imag_fmt = 0; |
|
366 |
|
367 if (free_format) |
|
368 return; |
|
369 |
2387
|
370 bool sign = (d < 0.0); |
1658
|
371 |
2387
|
372 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658
|
373 |
3611
|
374 bool int_only = (! inf_or_nan && D_NINT (d) == d); |
1658
|
375 |
|
376 double d_abs = d < 0.0 ? -d : d; |
|
377 |
2800
|
378 int digits = (inf_or_nan || d_abs == 0.0) |
|
379 ? 0 : static_cast<int> (floor (log10 (d_abs) + 1.0)); |
1658
|
380 |
3611
|
381 set_real_format (sign, digits, inf_or_nan, int_only, fw); |
1658
|
382 } |
|
383 |
1
|
384 static inline void |
|
385 set_format (double d) |
|
386 { |
|
387 int fw; |
|
388 set_format (d, fw); |
|
389 } |
|
390 |
|
391 static void |
2387
|
392 set_real_matrix_format (bool sign, int x_max, int x_min, |
|
393 bool inf_or_nan, int int_or_inf_or_nan, int& fw) |
1
|
394 { |
3608
|
395 static float_format fmt; |
1
|
396 |
2165
|
397 int prec = Voutput_precision; |
1
|
398 |
|
399 int ld, rd; |
|
400 |
|
401 if (bank_format) |
|
402 { |
|
403 int digits = x_max > x_min ? x_max : x_min; |
|
404 fw = digits <= 0 ? 4 : digits + 3; |
|
405 if (inf_or_nan && fw < 3) |
|
406 fw = 3; |
|
407 fw += sign; |
|
408 rd = 2; |
|
409 } |
1282
|
410 else if (hex_format) |
|
411 { |
|
412 fw = 2 * sizeof (double); |
|
413 rd = 0; |
|
414 } |
1309
|
415 else if (bit_format) |
|
416 { |
|
417 fw = 8 * sizeof (double); |
|
418 rd = 0; |
|
419 } |
4509
|
420 else if (Vfixed_point_format && ! print_g) |
3268
|
421 { |
|
422 rd = prec; |
|
423 fw = rd + 2; |
|
424 if (inf_or_nan && fw < 3) |
|
425 fw = 3; |
|
426 fw += sign; |
|
427 } |
1715
|
428 else if (int_or_inf_or_nan) |
1
|
429 { |
|
430 int digits = x_max > x_min ? x_max : x_min; |
|
431 fw = digits <= 0 ? 1 : digits; |
|
432 if (inf_or_nan && fw < 3) |
|
433 fw = 3; |
|
434 fw += sign; |
3682
|
435 rd = fw; |
1
|
436 } |
|
437 else |
|
438 { |
|
439 int ld_max, rd_max; |
|
440 if (x_max > 0) |
|
441 { |
|
442 ld_max = x_max; |
1658
|
443 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
444 x_max++; |
|
445 } |
|
446 else |
|
447 { |
|
448 ld_max = 1; |
1658
|
449 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
450 x_max = -x_max + 1; |
|
451 } |
|
452 |
|
453 int ld_min, rd_min; |
|
454 if (x_min > 0) |
|
455 { |
|
456 ld_min = x_min; |
1658
|
457 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
458 x_min++; |
|
459 } |
|
460 else |
|
461 { |
|
462 ld_min = 1; |
1658
|
463 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
464 x_min = -x_min + 1; |
|
465 } |
|
466 |
|
467 ld = ld_max > ld_min ? ld_max : ld_min; |
|
468 rd = rd_max > rd_min ? rd_max : rd_min; |
|
469 |
|
470 fw = ld + 1 + rd; |
|
471 if (inf_or_nan && fw < 3) |
|
472 fw = 3; |
|
473 fw += sign; |
|
474 } |
|
475 |
1658
|
476 if (! (bank_format || hex_format || bit_format) |
3105
|
477 && (print_e |
4509
|
478 || print_g |
3105
|
479 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1
|
480 { |
4509
|
481 if (print_g) |
|
482 fmt = float_format (); |
|
483 else |
|
484 { |
|
485 int exp_field = 4; |
|
486 if (x_max > 100 || x_min > 100) |
|
487 exp_field++; |
1
|
488 |
4509
|
489 fw = 2 + prec + exp_field; |
|
490 if (inf_or_nan && fw < 3) |
|
491 fw = 3; |
|
492 fw += sign; |
1
|
493 |
4509
|
494 fmt = float_format (fw, prec - 1, std::ios::scientific); |
|
495 } |
3608
|
496 |
1
|
497 if (print_big_e) |
3608
|
498 fmt.uppercase (); |
1
|
499 } |
3611
|
500 else if (int_or_inf_or_nan) |
|
501 fmt = float_format (fw, rd); |
1
|
502 else |
3608
|
503 fmt = float_format (fw, rd, std::ios::fixed); |
1
|
504 |
3608
|
505 curr_real_fmt = &fmt; |
1
|
506 } |
|
507 |
1658
|
508 static void |
3105
|
509 set_format (const Matrix& m, int& fw, double& scale) |
1658
|
510 { |
|
511 curr_real_fmt = 0; |
|
512 curr_imag_fmt = 0; |
|
513 |
|
514 if (free_format) |
|
515 return; |
|
516 |
4431
|
517 bool sign = m.any_element_is_negative (true); |
1658
|
518 |
2387
|
519 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658
|
520 |
2387
|
521 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658
|
522 |
2387
|
523 Matrix m_abs = m.abs (); |
1658
|
524 double max_abs = pr_max_internal (m_abs); |
|
525 double min_abs = pr_min_internal (m_abs); |
|
526 |
2800
|
527 int x_max = max_abs == 0.0 |
|
528 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); |
|
529 |
|
530 int x_min = min_abs == 0.0 |
|
531 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); |
1658
|
532 |
4270
|
533 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105
|
534 |
1658
|
535 set_real_matrix_format (sign, x_max, x_min, inf_or_nan, |
1715
|
536 int_or_inf_or_nan, fw); |
1658
|
537 } |
|
538 |
1
|
539 static inline void |
164
|
540 set_format (const Matrix& m) |
1
|
541 { |
|
542 int fw; |
3105
|
543 double scale; |
|
544 set_format (m, fw, scale); |
1
|
545 } |
|
546 |
|
547 static void |
2387
|
548 set_complex_format (bool sign, int x_max, int x_min, int r_x, |
|
549 bool inf_or_nan, int int_only, int& r_fw, int& i_fw) |
1
|
550 { |
3608
|
551 static float_format r_fmt; |
|
552 static float_format i_fmt; |
1
|
553 |
2165
|
554 int prec = Voutput_precision; |
1
|
555 |
|
556 int ld, rd; |
|
557 |
|
558 if (bank_format) |
|
559 { |
|
560 int digits = r_x; |
|
561 i_fw = 0; |
|
562 r_fw = digits <= 0 ? 4 : digits + 3; |
|
563 if (inf_or_nan && r_fw < 3) |
|
564 r_fw = 3; |
|
565 r_fw += sign; |
|
566 rd = 2; |
|
567 } |
1282
|
568 else if (hex_format) |
|
569 { |
|
570 r_fw = 2 * sizeof (double); |
|
571 i_fw = 2 * sizeof (double); |
|
572 rd = 0; |
|
573 } |
1309
|
574 else if (bit_format) |
|
575 { |
|
576 r_fw = 8 * sizeof (double); |
|
577 i_fw = 8 * sizeof (double); |
|
578 rd = 0; |
|
579 } |
1658
|
580 else if (inf_or_nan || int_only) |
1
|
581 { |
|
582 int digits = x_max > x_min ? x_max : x_min; |
|
583 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
584 if (inf_or_nan && i_fw < 3) |
|
585 i_fw = r_fw = 3; |
|
586 r_fw += sign; |
3682
|
587 rd = r_fw; |
1
|
588 } |
|
589 else |
|
590 { |
|
591 int ld_max, rd_max; |
|
592 if (x_max > 0) |
|
593 { |
|
594 ld_max = x_max; |
1658
|
595 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
596 x_max++; |
|
597 } |
|
598 else |
|
599 { |
|
600 ld_max = 1; |
1658
|
601 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
602 x_max = -x_max + 1; |
|
603 } |
|
604 |
|
605 int ld_min, rd_min; |
|
606 if (x_min > 0) |
|
607 { |
|
608 ld_min = x_min; |
1658
|
609 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
610 x_min++; |
|
611 } |
|
612 else |
|
613 { |
|
614 ld_min = 1; |
1658
|
615 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
616 x_min = -x_min + 1; |
|
617 } |
|
618 |
|
619 ld = ld_max > ld_min ? ld_max : ld_min; |
|
620 rd = rd_max > rd_min ? rd_max : rd_min; |
|
621 |
|
622 i_fw = r_fw = ld + 1 + rd; |
|
623 if (inf_or_nan && i_fw < 3) |
|
624 i_fw = r_fw = 3; |
|
625 r_fw += sign; |
|
626 } |
|
627 |
1309
|
628 if (! (bank_format || hex_format || bit_format) |
4509
|
629 && (r_fw > Voutput_max_field_width || print_e || print_g)) |
1
|
630 { |
4509
|
631 if (print_g) |
|
632 { |
|
633 r_fmt = float_format (); |
|
634 i_fmt = float_format (); |
|
635 } |
|
636 else |
|
637 { |
|
638 int exp_field = 4; |
|
639 if (x_max > 100 || x_min > 100) |
|
640 exp_field++; |
1
|
641 |
4509
|
642 i_fw = r_fw = 1 + prec + exp_field; |
|
643 if (inf_or_nan && i_fw < 3) |
|
644 i_fw = r_fw = 3; |
|
645 r_fw += sign; |
1
|
646 |
4509
|
647 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
|
648 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); |
|
649 } |
3608
|
650 |
1
|
651 if (print_big_e) |
|
652 { |
3608
|
653 r_fmt.uppercase (); |
|
654 i_fmt.uppercase (); |
1
|
655 } |
|
656 } |
3611
|
657 else if (inf_or_nan || int_only) |
|
658 { |
|
659 r_fmt = float_format (r_fw, rd); |
|
660 i_fmt = float_format (i_fw, rd); |
|
661 } |
1
|
662 else |
|
663 { |
3608
|
664 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
|
665 i_fmt = float_format (i_fw, rd, std::ios::fixed); |
1
|
666 } |
|
667 |
3608
|
668 curr_real_fmt = &r_fmt; |
|
669 curr_imag_fmt = &i_fmt; |
1
|
670 } |
|
671 |
1658
|
672 static void |
|
673 set_format (const Complex& c, int& r_fw, int& i_fw) |
|
674 { |
|
675 curr_real_fmt = 0; |
|
676 curr_imag_fmt = 0; |
|
677 |
|
678 if (free_format) |
|
679 return; |
|
680 |
|
681 double rp = c.real (); |
|
682 double ip = c.imag (); |
|
683 |
2387
|
684 bool sign = (rp < 0.0); |
1658
|
685 |
2387
|
686 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658
|
687 |
2387
|
688 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658
|
689 |
|
690 double r_abs = rp < 0.0 ? -rp : rp; |
|
691 double i_abs = ip < 0.0 ? -ip : ip; |
|
692 |
2800
|
693 int r_x = r_abs == 0.0 |
|
694 ? 0 : static_cast<int> (floor (log10 (r_abs) + 1.0)); |
|
695 |
|
696 int i_x = i_abs == 0.0 |
|
697 ? 0 : static_cast<int> (floor (log10 (i_abs) + 1.0)); |
1658
|
698 |
|
699 int x_max, x_min; |
|
700 |
|
701 if (r_x > i_x) |
|
702 { |
|
703 x_max = r_x; |
|
704 x_min = i_x; |
|
705 } |
|
706 else |
|
707 { |
|
708 x_max = i_x; |
|
709 x_min = r_x; |
|
710 } |
|
711 |
|
712 set_complex_format (sign, x_max, x_min, r_x, inf_or_nan, int_only, |
|
713 r_fw, i_fw); |
|
714 } |
|
715 |
1
|
716 static inline void |
164
|
717 set_format (const Complex& c) |
1
|
718 { |
|
719 int r_fw, i_fw; |
|
720 set_format (c, r_fw, i_fw); |
|
721 } |
|
722 |
|
723 static void |
2387
|
724 set_complex_matrix_format (bool sign, int x_max, int x_min, |
|
725 int r_x_max, int r_x_min, bool inf_or_nan, |
1715
|
726 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1
|
727 { |
3608
|
728 static float_format r_fmt; |
|
729 static float_format i_fmt; |
1
|
730 |
2165
|
731 int prec = Voutput_precision; |
1
|
732 |
|
733 int ld, rd; |
|
734 |
|
735 if (bank_format) |
|
736 { |
|
737 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; |
|
738 i_fw = 0; |
|
739 r_fw = digits <= 0 ? 4 : digits + 3; |
|
740 if (inf_or_nan && i_fw < 3) |
|
741 i_fw = r_fw = 3; |
|
742 r_fw += sign; |
|
743 rd = 2; |
|
744 } |
1282
|
745 else if (hex_format) |
|
746 { |
|
747 r_fw = 2 * sizeof (double); |
|
748 i_fw = 2 * sizeof (double); |
|
749 rd = 0; |
|
750 } |
1309
|
751 else if (bit_format) |
|
752 { |
|
753 r_fw = 8 * sizeof (double); |
|
754 i_fw = 8 * sizeof (double); |
|
755 rd = 0; |
|
756 } |
4509
|
757 else if (Vfixed_point_format && ! print_g) |
3268
|
758 { |
|
759 rd = prec; |
|
760 i_fw = r_fw = rd + 2; |
|
761 if (inf_or_nan && i_fw < 3) |
|
762 i_fw = r_fw = 3; |
|
763 r_fw += sign; |
|
764 } |
1715
|
765 else if (int_or_inf_or_nan) |
1
|
766 { |
|
767 int digits = x_max > x_min ? x_max : x_min; |
|
768 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
769 if (inf_or_nan && i_fw < 3) |
|
770 i_fw = r_fw = 3; |
|
771 r_fw += sign; |
3682
|
772 rd = r_fw; |
1
|
773 } |
|
774 else |
|
775 { |
|
776 int ld_max, rd_max; |
|
777 if (x_max > 0) |
|
778 { |
|
779 ld_max = x_max; |
1658
|
780 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
781 x_max++; |
|
782 } |
|
783 else |
|
784 { |
|
785 ld_max = 1; |
1658
|
786 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
787 x_max = -x_max + 1; |
|
788 } |
|
789 |
|
790 int ld_min, rd_min; |
|
791 if (x_min > 0) |
|
792 { |
|
793 ld_min = x_min; |
1658
|
794 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
795 x_min++; |
|
796 } |
|
797 else |
|
798 { |
|
799 ld_min = 1; |
1658
|
800 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
801 x_min = -x_min + 1; |
|
802 } |
|
803 |
|
804 ld = ld_max > ld_min ? ld_max : ld_min; |
|
805 rd = rd_max > rd_min ? rd_max : rd_min; |
|
806 |
|
807 i_fw = r_fw = ld + 1 + rd; |
|
808 if (inf_or_nan && i_fw < 3) |
|
809 i_fw = r_fw = 3; |
|
810 r_fw += sign; |
|
811 } |
|
812 |
1309
|
813 if (! (bank_format || hex_format || bit_format) |
3105
|
814 && (print_e |
4509
|
815 || print_g |
3105
|
816 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1
|
817 { |
4509
|
818 if (print_g) |
|
819 { |
|
820 r_fmt = float_format (); |
|
821 i_fmt = float_format (); |
|
822 } |
|
823 else |
|
824 { |
|
825 int exp_field = 4; |
|
826 if (x_max > 100 || x_min > 100) |
|
827 exp_field++; |
1
|
828 |
4509
|
829 i_fw = r_fw = 1 + prec + exp_field; |
|
830 if (inf_or_nan && i_fw < 3) |
|
831 i_fw = r_fw = 3; |
|
832 r_fw += sign; |
1
|
833 |
4509
|
834 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
|
835 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); |
|
836 } |
3608
|
837 |
1
|
838 if (print_big_e) |
|
839 { |
3608
|
840 r_fmt.uppercase (); |
|
841 i_fmt.uppercase (); |
1
|
842 } |
|
843 } |
3611
|
844 else if (int_or_inf_or_nan) |
|
845 { |
|
846 r_fmt = float_format (r_fw, rd); |
|
847 i_fmt = float_format (i_fw, rd); |
|
848 } |
1
|
849 else |
|
850 { |
3608
|
851 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
|
852 i_fmt = float_format (i_fw, rd, std::ios::fixed); |
1
|
853 } |
|
854 |
3608
|
855 curr_real_fmt = &r_fmt; |
|
856 curr_imag_fmt = &i_fmt; |
1
|
857 } |
|
858 |
1658
|
859 static void |
3105
|
860 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658
|
861 { |
|
862 curr_real_fmt = 0; |
|
863 curr_imag_fmt = 0; |
|
864 |
|
865 if (free_format) |
|
866 return; |
|
867 |
|
868 Matrix rp = real (cm); |
|
869 Matrix ip = imag (cm); |
|
870 |
4431
|
871 bool sign = rp.any_element_is_negative (true); |
1658
|
872 |
2387
|
873 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658
|
874 |
2387
|
875 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () |
|
876 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658
|
877 |
2387
|
878 Matrix r_m_abs = rp.abs (); |
1658
|
879 double r_max_abs = pr_max_internal (r_m_abs); |
|
880 double r_min_abs = pr_min_internal (r_m_abs); |
|
881 |
2387
|
882 Matrix i_m_abs = ip.abs (); |
1658
|
883 double i_max_abs = pr_max_internal (i_m_abs); |
|
884 double i_min_abs = pr_min_internal (i_m_abs); |
|
885 |
2800
|
886 int r_x_max = r_max_abs == 0.0 |
|
887 ? 0 : static_cast<int> (floor (log10 (r_max_abs) + 1.0)); |
|
888 |
|
889 int r_x_min = r_min_abs == 0.0 |
|
890 ? 0 : static_cast<int> (floor (log10 (r_min_abs) + 1.0)); |
1658
|
891 |
2800
|
892 int i_x_max = i_max_abs == 0.0 |
|
893 ? 0 : static_cast<int> (floor (log10 (i_max_abs) + 1.0)); |
|
894 |
|
895 int i_x_min = i_min_abs == 0.0 |
|
896 ? 0 : static_cast<int> (floor (log10 (i_min_abs) + 1.0)); |
1658
|
897 |
|
898 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; |
|
899 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; |
|
900 |
4270
|
901 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105
|
902 |
1658
|
903 set_complex_matrix_format (sign, x_max, x_min, r_x_max, r_x_min, |
1715
|
904 inf_or_nan, int_or_inf_or_nan, r_fw, i_fw); |
1658
|
905 } |
|
906 |
1
|
907 static inline void |
164
|
908 set_format (const ComplexMatrix& cm) |
1
|
909 { |
|
910 int r_fw, i_fw; |
3105
|
911 double scale; |
|
912 set_format (cm, r_fw, i_fw, scale); |
1
|
913 } |
|
914 |
|
915 static void |
3608
|
916 set_range_format (bool sign, int x_max, int x_min, int all_ints, int& fw) |
1
|
917 { |
3608
|
918 static float_format fmt; |
1
|
919 |
2165
|
920 int prec = Voutput_precision; |
1
|
921 |
|
922 int ld, rd; |
|
923 |
|
924 if (bank_format) |
|
925 { |
|
926 int digits = x_max > x_min ? x_max : x_min; |
|
927 fw = sign + digits < 0 ? 4 : digits + 3; |
|
928 rd = 2; |
|
929 } |
1282
|
930 else if (hex_format) |
|
931 { |
|
932 fw = 2 * sizeof (double); |
|
933 rd = 0; |
|
934 } |
1309
|
935 else if (bit_format) |
|
936 { |
|
937 fw = 8 * sizeof (double); |
|
938 rd = 0; |
|
939 } |
1658
|
940 else if (all_ints) |
1
|
941 { |
|
942 int digits = x_max > x_min ? x_max : x_min; |
|
943 fw = sign + digits; |
3682
|
944 rd = fw; |
1
|
945 } |
4509
|
946 else if (Vfixed_point_format && ! print_g) |
3105
|
947 { |
|
948 rd = prec; |
|
949 fw = rd + 2 + sign; |
|
950 } |
1
|
951 else |
|
952 { |
|
953 int ld_max, rd_max; |
|
954 if (x_max > 0) |
|
955 { |
|
956 ld_max = x_max; |
1658
|
957 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
958 x_max++; |
|
959 } |
|
960 else |
|
961 { |
|
962 ld_max = 1; |
1658
|
963 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
964 x_max = -x_max + 1; |
|
965 } |
|
966 |
|
967 int ld_min, rd_min; |
|
968 if (x_min > 0) |
|
969 { |
|
970 ld_min = x_min; |
1658
|
971 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
972 x_min++; |
|
973 } |
|
974 else |
|
975 { |
|
976 ld_min = 1; |
1658
|
977 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
978 x_min = -x_min + 1; |
|
979 } |
|
980 |
|
981 ld = ld_max > ld_min ? ld_max : ld_min; |
|
982 rd = rd_max > rd_min ? rd_max : rd_min; |
|
983 |
|
984 fw = sign + ld + 1 + rd; |
|
985 } |
|
986 |
1309
|
987 if (! (bank_format || hex_format || bit_format) |
3105
|
988 && (print_e |
4509
|
989 || print_g |
3105
|
990 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1
|
991 { |
4509
|
992 if (print_g) |
|
993 fmt = float_format (); |
|
994 else |
|
995 { |
|
996 int exp_field = 4; |
|
997 if (x_max > 100 || x_min > 100) |
|
998 exp_field++; |
1
|
999 |
4509
|
1000 fw = sign + 2 + prec + exp_field; |
1
|
1001 |
4509
|
1002 fmt = float_format (fw, prec - 1, std::ios::scientific); |
|
1003 } |
3608
|
1004 |
1
|
1005 if (print_big_e) |
3608
|
1006 fmt.uppercase (); |
1
|
1007 } |
3611
|
1008 else if (all_ints) |
|
1009 fmt = float_format (fw, rd); |
1
|
1010 else |
3608
|
1011 fmt = float_format (fw, rd, std::ios::fixed); |
1
|
1012 |
3608
|
1013 curr_real_fmt = &fmt; |
1
|
1014 } |
|
1015 |
1658
|
1016 static void |
3105
|
1017 set_format (const Range& r, int& fw, double& scale) |
1658
|
1018 { |
|
1019 curr_real_fmt = 0; |
|
1020 curr_imag_fmt = 0; |
|
1021 |
|
1022 if (free_format) |
|
1023 return; |
|
1024 |
|
1025 double r_min = r.base (); |
|
1026 double r_max = r.limit (); |
|
1027 |
|
1028 if (r_max < r_min) |
|
1029 { |
|
1030 double tmp = r_max; |
|
1031 r_max = r_min; |
|
1032 r_min = tmp; |
|
1033 } |
|
1034 |
2387
|
1035 bool sign = (r_min < 0.0); |
1658
|
1036 |
2387
|
1037 bool all_ints = r.all_elements_are_ints (); |
1658
|
1038 |
|
1039 double max_abs = r_max < 0.0 ? -r_max : r_max; |
|
1040 double min_abs = r_min < 0.0 ? -r_min : r_min; |
|
1041 |
2800
|
1042 int x_max = max_abs == 0.0 |
|
1043 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); |
|
1044 |
|
1045 int x_min = min_abs == 0.0 |
|
1046 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); |
1658
|
1047 |
4270
|
1048 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1); |
3105
|
1049 |
1658
|
1050 set_range_format (sign, x_max, x_min, all_ints, fw); |
|
1051 } |
|
1052 |
1
|
1053 static inline void |
164
|
1054 set_format (const Range& r) |
1
|
1055 { |
|
1056 int fw; |
3105
|
1057 double scale; |
|
1058 set_format (r, fw, scale); |
1
|
1059 } |
|
1060 |
1282
|
1061 union equiv |
|
1062 { |
|
1063 double d; |
|
1064 unsigned char i[sizeof (double)]; |
|
1065 }; |
|
1066 |
1309
|
1067 #define PRINT_CHAR_BITS(os, c) \ |
|
1068 do \ |
|
1069 { \ |
|
1070 unsigned char ctmp = c; \ |
|
1071 char stmp[9]; \ |
1488
|
1072 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
|
1073 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ |
|
1074 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ |
|
1075 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ |
|
1076 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ |
|
1077 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ |
|
1078 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ |
|
1079 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ |
1309
|
1080 stmp[8] = '\0'; \ |
3013
|
1081 os << stmp; \ |
1309
|
1082 } \ |
|
1083 while (0) |
|
1084 |
|
1085 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ |
|
1086 do \ |
|
1087 { \ |
|
1088 unsigned char ctmp = c; \ |
|
1089 char stmp[9]; \ |
1488
|
1090 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
|
1091 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ |
|
1092 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ |
|
1093 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ |
|
1094 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ |
|
1095 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ |
|
1096 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ |
|
1097 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ |
1309
|
1098 stmp[8] = '\0'; \ |
3013
|
1099 os << stmp; \ |
1309
|
1100 } \ |
|
1101 while (0) |
|
1102 |
2522
|
1103 static void |
3608
|
1104 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0) |
1
|
1105 { |
529
|
1106 if (fmt) |
1
|
1107 { |
1282
|
1108 if (hex_format) |
|
1109 { |
|
1110 equiv tmp; |
|
1111 tmp.d = d; |
|
1112 |
|
1113 // Unless explicitly asked for, always print in big-endian |
|
1114 // format. |
|
1115 |
|
1116 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
1117 // formats and not for Cray? |
|
1118 |
3013
|
1119 // XXX FIXME XXX -- will bad things happen if we are |
|
1120 // interrupted before resetting the format flags and fill |
|
1121 // character? |
|
1122 |
2317
|
1123 oct_mach_info::float_format flt_fmt = |
|
1124 oct_mach_info::native_float_format (); |
|
1125 |
3013
|
1126 char ofill = os.fill ('0'); |
|
1127 |
3608
|
1128 std::ios::fmtflags oflags |
|
1129 = os.flags (std::ios::right | std::ios::hex); |
3013
|
1130 |
1282
|
1131 if (hex_format > 1 |
4574
|
1132 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
|
1133 || flt_fmt == oct_mach_info::flt_fmt_cray |
|
1134 || flt_fmt == oct_mach_info::flt_fmt_unknown) |
1282
|
1135 { |
1322
|
1136 for (size_t i = 0; i < sizeof (double); i++) |
3548
|
1137 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282
|
1138 } |
|
1139 else |
|
1140 { |
1328
|
1141 for (int i = sizeof (double) - 1; i >= 0; i--) |
3548
|
1142 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282
|
1143 } |
3013
|
1144 |
|
1145 os.fill (ofill); |
|
1146 os.setf (oflags); |
1282
|
1147 } |
1309
|
1148 else if (bit_format) |
|
1149 { |
|
1150 equiv tmp; |
|
1151 tmp.d = d; |
|
1152 |
|
1153 // Unless explicitly asked for, always print in big-endian |
|
1154 // format. |
|
1155 |
|
1156 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
1157 // formats and not for Cray? |
|
1158 |
2317
|
1159 oct_mach_info::float_format flt_fmt = |
|
1160 oct_mach_info::native_float_format (); |
|
1161 |
4574
|
1162 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
|
1163 || flt_fmt == oct_mach_info::flt_fmt_cray |
|
1164 || flt_fmt == oct_mach_info::flt_fmt_unknown) |
1309
|
1165 { |
1322
|
1166 for (size_t i = 0; i < sizeof (double); i++) |
1309
|
1167 PRINT_CHAR_BITS (os, tmp.i[i]); |
|
1168 } |
|
1169 else |
|
1170 { |
|
1171 if (bit_format > 1) |
|
1172 { |
1328
|
1173 for (size_t i = 0; i < sizeof (double); i++) |
1309
|
1174 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
|
1175 } |
|
1176 else |
|
1177 { |
|
1178 for (int i = sizeof (double) - 1; i >= 0; i--) |
|
1179 PRINT_CHAR_BITS (os, tmp.i[i]); |
|
1180 } |
|
1181 } |
|
1182 } |
1282
|
1183 else if (xisinf (d)) |
1
|
1184 { |
2804
|
1185 const char *s; |
1
|
1186 if (d < 0.0) |
|
1187 s = "-Inf"; |
|
1188 else |
|
1189 s = "Inf"; |
|
1190 |
|
1191 if (fw > 0) |
3548
|
1192 os << std::setw (fw) << s; |
1
|
1193 else |
|
1194 os << s; |
|
1195 } |
4025
|
1196 else if (octave_is_NA (d)) |
|
1197 { |
|
1198 if (fw > 0) |
|
1199 os << std::setw (fw) << "NA"; |
|
1200 else |
|
1201 os << "NA"; |
|
1202 } |
1
|
1203 else if (xisnan (d)) |
|
1204 { |
|
1205 if (fw > 0) |
3548
|
1206 os << std::setw (fw) << "NaN"; |
1
|
1207 else |
|
1208 os << "NaN"; |
|
1209 } |
|
1210 else |
3608
|
1211 os << pr_formatted_float (*fmt, d); |
1
|
1212 } |
529
|
1213 else |
|
1214 os << d; |
1
|
1215 } |
|
1216 |
|
1217 static inline void |
3608
|
1218 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
1
|
1219 { |
4509
|
1220 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608
|
1221 d /= scale; |
|
1222 |
1
|
1223 pr_any_float (curr_real_fmt, os, d, fw); |
|
1224 } |
|
1225 |
|
1226 static inline void |
3523
|
1227 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1
|
1228 { |
|
1229 pr_any_float (curr_imag_fmt, os, d, fw); |
|
1230 } |
|
1231 |
2522
|
1232 static void |
3608
|
1233 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, |
|
1234 int i_fw = 0, double scale = 1.0) |
1
|
1235 { |
4509
|
1236 Complex tmp |
|
1237 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; |
3608
|
1238 |
|
1239 double r = tmp.real (); |
|
1240 |
1
|
1241 pr_float (os, r, r_fw); |
3608
|
1242 |
1
|
1243 if (! bank_format) |
|
1244 { |
3608
|
1245 double i = tmp.imag (); |
4349
|
1246 if (! (hex_format || bit_format) && lo_ieee_signbit (i)) |
1
|
1247 { |
|
1248 os << " - "; |
|
1249 i = -i; |
|
1250 pr_imag_float (os, i, i_fw); |
|
1251 } |
|
1252 else |
|
1253 { |
1309
|
1254 if (hex_format || bit_format) |
1282
|
1255 os << " "; |
|
1256 else |
|
1257 os << " + "; |
|
1258 |
1
|
1259 pr_imag_float (os, i, i_fw); |
|
1260 } |
|
1261 os << "i"; |
|
1262 } |
|
1263 } |
|
1264 |
626
|
1265 static void |
3523
|
1266 print_empty_matrix (std::ostream& os, int nr, int nc, bool pr_as_read_syntax) |
626
|
1267 { |
|
1268 assert (nr == 0 || nc == 0); |
|
1269 |
|
1270 if (pr_as_read_syntax) |
|
1271 { |
|
1272 if (nr == 0 && nc == 0) |
|
1273 os << "[]"; |
|
1274 else |
|
1275 os << "zeros (" << nr << ", " << nc << ")"; |
|
1276 } |
|
1277 else |
|
1278 { |
|
1279 os << "[]"; |
4559
|
1280 |
2165
|
1281 if (Vprint_empty_dimensions) |
626
|
1282 os << "(" << nr << "x" << nc << ")"; |
|
1283 } |
|
1284 } |
|
1285 |
1186
|
1286 static void |
4559
|
1287 print_empty_nd_array (std::ostream& os, const dim_vector& dims, |
|
1288 bool pr_as_read_syntax) |
|
1289 { |
|
1290 assert (dims.any_zero ()); |
|
1291 |
|
1292 if (pr_as_read_syntax) |
|
1293 os << "zeros (" << dims.str (',') << ")"; |
|
1294 else |
|
1295 { |
|
1296 os << "[]"; |
|
1297 |
|
1298 if (Vprint_empty_dimensions) |
|
1299 os << "(" << dims.str () << ")"; |
|
1300 } |
|
1301 } |
|
1302 |
|
1303 static void |
3523
|
1304 pr_scale_header (std::ostream& os, double scale) |
3105
|
1305 { |
4509
|
1306 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105
|
1307 { |
3568
|
1308 os << " " |
|
1309 << std::setw (8) << std::setprecision (1) |
|
1310 << std::setiosflags (std::ios::scientific|std::ios::left) |
|
1311 << scale |
|
1312 << std::resetiosflags (std::ios::scientific|std::ios::left) |
|
1313 << " *\n"; |
3105
|
1314 |
|
1315 if (! compact_format) |
|
1316 os << "\n"; |
|
1317 } |
|
1318 } |
|
1319 |
|
1320 static void |
3523
|
1321 pr_col_num_header (std::ostream& os, int total_width, int max_width, |
1972
|
1322 int lim, int col, int extra_indent) |
1186
|
1323 { |
2165
|
1324 if (total_width > max_width && Vsplit_long_rows) |
1186
|
1325 { |
|
1326 if (col != 0 && ! compact_format) |
2915
|
1327 os << "\n\n"; |
1186
|
1328 |
|
1329 int num_cols = lim - col; |
|
1330 |
3548
|
1331 os << std::setw (extra_indent) << ""; |
1972
|
1332 |
1186
|
1333 if (num_cols == 1) |
|
1334 os << " Column " << col + 1 << ":\n"; |
|
1335 else if (num_cols == 2) |
|
1336 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
|
1337 else |
|
1338 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915
|
1339 |
|
1340 if (! compact_format) |
|
1341 os << "\n"; |
1186
|
1342 } |
|
1343 } |
|
1344 |
3248
|
1345 static inline void |
3608
|
1346 pr_plus_format (std::ostream& os, double d) |
3248
|
1347 { |
4632
|
1348 if (d > 0.0) |
|
1349 os << plus_format_chars[0]; |
3248
|
1350 else if (d < 0.0) |
4632
|
1351 os << plus_format_chars[1]; |
3248
|
1352 else |
4632
|
1353 os << plus_format_chars[2]; |
3248
|
1354 } |
|
1355 |
1
|
1356 void |
3523
|
1357 octave_print_internal (std::ostream& os, double d, bool pr_as_read_syntax) |
1
|
1358 { |
|
1359 if (plus_format) |
|
1360 { |
3608
|
1361 pr_plus_format (os, d); |
1
|
1362 } |
|
1363 else |
|
1364 { |
|
1365 set_format (d); |
|
1366 if (free_format) |
|
1367 os << d; |
|
1368 else |
|
1369 pr_float (os, d); |
|
1370 } |
|
1371 } |
|
1372 |
|
1373 void |
3608
|
1374 octave_print_internal (std::ostream& os, const Matrix& m, |
|
1375 bool pr_as_read_syntax, int extra_indent) |
1
|
1376 { |
|
1377 int nr = m.rows (); |
|
1378 int nc = m.columns (); |
|
1379 |
2408
|
1380 if (nr == 0 || nc == 0) |
626
|
1381 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1382 else if (plus_format && ! pr_as_read_syntax) |
1
|
1383 { |
|
1384 for (int i = 0; i < nr; i++) |
|
1385 { |
|
1386 for (int j = 0; j < nc; j++) |
|
1387 { |
4153
|
1388 OCTAVE_QUIT; |
|
1389 |
3608
|
1390 pr_plus_format (os, m(i,j)); |
1
|
1391 } |
2907
|
1392 |
|
1393 if (i < nr - 1) |
|
1394 os << "\n"; |
1
|
1395 } |
|
1396 } |
|
1397 else |
|
1398 { |
|
1399 int fw; |
3105
|
1400 double scale = 1.0; |
|
1401 set_format (m, fw, scale); |
1
|
1402 int column_width = fw + 2; |
|
1403 int total_width = nc * column_width; |
2926
|
1404 int max_width = command_editor::terminal_cols (); |
1
|
1405 |
626
|
1406 if (pr_as_read_syntax) |
|
1407 max_width -= 4; |
1972
|
1408 else |
|
1409 max_width -= extra_indent; |
|
1410 |
|
1411 if (max_width < 0) |
|
1412 max_width = 0; |
626
|
1413 |
1
|
1414 if (free_format) |
|
1415 { |
626
|
1416 if (pr_as_read_syntax) |
|
1417 os << "[\n"; |
|
1418 |
1
|
1419 os << m; |
626
|
1420 |
|
1421 if (pr_as_read_syntax) |
|
1422 os << "]"; |
|
1423 |
1
|
1424 return; |
|
1425 } |
|
1426 |
|
1427 int inc = nc; |
2165
|
1428 if (total_width > max_width && Vsplit_long_rows) |
1
|
1429 { |
|
1430 inc = max_width / column_width; |
|
1431 if (inc == 0) |
|
1432 inc++; |
|
1433 } |
|
1434 |
626
|
1435 if (pr_as_read_syntax) |
1
|
1436 { |
|
1437 for (int i = 0; i < nr; i++) |
|
1438 { |
626
|
1439 int col = 0; |
|
1440 while (col < nc) |
1
|
1441 { |
626
|
1442 int lim = col + inc < nc ? col + inc : nc; |
|
1443 |
|
1444 for (int j = col; j < lim; j++) |
|
1445 { |
4153
|
1446 OCTAVE_QUIT; |
|
1447 |
626
|
1448 if (i == 0 && j == 0) |
|
1449 os << "[ "; |
|
1450 else |
|
1451 { |
|
1452 if (j > col && j < lim) |
|
1453 os << ", "; |
|
1454 else |
|
1455 os << " "; |
|
1456 } |
|
1457 |
3608
|
1458 pr_float (os, m(i,j)); |
626
|
1459 } |
|
1460 |
|
1461 col += inc; |
|
1462 |
|
1463 if (col >= nc) |
|
1464 { |
|
1465 if (i == nr - 1) |
|
1466 os << " ]"; |
|
1467 else |
|
1468 os << ";\n"; |
|
1469 } |
|
1470 else |
|
1471 os << " ...\n"; |
1
|
1472 } |
|
1473 } |
626
|
1474 } |
|
1475 else |
|
1476 { |
3105
|
1477 pr_scale_header (os, scale); |
|
1478 |
626
|
1479 for (int col = 0; col < nc; col += inc) |
|
1480 { |
|
1481 int lim = col + inc < nc ? col + inc : nc; |
|
1482 |
1972
|
1483 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1484 extra_indent); |
626
|
1485 |
|
1486 for (int i = 0; i < nr; i++) |
|
1487 { |
3548
|
1488 os << std::setw (extra_indent) << ""; |
1972
|
1489 |
626
|
1490 for (int j = col; j < lim; j++) |
|
1491 { |
4153
|
1492 OCTAVE_QUIT; |
|
1493 |
626
|
1494 os << " "; |
|
1495 |
3608
|
1496 pr_float (os, m(i,j), fw, scale); |
626
|
1497 } |
|
1498 |
2907
|
1499 if (i < nr - 1) |
|
1500 os << "\n"; |
626
|
1501 } |
|
1502 } |
1
|
1503 } |
|
1504 } |
|
1505 } |
|
1506 |
4532
|
1507 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ |
|
1508 do \ |
|
1509 { \ |
4559
|
1510 if (nda.is_empty ()) \ |
|
1511 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \ |
|
1512 else \ |
|
1513 { \ |
4532
|
1514 \ |
4559
|
1515 int ndims = nda.ndims (); \ |
|
1516 \ |
|
1517 dim_vector dims = nda.dims (); \ |
4532
|
1518 \ |
4559
|
1519 Array<int> ra_idx (ndims, 0); \ |
4532
|
1520 \ |
4559
|
1521 int m = 1; \ |
4532
|
1522 \ |
4559
|
1523 for (int i = 2; i < ndims; i++) \ |
|
1524 m *= dims(i); \ |
|
1525 \ |
|
1526 int nr = dims(0); \ |
|
1527 int nc = dims(1); \ |
4532
|
1528 \ |
4559
|
1529 for (int i = 0; i < m; i++) \ |
|
1530 { \ |
4655
|
1531 OCTAVE_QUIT; \ |
|
1532 \ |
4559
|
1533 std::string nm = "ans"; \ |
4532
|
1534 \ |
4559
|
1535 if (m > 1) \ |
|
1536 { \ |
|
1537 nm += "(:,:,"; \ |
4532
|
1538 \ |
4559
|
1539 OSSTREAM buf; \ |
4532
|
1540 \ |
4559
|
1541 for (int k = 2; k < ndims; k++) \ |
|
1542 { \ |
|
1543 buf << ra_idx(k) + 1; \ |
4532
|
1544 \ |
4559
|
1545 if (k < ndims - 1) \ |
|
1546 buf << ","; \ |
|
1547 else \ |
|
1548 buf << ")"; \ |
|
1549 } \ |
4532
|
1550 \ |
4559
|
1551 buf << OSSTREAM_ENDS; \ |
4532
|
1552 \ |
4559
|
1553 nm += OSSTREAM_STR (buf); \ |
|
1554 \ |
|
1555 OSSTREAM_FREEZE (buf); \ |
|
1556 } \ |
4532
|
1557 \ |
4559
|
1558 Array<idx_vector> idx (ndims); \ |
4532
|
1559 \ |
4559
|
1560 idx(0) = idx_vector (':'); \ |
|
1561 idx(1) = idx_vector (':'); \ |
|
1562 \ |
|
1563 for (int k = 2; k < ndims; k++) \ |
|
1564 idx(k) = idx_vector (ra_idx(k) + 1); \ |
4532
|
1565 \ |
4559
|
1566 octave_value page \ |
|
1567 = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \ |
|
1568 \ |
|
1569 page.print_with_name (os, nm); \ |
4532
|
1570 \ |
4559
|
1571 if (i < m) \ |
|
1572 NDA_T::increment_index (ra_idx, dims, 2); \ |
|
1573 } \ |
|
1574 } \ |
4532
|
1575 } \ |
|
1576 while (0) |
|
1577 |
4513
|
1578 void |
|
1579 octave_print_internal (std::ostream& os, const NDArray& nda, |
|
1580 bool pr_as_read_syntax, int extra_indent) |
|
1581 { |
|
1582 switch (nda.ndims ()) |
|
1583 { |
|
1584 case 1: |
|
1585 case 2: |
|
1586 octave_print_internal (os, nda.matrix_value (), |
|
1587 pr_as_read_syntax, extra_indent); |
|
1588 break; |
|
1589 |
|
1590 default: |
4532
|
1591 PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix); |
4513
|
1592 break; |
|
1593 } |
|
1594 } |
|
1595 |
3248
|
1596 static inline void |
3608
|
1597 pr_plus_format (std::ostream& os, const Complex& c) |
3248
|
1598 { |
|
1599 double rp = c.real (); |
|
1600 double ip = c.imag (); |
|
1601 |
|
1602 if (rp == 0.0) |
|
1603 { |
|
1604 if (ip == 0.0) |
|
1605 os << " "; |
|
1606 else |
|
1607 os << "i"; |
|
1608 } |
|
1609 else if (ip == 0.0) |
3608
|
1610 pr_plus_format (os, rp); |
3248
|
1611 else |
|
1612 os << "c"; |
|
1613 } |
|
1614 |
1
|
1615 void |
3523
|
1616 octave_print_internal (std::ostream& os, const Complex& c, |
1972
|
1617 bool pr_as_read_syntax) |
1
|
1618 { |
|
1619 if (plus_format) |
|
1620 { |
3608
|
1621 pr_plus_format (os, c); |
1
|
1622 } |
|
1623 else |
|
1624 { |
|
1625 set_format (c); |
|
1626 if (free_format) |
|
1627 os << c; |
|
1628 else |
|
1629 pr_complex (os, c); |
|
1630 } |
|
1631 } |
|
1632 |
|
1633 void |
3523
|
1634 octave_print_internal (std::ostream& os, const ComplexMatrix& cm, |
1972
|
1635 bool pr_as_read_syntax, int extra_indent) |
1
|
1636 { |
|
1637 int nr = cm.rows (); |
|
1638 int nc = cm.columns (); |
|
1639 |
2408
|
1640 if (nr == 0 || nc == 0) |
626
|
1641 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1642 else if (plus_format && ! pr_as_read_syntax) |
1
|
1643 { |
|
1644 for (int i = 0; i < nr; i++) |
|
1645 { |
|
1646 for (int j = 0; j < nc; j++) |
|
1647 { |
4153
|
1648 OCTAVE_QUIT; |
|
1649 |
3608
|
1650 pr_plus_format (os, cm(i,j)); |
1
|
1651 } |
2907
|
1652 |
|
1653 if (i < nr - 1) |
|
1654 os << "\n"; |
1
|
1655 } |
|
1656 } |
|
1657 else |
|
1658 { |
|
1659 int r_fw, i_fw; |
3105
|
1660 double scale = 1.0; |
|
1661 set_format (cm, r_fw, i_fw, scale); |
1
|
1662 int column_width = i_fw + r_fw; |
1309
|
1663 column_width += (bank_format || hex_format|| bit_format) ? 2 : 7; |
1
|
1664 int total_width = nc * column_width; |
2926
|
1665 int max_width = command_editor::terminal_cols (); |
1
|
1666 |
626
|
1667 if (pr_as_read_syntax) |
|
1668 max_width -= 4; |
1972
|
1669 else |
|
1670 max_width -= extra_indent; |
|
1671 |
|
1672 if (max_width < 0) |
|
1673 max_width = 0; |
626
|
1674 |
1
|
1675 if (free_format) |
|
1676 { |
626
|
1677 if (pr_as_read_syntax) |
|
1678 os << "[\n"; |
|
1679 |
1
|
1680 os << cm; |
626
|
1681 |
|
1682 if (pr_as_read_syntax) |
|
1683 os << "]"; |
|
1684 |
1
|
1685 return; |
|
1686 } |
|
1687 |
|
1688 int inc = nc; |
2165
|
1689 if (total_width > max_width && Vsplit_long_rows) |
1
|
1690 { |
|
1691 inc = max_width / column_width; |
|
1692 if (inc == 0) |
|
1693 inc++; |
|
1694 } |
|
1695 |
626
|
1696 if (pr_as_read_syntax) |
1
|
1697 { |
|
1698 for (int i = 0; i < nr; i++) |
|
1699 { |
626
|
1700 int col = 0; |
|
1701 while (col < nc) |
1
|
1702 { |
626
|
1703 int lim = col + inc < nc ? col + inc : nc; |
|
1704 |
|
1705 for (int j = col; j < lim; j++) |
|
1706 { |
4153
|
1707 OCTAVE_QUIT; |
|
1708 |
626
|
1709 if (i == 0 && j == 0) |
|
1710 os << "[ "; |
|
1711 else |
|
1712 { |
|
1713 if (j > col && j < lim) |
|
1714 os << ", "; |
|
1715 else |
|
1716 os << " "; |
|
1717 } |
|
1718 |
3608
|
1719 pr_complex (os, cm(i,j)); |
626
|
1720 } |
|
1721 |
|
1722 col += inc; |
|
1723 |
|
1724 if (col >= nc) |
|
1725 { |
|
1726 if (i == nr - 1) |
|
1727 os << " ]"; |
|
1728 else |
|
1729 os << ";\n"; |
|
1730 } |
1
|
1731 else |
626
|
1732 os << " ...\n"; |
1
|
1733 } |
|
1734 } |
626
|
1735 } |
|
1736 else |
|
1737 { |
3105
|
1738 pr_scale_header (os, scale); |
|
1739 |
626
|
1740 for (int col = 0; col < nc; col += inc) |
|
1741 { |
|
1742 int lim = col + inc < nc ? col + inc : nc; |
|
1743 |
1972
|
1744 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1745 extra_indent); |
626
|
1746 |
|
1747 for (int i = 0; i < nr; i++) |
|
1748 { |
3548
|
1749 os << std::setw (extra_indent) << ""; |
1972
|
1750 |
626
|
1751 for (int j = col; j < lim; j++) |
|
1752 { |
4153
|
1753 OCTAVE_QUIT; |
|
1754 |
626
|
1755 os << " "; |
|
1756 |
3608
|
1757 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
626
|
1758 } |
2907
|
1759 |
|
1760 if (i < nr - 1) |
|
1761 os << "\n"; |
626
|
1762 } |
|
1763 } |
1
|
1764 } |
|
1765 } |
|
1766 } |
|
1767 |
|
1768 void |
4513
|
1769 octave_print_internal (std::ostream& os, const ComplexNDArray& nda, |
|
1770 bool pr_as_read_syntax, int extra_indent) |
|
1771 { |
|
1772 switch (nda.ndims ()) |
|
1773 { |
|
1774 case 1: |
|
1775 case 2: |
|
1776 octave_print_internal (os, nda.matrix_value (), |
|
1777 pr_as_read_syntax, extra_indent); |
|
1778 break; |
|
1779 |
|
1780 default: |
4532
|
1781 PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix); |
4513
|
1782 break; |
|
1783 } |
|
1784 } |
|
1785 |
|
1786 void |
3523
|
1787 octave_print_internal (std::ostream& os, const Range& r, |
1972
|
1788 bool pr_as_read_syntax, int extra_indent) |
1
|
1789 { |
626
|
1790 double base = r.base (); |
1
|
1791 double increment = r.inc (); |
626
|
1792 double limit = r.limit (); |
1
|
1793 int num_elem = r.nelem (); |
|
1794 |
626
|
1795 if (plus_format && ! pr_as_read_syntax) |
1
|
1796 { |
|
1797 for (int i = 0; i < num_elem; i++) |
|
1798 { |
4153
|
1799 OCTAVE_QUIT; |
|
1800 |
626
|
1801 double val = base + i * increment; |
4632
|
1802 |
|
1803 pr_plus_format (os, val); |
1
|
1804 } |
|
1805 } |
|
1806 else |
|
1807 { |
|
1808 int fw; |
3105
|
1809 double scale = 1.0; |
|
1810 set_format (r, fw, scale); |
1
|
1811 |
626
|
1812 if (pr_as_read_syntax) |
1
|
1813 { |
626
|
1814 if (free_format) |
|
1815 { |
|
1816 os << base << " : "; |
|
1817 if (increment != 1.0) |
|
1818 os << increment << " : "; |
|
1819 os << limit; |
|
1820 } |
|
1821 else |
|
1822 { |
|
1823 pr_float (os, base, fw); |
|
1824 os << " : "; |
|
1825 if (increment != 1.0) |
|
1826 { |
|
1827 pr_float (os, increment, fw); |
|
1828 os << " : "; |
|
1829 } |
|
1830 pr_float (os, limit, fw); |
|
1831 } |
1
|
1832 } |
626
|
1833 else |
|
1834 { |
|
1835 int column_width = fw + 2; |
|
1836 int total_width = num_elem * column_width; |
2926
|
1837 int max_width = command_editor::terminal_cols (); |
1
|
1838 |
626
|
1839 if (free_format) |
|
1840 { |
|
1841 os << r; |
|
1842 return; |
|
1843 } |
1
|
1844 |
626
|
1845 int inc = num_elem; |
2165
|
1846 if (total_width > max_width && Vsplit_long_rows) |
1
|
1847 { |
626
|
1848 inc = max_width / column_width; |
|
1849 if (inc == 0) |
|
1850 inc++; |
1
|
1851 } |
|
1852 |
1972
|
1853 max_width -= extra_indent; |
|
1854 |
|
1855 if (max_width < 0) |
|
1856 max_width = 0; |
|
1857 |
3105
|
1858 pr_scale_header (os, scale); |
|
1859 |
626
|
1860 int col = 0; |
|
1861 while (col < num_elem) |
1
|
1862 { |
626
|
1863 int lim = col + inc < num_elem ? col + inc : num_elem; |
|
1864 |
1972
|
1865 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1866 extra_indent); |
|
1867 |
3548
|
1868 os << std::setw (extra_indent) << ""; |
626
|
1869 |
|
1870 for (int i = col; i < lim; i++) |
|
1871 { |
4153
|
1872 OCTAVE_QUIT; |
|
1873 |
626
|
1874 double val = base + i * increment; |
3105
|
1875 |
626
|
1876 os << " "; |
3105
|
1877 |
3608
|
1878 pr_float (os, val, fw, scale); |
626
|
1879 } |
|
1880 |
2907
|
1881 col += inc; |
626
|
1882 |
2907
|
1883 if (col < num_elem) |
|
1884 os << "\n"; |
1
|
1885 } |
|
1886 } |
|
1887 } |
|
1888 } |
|
1889 |
1343
|
1890 void |
3523
|
1891 octave_print_internal (std::ostream& os, const boolMatrix& bm, |
3215
|
1892 bool pr_as_read_syntax, |
|
1893 int extra_indent) |
|
1894 { |
|
1895 Matrix tmp (bm); |
|
1896 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
|
1897 } |
|
1898 |
|
1899 void |
4513
|
1900 octave_print_internal (std::ostream& os, const boolNDArray& nda, |
|
1901 bool pr_as_read_syntax, |
|
1902 int extra_indent) |
|
1903 { |
|
1904 switch (nda.ndims ()) |
|
1905 { |
|
1906 case 1: |
|
1907 case 2: |
|
1908 octave_print_internal (os, nda.matrix_value (), |
|
1909 pr_as_read_syntax, extra_indent); |
|
1910 break; |
|
1911 |
|
1912 default: |
4532
|
1913 PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix); |
4513
|
1914 break; |
|
1915 } |
|
1916 } |
|
1917 |
|
1918 void |
3523
|
1919 octave_print_internal (std::ostream& os, const charMatrix& chm, |
3215
|
1920 bool pr_as_read_syntax, |
|
1921 int /* extra_indent XXX FIXME XXX */, |
|
1922 bool pr_as_string) |
1343
|
1923 { |
1572
|
1924 if (pr_as_string) |
|
1925 { |
|
1926 int nstr = chm.rows (); |
1343
|
1927 |
1572
|
1928 if (pr_as_read_syntax && nstr > 1) |
|
1929 os << "[ "; |
1343
|
1930 |
2907
|
1931 if (nstr != 0) |
1343
|
1932 { |
2664
|
1933 for (int i = 0; i < nstr; i++) |
1572
|
1934 { |
4153
|
1935 OCTAVE_QUIT; |
|
1936 |
3523
|
1937 std::string row = chm.row_as_string (i); |
2664
|
1938 |
|
1939 if (pr_as_read_syntax) |
|
1940 { |
|
1941 os << "\"" << undo_string_escapes (row) << "\""; |
1343
|
1942 |
2664
|
1943 if (i < nstr - 1) |
|
1944 os << "; "; |
|
1945 } |
|
1946 else |
2907
|
1947 { |
|
1948 os << row; |
|
1949 |
|
1950 if (i < nstr - 1) |
|
1951 os << "\n"; |
|
1952 } |
1572
|
1953 } |
1343
|
1954 } |
1572
|
1955 |
|
1956 if (pr_as_read_syntax && nstr > 1) |
|
1957 os << " ]"; |
1343
|
1958 } |
1572
|
1959 else |
|
1960 { |
|
1961 os << "sorry, printing char matrices not implemented yet\n"; |
|
1962 } |
1343
|
1963 } |
|
1964 |
4513
|
1965 void |
|
1966 octave_print_internal (std::ostream& os, const charNDArray& nda, |
|
1967 bool pr_as_read_syntax, int extra_indent, |
|
1968 bool pr_as_string) |
|
1969 { |
|
1970 switch (nda.ndims ()) |
|
1971 { |
|
1972 case 1: |
|
1973 case 2: |
|
1974 octave_print_internal (os, nda.matrix_value (), |
|
1975 pr_as_read_syntax, extra_indent, pr_as_string); |
|
1976 break; |
|
1977 |
|
1978 default: |
4532
|
1979 PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix); |
4513
|
1980 break; |
|
1981 } |
|
1982 } |
|
1983 |
4655
|
1984 void |
|
1985 octave_print_internal (std::ostream& os, const ArrayN<std::string>& nda, |
|
1986 bool pr_as_read_syntax, int extra_indent) |
|
1987 { |
|
1988 // XXX FIXME XXX -- this mostly duplicates the code in the |
|
1989 // PRINT_ND_ARRAY macro. |
|
1990 |
|
1991 if (nda.is_empty ()) |
|
1992 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); |
|
1993 else if (nda.length () == 1) |
|
1994 { |
|
1995 os << nda(0); |
|
1996 } |
|
1997 else |
|
1998 { |
|
1999 int ndims = nda.ndims (); |
|
2000 |
|
2001 dim_vector dims = nda.dims (); |
|
2002 |
|
2003 Array<int> ra_idx (ndims, 0); |
|
2004 |
|
2005 int m = 1; |
|
2006 |
|
2007 for (int i = 2; i < ndims; i++) |
|
2008 m *= dims(i); |
|
2009 |
|
2010 int nr = dims(0); |
|
2011 int nc = dims(1); |
|
2012 |
|
2013 for (int i = 0; i < m; i++) |
|
2014 { |
|
2015 std::string nm = "ans"; |
|
2016 |
|
2017 if (m > 1) |
|
2018 { |
|
2019 nm += "(:,:,"; |
|
2020 |
|
2021 OSSTREAM buf; |
|
2022 |
|
2023 for (int k = 2; k < ndims; k++) |
|
2024 { |
|
2025 buf << ra_idx(k) + 1; |
|
2026 |
|
2027 if (k < ndims - 1) |
|
2028 buf << ","; |
|
2029 else |
|
2030 buf << ")"; |
|
2031 } |
|
2032 |
|
2033 buf << OSSTREAM_ENDS; |
|
2034 |
|
2035 nm += OSSTREAM_STR (buf); |
|
2036 |
|
2037 OSSTREAM_FREEZE (buf); |
|
2038 } |
|
2039 |
|
2040 Array<idx_vector> idx (ndims); |
|
2041 |
|
2042 idx(0) = idx_vector (':'); |
|
2043 idx(1) = idx_vector (':'); |
|
2044 |
|
2045 for (int k = 2; k < ndims; k++) |
|
2046 idx(k) = idx_vector (ra_idx(k) + 1); |
|
2047 |
|
2048 Array2<std::string> page (nda.index (idx), nr, nc); |
|
2049 |
|
2050 // XXX FIXME XXX -- need to do some more work to put these |
|
2051 // in neatly aligned columns... |
|
2052 |
|
2053 int n_rows = page.rows (); |
|
2054 int n_cols = page.cols (); |
|
2055 |
|
2056 os << nm << " =\n\n"; |
|
2057 |
|
2058 for (int ii = 0; ii < n_rows; ii++) |
|
2059 { |
|
2060 for (int jj = 0; jj < n_cols; jj++) |
|
2061 os << " " << page(ii,jj); |
|
2062 |
|
2063 os << "\n"; |
|
2064 } |
|
2065 |
|
2066 if (i < m - 1) |
|
2067 os << "\n"; |
|
2068 |
|
2069 if (i < m) |
|
2070 increment_index (ra_idx, dims, 2); |
|
2071 } |
|
2072 } |
|
2073 } |
|
2074 |
3933
|
2075 extern void |
|
2076 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928
|
2077 { |
3933
|
2078 panic_impossible (); |
3928
|
2079 } |
|
2080 |
3685
|
2081 DEFUN (disp, args, nargout, |
|
2082 "-*- texinfo -*-\n\ |
|
2083 @deftypefn {Built-in Function} {} disp (@var{x})\n\ |
|
2084 Display the value of @var{x}. For example,\n\ |
|
2085 \n\ |
|
2086 @example\n\ |
|
2087 disp (\"The value of pi is:\"), disp (pi)\n\ |
|
2088 \n\ |
|
2089 @print{} the value of pi is:\n\ |
|
2090 @print{} 3.1416\n\ |
|
2091 @end example\n\ |
|
2092 \n\ |
|
2093 @noindent\n\ |
|
2094 Note that the output from @code{disp} always ends with a newline.\n\ |
|
2095 \n\ |
|
2096 If an output value is requested, @code{disp} prints nothing and\n\ |
|
2097 returns the formatted output in a string.\n\ |
|
2098 @end deftypefn\n\ |
|
2099 @seealso{fdisp}") |
|
2100 { |
|
2101 octave_value retval; |
|
2102 |
|
2103 int nargin = args.length (); |
|
2104 |
|
2105 if (nargin == 1 && nargout < 2) |
|
2106 { |
|
2107 if (nargout == 0) |
|
2108 args(0).print (octave_stdout); |
|
2109 else |
|
2110 { |
4051
|
2111 OSSTREAM buf; |
3685
|
2112 args(0).print (buf); |
4051
|
2113 buf << OSSTREAM_ENDS; |
|
2114 retval = OSSTREAM_STR (buf); |
|
2115 OSSTREAM_FREEZE (buf); |
3685
|
2116 } |
|
2117 } |
|
2118 else |
|
2119 print_usage ("disp"); |
|
2120 |
|
2121 return retval; |
|
2122 } |
|
2123 |
|
2124 DEFUN (fdisp, args, , |
|
2125 "-*- texinfo -*-\n\ |
|
2126 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\ |
|
2127 Display the value of @var{x} on the stream @var{fid}. For example,\n\ |
|
2128 \n\ |
|
2129 @example\n\ |
|
2130 disp (stdout, \"The value of pi is:\"), disp (stdout, pi)\n\ |
|
2131 \n\ |
|
2132 @print{} the value of pi is:\n\ |
|
2133 @print{} 3.1416\n\ |
|
2134 @end example\n\ |
|
2135 \n\ |
|
2136 @noindent\n\ |
|
2137 Note that the output from @code{disp} always ends with a newline.\n\ |
|
2138 \n\ |
|
2139 If an output value is requested, @code{disp} prints nothing and\n\ |
|
2140 returns the formatted output in a string.\n\ |
|
2141 @end deftypefn\n\ |
|
2142 @seealso{disp}") |
|
2143 { |
|
2144 octave_value retval; |
|
2145 |
|
2146 int nargin = args.length (); |
|
2147 |
|
2148 if (nargin == 2) |
|
2149 { |
|
2150 int fid = octave_stream_list::get_file_number (args (0)); |
|
2151 |
|
2152 octave_stream os = octave_stream_list::lookup (fid, "fdisp"); |
|
2153 |
|
2154 if (! error_state) |
|
2155 { |
3769
|
2156 std::ostream *osp = os.output_stream (); |
3685
|
2157 |
|
2158 if (osp) |
|
2159 args(1).print (*osp); |
|
2160 else |
|
2161 error ("fdisp: stream not open for writing"); |
|
2162 } |
|
2163 } |
|
2164 else |
|
2165 print_usage ("fdisp"); |
|
2166 |
|
2167 return retval; |
|
2168 } |
|
2169 |
1
|
2170 static void |
|
2171 init_format_state (void) |
|
2172 { |
2387
|
2173 free_format = false; |
|
2174 plus_format = false; |
|
2175 bank_format = false; |
3608
|
2176 hex_format = 0; |
1309
|
2177 bit_format = 0; |
2387
|
2178 print_e = false; |
|
2179 print_big_e = false; |
4509
|
2180 print_g = false; |
1
|
2181 } |
|
2182 |
|
2183 static void |
|
2184 set_output_prec_and_fw (int prec, int fw) |
|
2185 { |
4233
|
2186 bind_builtin_variable ("output_precision", prec); |
|
2187 bind_builtin_variable ("output_max_field_width", fw); |
1
|
2188 } |
|
2189 |
1755
|
2190 static void |
|
2191 set_format_style (int argc, const string_vector& argv) |
1
|
2192 { |
1755
|
2193 int idx = 1; |
|
2194 |
1899
|
2195 if (--argc > 0) |
1
|
2196 { |
3523
|
2197 std::string arg = argv[idx++]; |
2584
|
2198 |
1755
|
2199 if (arg == "short") |
1
|
2200 { |
1755
|
2201 if (--argc > 0) |
1
|
2202 { |
1755
|
2203 arg = argv[idx++]; |
|
2204 |
|
2205 if (arg == "e") |
1
|
2206 { |
1755
|
2207 init_format_state (); |
2387
|
2208 print_e = true; |
1755
|
2209 } |
|
2210 else if (arg == "E") |
|
2211 { |
|
2212 init_format_state (); |
2387
|
2213 print_e = true; |
|
2214 print_big_e = true; |
1
|
2215 } |
4509
|
2216 else if (arg == "g") |
|
2217 { |
|
2218 init_format_state (); |
|
2219 print_g = true; |
|
2220 } |
|
2221 else if (arg == "G") |
|
2222 { |
|
2223 init_format_state (); |
|
2224 print_g = true; |
|
2225 print_big_e = true; |
|
2226 } |
1
|
2227 else |
|
2228 { |
1755
|
2229 error ("format: unrecognized option `short %s'", |
|
2230 arg.c_str ()); |
|
2231 return; |
|
2232 } |
|
2233 } |
|
2234 else |
|
2235 init_format_state (); |
|
2236 |
4509
|
2237 set_output_prec_and_fw (5, 10); |
1755
|
2238 } |
|
2239 else if (arg == "long") |
|
2240 { |
|
2241 if (--argc > 0) |
|
2242 { |
|
2243 arg = argv[idx++]; |
|
2244 |
|
2245 if (arg == "e") |
|
2246 { |
|
2247 init_format_state (); |
2387
|
2248 print_e = true; |
1755
|
2249 } |
|
2250 else if (arg == "E") |
|
2251 { |
|
2252 init_format_state (); |
2387
|
2253 print_e = true; |
|
2254 print_big_e = true; |
1
|
2255 } |
4509
|
2256 else if (arg == "g") |
|
2257 { |
|
2258 init_format_state (); |
|
2259 print_g = true; |
|
2260 } |
|
2261 else if (arg == "G") |
|
2262 { |
|
2263 init_format_state (); |
|
2264 print_g = true; |
|
2265 print_big_e = true; |
|
2266 } |
1
|
2267 else |
1755
|
2268 { |
|
2269 error ("format: unrecognized option `long %s'", |
|
2270 arg.c_str ()); |
|
2271 return; |
|
2272 } |
1186
|
2273 } |
1
|
2274 else |
1755
|
2275 init_format_state (); |
|
2276 |
4509
|
2277 set_output_prec_and_fw (15, 20); |
1755
|
2278 } |
|
2279 else if (arg == "hex") |
|
2280 { |
|
2281 init_format_state (); |
3608
|
2282 hex_format = 1; |
1755
|
2283 } |
|
2284 else if (arg == "native-hex") |
|
2285 { |
|
2286 init_format_state (); |
|
2287 hex_format = 2; |
|
2288 } |
|
2289 else if (arg == "bit") |
|
2290 { |
|
2291 init_format_state (); |
|
2292 bit_format = 1; |
|
2293 } |
|
2294 else if (arg == "native-bit") |
|
2295 { |
|
2296 init_format_state (); |
|
2297 bit_format = 2; |
|
2298 } |
|
2299 else if (arg == "+" || arg == "plus") |
|
2300 { |
4632
|
2301 if (--argc > 0) |
|
2302 { |
|
2303 arg = argv[idx++]; |
|
2304 |
|
2305 if (arg.length () == 3) |
|
2306 plus_format_chars = arg; |
|
2307 else |
|
2308 { |
|
2309 error ("format: invalid option for plus format"); |
|
2310 return; |
|
2311 } |
|
2312 } |
|
2313 else |
|
2314 plus_format_chars = "+ "; |
|
2315 |
1755
|
2316 init_format_state (); |
2387
|
2317 plus_format = true; |
1755
|
2318 } |
|
2319 else if (arg == "bank") |
|
2320 { |
|
2321 init_format_state (); |
2387
|
2322 bank_format = true; |
1755
|
2323 } |
|
2324 else if (arg == "free") |
|
2325 { |
|
2326 init_format_state (); |
2387
|
2327 free_format = true; |
1755
|
2328 } |
|
2329 else if (arg == "none") |
|
2330 { |
|
2331 init_format_state (); |
2387
|
2332 free_format = true; |
1755
|
2333 } |
|
2334 else if (arg == "compact") |
|
2335 { |
2387
|
2336 compact_format = true; |
1755
|
2337 } |
|
2338 else if (arg == "loose") |
|
2339 { |
2387
|
2340 compact_format = false; |
1
|
2341 } |
|
2342 else |
1755
|
2343 error ("format: unrecognized format state `%s'", arg.c_str ()); |
1
|
2344 } |
|
2345 else |
|
2346 { |
|
2347 init_format_state (); |
|
2348 set_output_prec_and_fw (5, 10); |
|
2349 } |
|
2350 } |
|
2351 |
4208
|
2352 DEFCMD (format, args, , |
3372
|
2353 "-*- texinfo -*-\n\ |
|
2354 @deffn {Command} format options\n\ |
|
2355 Control the format of the output produced by @code{disp} and Octave's\n\ |
|
2356 normal echoing mechanism. Valid options are listed in the following\n\ |
|
2357 table.\n\ |
|
2358 \n\ |
|
2359 @table @code\n\ |
|
2360 @item short\n\ |
|
2361 Octave will try to print numbers with at\n\ |
4509
|
2362 least 5 significant figures within a field that is a maximum of 10\n\ |
|
2363 characters wide (not counting additional spacing that is added between\n\ |
|
2364 columns of a matrix).\n\ |
3372
|
2365 \n\ |
|
2366 If Octave is unable to format a matrix so that columns line up on the\n\ |
|
2367 decimal point and all the numbers fit within the maximum field width,\n\ |
|
2368 it switches to an @samp{e} format.\n\ |
|
2369 \n\ |
|
2370 @item long\n\ |
|
2371 Octave will try to print numbers with at least 15 significant figures\n\ |
4509
|
2372 within a field that is a maximum of 20 characters wide (not counting\n\ |
|
2373 additional spacing that is added between columns of a matrix).\n\ |
3372
|
2374 \n\ |
|
2375 As will the @samp{short} format, Octave will switch to an @samp{e}\n\ |
|
2376 format if it is unable to format a matrix so that columns line up on the\n\ |
|
2377 decimal point and all the numbers fit within the maximum field width.\n\ |
|
2378 \n\ |
|
2379 @item long e\n\ |
|
2380 @itemx short e\n\ |
|
2381 The same as @samp{format long} or @samp{format short} but always display\n\ |
|
2382 output with an @samp{e} format. For example, with the @samp{short e}\n\ |
4509
|
2383 format, @code{pi} is displayed as @code{3.14e+00}.\n\ |
3372
|
2384 \n\ |
|
2385 @item long E\n\ |
|
2386 @itemx short E\n\ |
|
2387 The same as @samp{format long e} or @samp{format short e} but always\n\ |
|
2388 display output with an uppercase @samp{E} format. For example, with\n\ |
4509
|
2389 the @samp{long E} format, @code{pi} is displayed as\n\ |
3372
|
2390 @code{3.14159265358979E+00}.\n\ |
4509
|
2391 @item long g\n\ |
|
2392 @itemx short g\n\ |
|
2393 Choose between normal @samp{long} (or @samp{short}) and and\n\ |
|
2394 @samp{long e} (or @samp{short e}) formats based on the magnitude\n\ |
|
2395 of the number. For example, with the @samp{short g} format,\n\ |
|
2396 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
|
2397 \n\ |
|
2398 @example\n\ |
|
2399 @group\n\ |
|
2400 ans =\n\ |
|
2401 \n\ |
|
2402 3.1416\n\ |
|
2403 9.8696\n\ |
|
2404 97.409\n\ |
|
2405 9488.5\n\ |
|
2406 9.0032e+07\n\ |
|
2407 8.1058e+15\n\ |
|
2408 @end group\n\ |
|
2409 @end example\n\ |
|
2410 \n\ |
|
2411 @item long G\n\ |
|
2412 @itemx short G\n\ |
|
2413 The same as @samp{format long g} or @samp{format short g} but use an\n\ |
|
2414 uppercase @samp{E} format. For example, with the @samp{short G} format,\n\ |
|
2415 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ |
|
2416 \n\ |
|
2417 @example\n\ |
|
2418 @group\n\ |
|
2419 ans =\n\ |
|
2420 \n\ |
|
2421 3.1416\n\ |
|
2422 9.8696\n\ |
|
2423 97.409\n\ |
|
2424 9488.5\n\ |
|
2425 9.0032E+07\n\ |
|
2426 8.1058E+15\n\ |
|
2427 @end group\n\ |
|
2428 @end example\n\ |
3372
|
2429 \n\ |
|
2430 @item free\n\ |
|
2431 @itemx none\n\ |
|
2432 Print output in free format, without trying to line up columns of\n\ |
|
2433 matrices on the decimal point. This also causes complex numbers to be\n\ |
|
2434 formatted like this @samp{(0.604194, 0.607088)} instead of like this\n\ |
|
2435 @samp{0.60419 + 0.60709i}.\n\ |
529
|
2436 \n\ |
3372
|
2437 @item bank\n\ |
|
2438 Print in a fixed format with two places to the right of the decimal\n\ |
|
2439 point.\n\ |
|
2440 \n\ |
|
2441 @item +\n\ |
4632
|
2442 @itemx + @var{chars}\n\ |
|
2443 @itemx plus\n\ |
|
2444 @itemx plus @var{chars}\n\ |
3372
|
2445 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ |
|
2446 matrix elements. This format can be very useful for examining the\n\ |
|
2447 structure of a large matrix.\n\ |
|
2448 \n\ |
4632
|
2449 The optional argument @var{chars} specifies a list of 3 characters to use\n\ |
|
2450 for printing values greater than zero, less than zero and equal to zero.\n\ |
|
2451 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\ |
|
2452 is displayed as\n\ |
|
2453 \n\ |
|
2454 @example\n\ |
|
2455 @group\n\ |
|
2456 ans =\n\ |
|
2457 \n\ |
|
2458 +.-\n\ |
|
2459 -.+\n\ |
|
2460 @end group\n\ |
|
2461 @end example\n\ |
|
2462 \n\ |
3372
|
2463 @item hex\n\ |
|
2464 Print the hexadecimal representation numbers as they are stored in\n\ |
|
2465 memory. For example, on a workstation which stores 8 byte real values\n\ |
|
2466 in IEEE format with the least significant byte first, the value of\n\ |
|
2467 @code{pi} when printed in @code{hex} format is @code{400921fb54442d18}.\n\ |
|
2468 This format only works for numeric values.\n\ |
|
2469 \n\ |
|
2470 @item bit\n\ |
|
2471 Print the bit representation of numbers as stored in memory.\n\ |
|
2472 For example, the value of @code{pi} is\n\ |
|
2473 \n\ |
|
2474 @example\n\ |
|
2475 @group\n\ |
|
2476 01000000000010010010000111111011\n\ |
|
2477 01010100010001000010110100011000\n\ |
|
2478 @end group\n\ |
|
2479 @end example\n\ |
|
2480 \n\ |
|
2481 (shown here in two 32 bit sections for typesetting purposes) when\n\ |
|
2482 printed in bit format on a workstation which stores 8 byte real values\n\ |
|
2483 in IEEE format with the least significant byte first. This format only\n\ |
|
2484 works for numeric types.\n\ |
|
2485 @end table\n\ |
|
2486 \n\ |
|
2487 By default, Octave will try to print numbers with at least 5 significant\n\ |
|
2488 figures within a field that is a maximum of 10 characters wide.\n\ |
|
2489 \n\ |
|
2490 If Octave is unable to format a matrix so that columns line up on the\n\ |
|
2491 decimal point and all the numbers fit within the maximum field width,\n\ |
|
2492 it switches to an @samp{e} format.\n\ |
|
2493 \n\ |
|
2494 If @code{format} is invoked without any options, the default format\n\ |
|
2495 state is restored.\n\ |
|
2496 @end deffn") |
529
|
2497 { |
2086
|
2498 octave_value_list retval; |
529
|
2499 |
1755
|
2500 int argc = args.length () + 1; |
|
2501 |
1968
|
2502 string_vector argv = args.make_argv ("format"); |
1755
|
2503 |
|
2504 if (error_state) |
|
2505 return retval; |
529
|
2506 |
|
2507 set_format_style (argc, argv); |
|
2508 |
|
2509 return retval; |
|
2510 } |
|
2511 |
2165
|
2512 static int |
3105
|
2513 fixed_point_format (void) |
|
2514 { |
|
2515 Vfixed_point_format = check_preference ("fixed_point_format"); |
|
2516 |
|
2517 return 0; |
|
2518 } |
|
2519 |
|
2520 static int |
2165
|
2521 output_max_field_width (void) |
|
2522 { |
|
2523 double val; |
|
2524 if (builtin_real_scalar_variable ("output_max_field_width", val) |
4025
|
2525 && ! octave_is_NaN_or_NA (val)) |
2165
|
2526 { |
|
2527 int ival = NINT (val); |
2800
|
2528 if (ival > 0 && ival == val) |
2165
|
2529 { |
|
2530 Voutput_max_field_width = ival; |
|
2531 return 0; |
|
2532 } |
|
2533 } |
|
2534 gripe_invalid_value_specified ("output_max_field_width"); |
|
2535 return -1; |
|
2536 } |
|
2537 |
|
2538 static int |
|
2539 output_precision (void) |
|
2540 { |
|
2541 double val; |
|
2542 if (builtin_real_scalar_variable ("output_precision", val) |
4025
|
2543 && ! octave_is_NaN_or_NA (val)) |
2165
|
2544 { |
|
2545 int ival = NINT (val); |
2800
|
2546 if (ival >= 0 && ival == val) |
2165
|
2547 { |
|
2548 Voutput_precision = ival; |
|
2549 return 0; |
|
2550 } |
|
2551 } |
|
2552 gripe_invalid_value_specified ("output_precision"); |
|
2553 return -1; |
|
2554 } |
|
2555 |
|
2556 static int |
|
2557 print_empty_dimensions (void) |
|
2558 { |
|
2559 Vprint_empty_dimensions = check_preference ("print_empty_dimensions"); |
|
2560 |
|
2561 return 0; |
|
2562 } |
|
2563 |
|
2564 static int |
|
2565 split_long_rows (void) |
|
2566 { |
|
2567 Vsplit_long_rows = check_preference ("split_long_rows"); |
|
2568 |
|
2569 return 0; |
|
2570 } |
|
2571 |
|
2572 void |
|
2573 symbols_of_pr_output (void) |
|
2574 { |
4233
|
2575 DEFVAR (fixed_point_format, false, fixed_point_format, |
3321
|
2576 "-*- texinfo -*-\n\ |
|
2577 @defvr {Built-in Variable} fixed_point_format\n\ |
|
2578 If the value of this variable is nonzero, Octave will scale all values\n\ |
|
2579 in a matrix so that the largest may be written with one leading digit.\n\ |
|
2580 The scaling factor is printed on the first line of output. For example,\n\ |
|
2581 \n\ |
|
2582 @example\n\ |
|
2583 @group\n\ |
|
2584 octave:1> logspace (1, 7, 5)'\n\ |
|
2585 ans =\n\ |
|
2586 \n\ |
|
2587 1.0e+07 *\n\ |
|
2588 \n\ |
|
2589 0.00000\n\ |
|
2590 0.00003\n\ |
|
2591 0.00100\n\ |
|
2592 0.03162\n\ |
|
2593 1.00000\n\ |
|
2594 @end group\n\ |
|
2595 @end example\n\ |
|
2596 \n\ |
|
2597 @noindent\n\ |
|
2598 Notice that first value appears to be zero when it is actually 1. For\n\ |
|
2599 this reason, you should be careful when setting\n\ |
|
2600 @code{fixed_point_format} to a nonzero value.\n\ |
|
2601 \n\ |
|
2602 The default value of @code{fixed_point_format} is 0.\n\ |
3333
|
2603 @end defvr"); |
3105
|
2604 |
3258
|
2605 DEFVAR (output_max_field_width, 10.0, output_max_field_width, |
3321
|
2606 "-*- texinfo -*-\n\ |
|
2607 @defvr {Built-in Variable} output_max_field_width\n\ |
|
2608 This variable specifies the maximum width of a numeric output field.\n\ |
|
2609 The default value is 10.\n\ |
3333
|
2610 @end defvr"); |
2165
|
2611 |
3258
|
2612 DEFVAR (output_precision, 5.0, output_precision, |
3321
|
2613 "-*- texinfo -*-\n\ |
|
2614 @defvr {Built-in Variable} output_precision\n\ |
|
2615 This variable specifies the minimum number of significant figures to\n\ |
|
2616 display for numeric output. The default value is 5.\n\ |
3333
|
2617 @end defvr"); |
2165
|
2618 |
4233
|
2619 DEFVAR (print_empty_dimensions, true, print_empty_dimensions, |
3321
|
2620 "-*- texinfo -*-\n\ |
|
2621 @defvr {Built-in Variable} print_empty_dimensions\n\ |
|
2622 If the value of @code{print_empty_dimensions} is nonzero, the\n\ |
|
2623 dimensions of empty matrices are printed along with the empty matrix\n\ |
|
2624 symbol, @samp{[]}. For example, the expression\n\ |
|
2625 \n\ |
|
2626 @example\n\ |
|
2627 zeros (3, 0)\n\ |
|
2628 @end example\n\ |
|
2629 \n\ |
|
2630 @noindent\n\ |
|
2631 will print\n\ |
|
2632 \n\ |
|
2633 @example\n\ |
|
2634 ans = [](3x0)\n\ |
|
2635 @end example\n\ |
3333
|
2636 @end defvr"); |
2165
|
2637 |
4233
|
2638 DEFVAR (split_long_rows, true, split_long_rows, |
3321
|
2639 "-*- texinfo -*-\n\ |
|
2640 @defvr {Built-in Variable} split_long_rows\n\ |
|
2641 For large matrices, Octave may not be able to display all the columns of\n\ |
|
2642 a given row on one line of your screen. This can result in missing\n\ |
|
2643 information or output that is nearly impossible to decipher, depending\n\ |
|
2644 on whether your terminal truncates or wraps long lines.\n\ |
|
2645 \n\ |
|
2646 If the value of @code{split_long_rows} is nonzero, Octave will display\n\ |
|
2647 the matrix in a series of smaller pieces, each of which can fit within\n\ |
|
2648 the limits of your terminal width. Each set of rows is labeled so that\n\ |
|
2649 you can easily see which columns are currently being displayed.\n\ |
|
2650 For example:\n\ |
|
2651 \n\ |
|
2652 @smallexample\n\ |
|
2653 @group\n\ |
|
2654 octave:13> rand (2,10)\n\ |
|
2655 ans =\n\ |
|
2656 \n\ |
|
2657 Columns 1 through 6:\n\ |
|
2658 \n\ |
|
2659 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ |
|
2660 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ |
|
2661 \n\ |
|
2662 Columns 7 through 10:\n\ |
|
2663 \n\ |
|
2664 0.90174 0.11854 0.72313 0.73326\n\ |
|
2665 0.44672 0.94303 0.56564 0.82150\n\ |
|
2666 @end group\n\ |
|
2667 @end smallexample\n\ |
|
2668 \n\ |
|
2669 @noindent\n\ |
|
2670 The default value of @code{split_long_rows} is nonzero.\n\ |
3333
|
2671 @end defvr"); |
2165
|
2672 } |
|
2673 |
1
|
2674 /* |
|
2675 ;;; Local Variables: *** |
|
2676 ;;; mode: C++ *** |
|
2677 ;;; End: *** |
|
2678 */ |