Mercurial > hg > octave-nkf
annotate src/pr-output.cc @ 11756:d68fc0ca4ece release-3-0-x
disp: produce sq-string unless arg is a dq-string
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Apr 2008 12:01:53 -0400 |
parents | 2eb392d058bb |
children | 7cc783e52ddb |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
4 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
1346 | 28 #include <cfloat> |
2825 | 29 #include <cstdio> |
1346 | 30 #include <cstring> |
1343 | 31 |
3503 | 32 #include <iomanip> |
33 #include <iostream> | |
5765 | 34 #include <sstream> |
1728 | 35 #include <string> |
36 | |
4655 | 37 #include "Array-util.h" |
453 | 38 #include "CMatrix.h" |
1 | 39 #include "Range.h" |
2926 | 40 #include "cmd-edit.h" |
1352 | 41 #include "dMatrix.h" |
2891 | 42 #include "lo-mappers.h" |
7231 | 43 #include "lo-math.h" |
2317 | 44 #include "mach-info.h" |
1651 | 45 #include "oct-cmplx.h" |
4153 | 46 #include "quit.h" |
1755 | 47 #include "str-vec.h" |
1 | 48 |
3933 | 49 #include "Cell.h" |
1352 | 50 #include "defun.h" |
51 #include "error.h" | |
2165 | 52 #include "gripes.h" |
1755 | 53 #include "oct-obj.h" |
3685 | 54 #include "oct-stream.h" |
1352 | 55 #include "pager.h" |
56 #include "pr-output.h" | |
1282 | 57 #include "sysdep.h" |
6803 | 58 #include "unwind-prot.h" |
1 | 59 #include "utils.h" |
1352 | 60 #include "variables.h" |
1 | 61 |
3105 | 62 // TRUE means use a scaled fixed point format for `format long' and |
63 // `format short'. | |
5794 | 64 static bool Vfixed_point_format = false; |
3105 | 65 |
2165 | 66 // The maximum field width for a number printed by the default output |
67 // routines. | |
5794 | 68 static int Voutput_max_field_width = 10; |
2165 | 69 |
70 // The precision of the numbers printed by the default output | |
71 // routines. | |
5794 | 72 static int Voutput_precision = 5; |
2165 | 73 |
5360 | 74 // TRUE means that the dimensions of empty objects should be printed |
2165 | 75 // like this: x = [](2x0). |
5794 | 76 bool Vprint_empty_dimensions = true; |
2165 | 77 |
78 // TRUE means that the rows of big matrices should be split into | |
79 // smaller slices that fit on the screen. | |
5794 | 80 static bool Vsplit_long_rows = true; |
2165 | 81 |
5759 | 82 // How many levels of structure elements should we print? |
5794 | 83 int Vstruct_levels_to_print = 2; |
5759 | 84 |
3018 | 85 // TRUE means don't do any fancy formatting. |
2387 | 86 static bool free_format = false; |
1 | 87 |
3018 | 88 // TRUE means print plus sign for nonzero, blank for zero. |
2387 | 89 static bool plus_format = false; |
1 | 90 |
4632 | 91 // First char for > 0, second for < 0, third for == 0. |
92 static std::string plus_format_chars = "+ "; | |
93 | |
6788 | 94 // TRUE means always print in a rational approximation |
95 static bool rat_format = false; | |
96 | |
97 // Used to force the length of the rational approximation string for Frats | |
98 static int rat_string_len = -1; | |
99 | |
3018 | 100 // TRUE means always print like dollars and cents. |
2387 | 101 static bool bank_format = false; |
1282 | 102 |
3018 | 103 // TRUE means print data in hexadecimal format. |
3608 | 104 static int hex_format = 0; |
1282 | 105 |
3018 | 106 // TRUE means print data in binary-bit-pattern format. |
1309 | 107 static int bit_format = 0; |
108 | |
3018 | 109 // TRUE means don't put newlines around the column number headers. |
2387 | 110 static bool compact_format = false; |
1186 | 111 |
3018 | 112 // TRUE means use an e format. |
2387 | 113 static bool print_e = false; |
1 | 114 |
4509 | 115 // TRUE means use a g format. |
116 static bool print_g = false; | |
117 | |
3018 | 118 // TRUE means print E instead of e for exponent field. |
2387 | 119 static bool print_big_e = false; |
1 | 120 |
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 (), |
142 int p = current_output_precision (), int f = 0) | |
3608 | 143 : fw (w), prec (p), fmt (f), up (0), sp (0) { } |
144 | |
145 float_format (const float_format& ff) | |
146 : fw (ff.fw), prec (ff.prec), fmt (ff.fmt), up (ff.up), sp (ff.sp) { } | |
147 | |
148 float_format& operator = (const float_format& ff) | |
149 { | |
150 if (&ff != this) | |
151 { | |
152 fw = ff.fw; | |
153 prec = ff.prec; | |
154 fmt = ff.fmt; | |
155 up = ff.up; | |
156 sp = ff.sp; | |
157 } | |
158 | |
159 return *this; | |
160 } | |
161 | |
162 ~float_format (void) { } | |
163 | |
164 float_format& scientific (void) { fmt = std::ios::scientific; return *this; } | |
165 float_format& fixed (void) { fmt = std::ios::fixed; return *this; } | |
166 float_format& general (void) { fmt = 0; return *this; } | |
167 | |
168 float_format& uppercase (void) { up = std::ios::uppercase; return *this; } | |
169 float_format& lowercase (void) { up = 0; return *this; } | |
170 | |
171 float_format& precision (int p) { prec = p; return *this; } | |
172 | |
173 float_format& width (int w) { fw = w; return *this; } | |
174 | |
175 float_format& trailing_zeros (bool tz = true) | |
176 { sp = tz ? std::ios::showpoint : 0; return *this; } | |
177 | |
178 friend std::ostream& operator << (std::ostream& os, | |
179 const pr_formatted_float& pff); | |
180 | |
6788 | 181 friend std::ostream& operator << (std::ostream& os, |
182 const pr_rational_float& pff); | |
183 | |
3608 | 184 private: |
185 | |
186 // Field width. Zero means as wide as necessary. | |
187 int fw; | |
188 | |
189 // Precision. | |
190 int prec; | |
191 | |
192 // Format. | |
193 int fmt; | |
194 | |
195 // E or e. | |
196 int up; | |
197 | |
198 // Show trailing zeros. | |
199 int sp; | |
200 }; | |
201 | |
202 class | |
203 pr_formatted_float | |
204 { | |
205 public: | |
206 | |
207 const float_format& f; | |
208 | |
209 double val; | |
210 | |
211 pr_formatted_float (const float_format& f_arg, double val_arg) | |
212 : f (f_arg), val (val_arg) { } | |
213 }; | |
214 | |
215 std::ostream& | |
216 operator << (std::ostream& os, const pr_formatted_float& pff) | |
217 { | |
3682 | 218 if (pff.f.fw >= 0) |
3608 | 219 os << std::setw (pff.f.fw); |
220 | |
3682 | 221 if (pff.f.prec >= 0) |
3608 | 222 os << std::setprecision (pff.f.prec); |
223 | |
3775 | 224 std::ios::fmtflags oflags = |
225 os.flags (static_cast<std::ios::fmtflags> | |
226 (pff.f.fmt | pff.f.up | pff.f.sp)); | |
3608 | 227 |
228 os << pff.val; | |
229 | |
230 os.flags (oflags); | |
231 | |
232 return os; | |
233 } | |
234 | |
6788 | 235 static inline std::string |
236 rational_approx (double val, int len) | |
237 { | |
238 std::string s; | |
239 | |
240 if (len <= 0) | |
241 len = 10; | |
242 | |
243 if (xisinf (val)) | |
244 s = "1/0"; | |
245 else if (xisnan (val)) | |
246 s = "0/0"; | |
247 else if (val < INT_MIN || val > INT_MAX || D_NINT (val) == val) | |
248 { | |
249 std::ostringstream buf; | |
250 buf.flags (std::ios::fixed); | |
251 buf << std::setprecision (0) << xround(val); | |
252 s = buf.str (); | |
253 } | |
254 else | |
255 { | |
256 double lastn = 1.; | |
257 double lastd = 0.; | |
258 double n = xround (val); | |
259 double d = 1.; | |
260 double frac = val - n; | |
261 int m = 0; | |
262 | |
263 std::ostringstream buf2; | |
264 buf2.flags (std::ios::fixed); | |
265 buf2 << std::setprecision (0) << static_cast<int>(n); | |
266 s = buf2.str(); | |
267 | |
268 while (1) | |
269 { | |
270 double flip = 1. / frac; | |
271 double step = xround (flip); | |
272 double nextn = n; | |
273 double nextd = d; | |
274 frac = flip - step; | |
275 n = n * step + lastn; | |
276 d = d * step + lastd; | |
277 lastn = nextn; | |
278 lastd = nextd; | |
279 | |
280 std::ostringstream buf; | |
281 buf.flags (std::ios::fixed); | |
282 buf << std::setprecision (0) << static_cast<int>(n) | |
283 << "/" << static_cast<int>(d); | |
284 m++; | |
285 | |
286 if (n < 0 && d < 0) | |
287 { | |
288 // Double negative, string can be two characters longer.. | |
289 if (buf.str().length() > static_cast<unsigned int>(len + 2) && | |
290 m > 1) | |
291 break; | |
292 } | |
293 else if (buf.str().length() > static_cast<unsigned int>(len) && | |
294 m > 1) | |
295 break; | |
296 | |
297 s = buf.str(); | |
298 | |
299 // Have we converged to 1/intmax ? | |
300 if (m > 100 || fabs (frac) < 1 / static_cast<double>(INT_MAX)) | |
301 { | |
302 lastn = n; | |
303 lastd = d; | |
304 break; | |
305 } | |
306 } | |
307 | |
308 if (lastd < 0.) | |
309 { | |
310 // Move sign to the top | |
311 lastd = - lastd; | |
312 lastn = - lastn; | |
313 std::ostringstream buf; | |
314 buf.flags (std::ios::fixed); | |
315 buf << std::setprecision (0) << static_cast<int>(lastn) | |
316 << "/" << static_cast<int>(lastd); | |
317 s = buf.str(); | |
318 } | |
319 } | |
320 | |
321 return s; | |
322 } | |
323 | |
324 class | |
325 pr_rational_float | |
326 { | |
327 public: | |
328 | |
329 const float_format& f; | |
330 | |
331 double val; | |
332 | |
333 pr_rational_float (const float_format& f_arg, double val_arg) | |
334 : f (f_arg), val (val_arg) { } | |
335 }; | |
336 | |
337 std::ostream& | |
338 operator << (std::ostream& os, const pr_rational_float& prf) | |
339 { | |
340 int fw = (rat_string_len > 0 ? rat_string_len : prf.f.fw); | |
341 std::string s = rational_approx (prf.val, fw); | |
342 | |
343 if (fw >= 0) | |
344 os << std::setw (fw); | |
345 | |
346 std::ios::fmtflags oflags = | |
347 os.flags (static_cast<std::ios::fmtflags> | |
348 (prf.f.fmt | prf.f.up | prf.f.sp)); | |
349 | |
350 if (fw > 0 && s.length() > static_cast<unsigned int>(fw)) | |
351 os << "*"; | |
352 else | |
353 os << s; | |
354 | |
355 os.flags (oflags); | |
356 | |
357 return os; | |
358 } | |
359 | |
3608 | 360 // Current format for real numbers and the real part of complex |
361 // numbers. | |
362 static float_format *curr_real_fmt = 0; | |
363 | |
364 // Current format for the imaginary part of complex numbers. | |
365 static float_format *curr_imag_fmt = 0; | |
1309 | 366 |
1 | 367 static double |
164 | 368 pr_max_internal (const Matrix& m) |
1 | 369 { |
5275 | 370 octave_idx_type nr = m.rows (); |
371 octave_idx_type nc = m.columns (); | |
1 | 372 |
3130 | 373 double result = -DBL_MAX; |
1 | 374 |
5748 | 375 bool all_inf_or_nan = true; |
376 | |
5275 | 377 for (octave_idx_type j = 0; j < nc; j++) |
378 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 379 { |
3608 | 380 double val = m(i,j); |
5388 | 381 if (xisinf (val) || xisnan (val)) |
1 | 382 continue; |
383 | |
5748 | 384 all_inf_or_nan = false; |
385 | |
1 | 386 if (val > result) |
387 result = val; | |
388 } | |
3608 | 389 |
5748 | 390 if (all_inf_or_nan) |
391 result = 0.0; | |
392 | |
1 | 393 return result; |
394 } | |
395 | |
396 static double | |
164 | 397 pr_min_internal (const Matrix& m) |
1 | 398 { |
5275 | 399 octave_idx_type nr = m.rows (); |
400 octave_idx_type nc = m.columns (); | |
1 | 401 |
402 double result = DBL_MAX; | |
403 | |
5748 | 404 bool all_inf_or_nan = true; |
405 | |
5275 | 406 for (octave_idx_type j = 0; j < nc; j++) |
407 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 408 { |
3608 | 409 double val = m(i,j); |
5389 | 410 if (xisinf (val) || xisnan (val)) |
1 | 411 continue; |
412 | |
5748 | 413 all_inf_or_nan = false; |
414 | |
1 | 415 if (val < result) |
416 result = val; | |
417 } | |
3608 | 418 |
5748 | 419 if (all_inf_or_nan) |
420 result = 0.0; | |
421 | |
1 | 422 return result; |
423 } | |
424 | |
5775 | 425 // FIXME -- it would be nice to share more code among these |
1658 | 426 // functions,.. |
427 | |
1 | 428 static void |
6959 | 429 set_real_format (int digits, bool inf_or_nan, bool int_only, int &fw) |
1 | 430 { |
3608 | 431 static float_format fmt; |
1 | 432 |
2165 | 433 int prec = Voutput_precision; |
1 | 434 |
435 int ld, rd; | |
436 | |
6788 | 437 if (rat_format) |
438 { | |
439 fw = 0; | |
440 rd = 0; | |
441 } | |
442 else if (bank_format) | |
1 | 443 { |
444 fw = digits < 0 ? 4 : digits + 3; | |
5748 | 445 if (inf_or_nan && fw < 4) |
446 fw = 4; | |
1 | 447 rd = 2; |
448 } | |
1282 | 449 else if (hex_format) |
450 { | |
451 fw = 2 * sizeof (double); | |
452 rd = 0; | |
453 } | |
1309 | 454 else if (bit_format) |
455 { | |
456 fw = 8 * sizeof (double); | |
457 rd = 0; | |
458 } | |
3611 | 459 else if (inf_or_nan || int_only) |
1 | 460 { |
5832 | 461 fw = 1 + digits; |
5748 | 462 if (inf_or_nan && fw < 4) |
463 fw = 4; | |
3682 | 464 rd = fw; |
1 | 465 } |
466 else | |
467 { | |
468 if (digits > 0) | |
469 { | |
470 ld = digits; | |
1658 | 471 rd = prec > digits ? prec - digits : prec; |
1 | 472 digits++; |
473 } | |
474 else | |
475 { | |
476 ld = 1; | |
1658 | 477 rd = prec > digits ? prec - digits : prec; |
1 | 478 digits = -digits + 1; |
479 } | |
480 | |
5832 | 481 fw = 1 + ld + 1 + rd; |
5748 | 482 if (inf_or_nan && fw < 4) |
483 fw = 4; | |
1 | 484 } |
485 | |
6788 | 486 if (! (rat_format || bank_format || hex_format || bit_format) |
4509 | 487 && (fw > Voutput_max_field_width || print_e || print_g)) |
1 | 488 { |
4509 | 489 if (print_g) |
490 fmt = float_format (); | |
491 else | |
492 { | |
493 int exp_field = 4; | |
494 if (digits > 100) | |
495 exp_field++; | |
1 | 496 |
4509 | 497 fw = 2 + prec + exp_field; |
5748 | 498 if (inf_or_nan && fw < 4) |
499 fw = 4; | |
1 | 500 |
4509 | 501 fmt = float_format (fw, prec - 1, std::ios::scientific); |
502 } | |
3608 | 503 |
1 | 504 if (print_big_e) |
3608 | 505 fmt.uppercase (); |
1 | 506 } |
5086 | 507 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 508 fmt = float_format (fw, rd); |
1 | 509 else |
3608 | 510 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 511 |
3608 | 512 curr_real_fmt = &fmt; |
1 | 513 } |
514 | |
1658 | 515 static void |
516 set_format (double d, int& fw) | |
517 { | |
518 curr_real_fmt = 0; | |
519 curr_imag_fmt = 0; | |
520 | |
521 if (free_format) | |
522 return; | |
523 | |
5389 | 524 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658 | 525 |
3611 | 526 bool int_only = (! inf_or_nan && D_NINT (d) == d); |
1658 | 527 |
528 double d_abs = d < 0.0 ? -d : d; | |
529 | |
2800 | 530 int digits = (inf_or_nan || d_abs == 0.0) |
531 ? 0 : static_cast<int> (floor (log10 (d_abs) + 1.0)); | |
1658 | 532 |
6959 | 533 set_real_format (digits, inf_or_nan, int_only, fw); |
1658 | 534 } |
535 | |
1 | 536 static inline void |
537 set_format (double d) | |
538 { | |
539 int fw; | |
540 set_format (d, fw); | |
541 } | |
542 | |
543 static void | |
6959 | 544 set_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
545 int int_or_inf_or_nan, int& fw) | |
1 | 546 { |
3608 | 547 static float_format fmt; |
1 | 548 |
2165 | 549 int prec = Voutput_precision; |
1 | 550 |
551 int ld, rd; | |
552 | |
6788 | 553 if (rat_format) |
554 { | |
555 fw = 9; | |
556 rd = 0; | |
557 } | |
558 else if (bank_format) | |
1 | 559 { |
560 int digits = x_max > x_min ? x_max : x_min; | |
561 fw = digits <= 0 ? 4 : digits + 3; | |
5748 | 562 if (inf_or_nan && fw < 4) |
563 fw = 4; | |
1 | 564 rd = 2; |
565 } | |
1282 | 566 else if (hex_format) |
567 { | |
568 fw = 2 * sizeof (double); | |
569 rd = 0; | |
570 } | |
1309 | 571 else if (bit_format) |
572 { | |
573 fw = 8 * sizeof (double); | |
574 rd = 0; | |
575 } | |
4509 | 576 else if (Vfixed_point_format && ! print_g) |
3268 | 577 { |
578 rd = prec; | |
579 fw = rd + 2; | |
5748 | 580 if (inf_or_nan && fw < 4) |
581 fw = 4; | |
3268 | 582 } |
1715 | 583 else if (int_or_inf_or_nan) |
1 | 584 { |
585 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 586 fw = digits <= 0 ? 2 : digits + 1; |
5748 | 587 if (inf_or_nan && fw < 4) |
588 fw = 4; | |
3682 | 589 rd = fw; |
1 | 590 } |
591 else | |
592 { | |
593 int ld_max, rd_max; | |
594 if (x_max > 0) | |
595 { | |
596 ld_max = x_max; | |
1658 | 597 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 598 x_max++; |
599 } | |
600 else | |
601 { | |
602 ld_max = 1; | |
1658 | 603 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 604 x_max = -x_max + 1; |
605 } | |
606 | |
607 int ld_min, rd_min; | |
608 if (x_min > 0) | |
609 { | |
610 ld_min = x_min; | |
1658 | 611 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 612 x_min++; |
613 } | |
614 else | |
615 { | |
616 ld_min = 1; | |
1658 | 617 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 618 x_min = -x_min + 1; |
619 } | |
620 | |
621 ld = ld_max > ld_min ? ld_max : ld_min; | |
622 rd = rd_max > rd_min ? rd_max : rd_min; | |
623 | |
5832 | 624 fw = 1 + ld + 1 + rd; |
5748 | 625 if (inf_or_nan && fw < 4) |
626 fw = 4; | |
1 | 627 } |
628 | |
6788 | 629 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 630 && (print_e |
4509 | 631 || print_g |
3105 | 632 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 633 { |
4509 | 634 if (print_g) |
635 fmt = float_format (); | |
636 else | |
637 { | |
638 int exp_field = 4; | |
639 if (x_max > 100 || x_min > 100) | |
640 exp_field++; | |
1 | 641 |
4509 | 642 fw = 2 + prec + exp_field; |
5748 | 643 if (inf_or_nan && fw < 4) |
644 fw = 4; | |
1 | 645 |
4509 | 646 fmt = float_format (fw, prec - 1, std::ios::scientific); |
647 } | |
3608 | 648 |
1 | 649 if (print_big_e) |
3608 | 650 fmt.uppercase (); |
1 | 651 } |
5086 | 652 else if (! bank_format && int_or_inf_or_nan) |
3611 | 653 fmt = float_format (fw, rd); |
1 | 654 else |
3608 | 655 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 656 |
3608 | 657 curr_real_fmt = &fmt; |
1 | 658 } |
659 | |
1658 | 660 static void |
3105 | 661 set_format (const Matrix& m, int& fw, double& scale) |
1658 | 662 { |
663 curr_real_fmt = 0; | |
664 curr_imag_fmt = 0; | |
665 | |
666 if (free_format) | |
667 return; | |
668 | |
2387 | 669 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 670 |
2387 | 671 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 672 |
2387 | 673 Matrix m_abs = m.abs (); |
1658 | 674 double max_abs = pr_max_internal (m_abs); |
675 double min_abs = pr_min_internal (m_abs); | |
676 | |
2800 | 677 int x_max = max_abs == 0.0 |
678 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); | |
679 | |
680 int x_min = min_abs == 0.0 | |
681 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); | |
1658 | 682 |
4270 | 683 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105 | 684 |
6959 | 685 set_real_matrix_format (x_max, x_min, inf_or_nan, int_or_inf_or_nan, fw); |
1658 | 686 } |
687 | |
1 | 688 static inline void |
164 | 689 set_format (const Matrix& m) |
1 | 690 { |
691 int fw; | |
3105 | 692 double scale; |
693 set_format (m, fw, scale); | |
1 | 694 } |
695 | |
696 static void | |
6959 | 697 set_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan, |
698 int int_only, int& r_fw, int& i_fw) | |
1 | 699 { |
3608 | 700 static float_format r_fmt; |
701 static float_format i_fmt; | |
1 | 702 |
2165 | 703 int prec = Voutput_precision; |
1 | 704 |
705 int ld, rd; | |
706 | |
6788 | 707 if (rat_format) |
708 { | |
709 i_fw = 0; | |
710 r_fw = 0; | |
711 rd = 0; | |
712 } | |
713 else if (bank_format) | |
1 | 714 { |
715 int digits = r_x; | |
716 i_fw = 0; | |
717 r_fw = digits <= 0 ? 4 : digits + 3; | |
5748 | 718 if (inf_or_nan && r_fw < 4) |
719 r_fw = 4; | |
1 | 720 rd = 2; |
721 } | |
1282 | 722 else if (hex_format) |
723 { | |
724 r_fw = 2 * sizeof (double); | |
725 i_fw = 2 * sizeof (double); | |
726 rd = 0; | |
727 } | |
1309 | 728 else if (bit_format) |
729 { | |
730 r_fw = 8 * sizeof (double); | |
731 i_fw = 8 * sizeof (double); | |
732 rd = 0; | |
733 } | |
1658 | 734 else if (inf_or_nan || int_only) |
1 | 735 { |
736 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 737 i_fw = digits <= 0 ? 1 : digits; |
738 r_fw = i_fw + 1; | |
739 if (inf_or_nan && i_fw < 3) | |
740 { | |
741 i_fw = 3; | |
742 r_fw = 4; | |
743 } | |
3682 | 744 rd = r_fw; |
1 | 745 } |
746 else | |
747 { | |
748 int ld_max, rd_max; | |
749 if (x_max > 0) | |
750 { | |
751 ld_max = x_max; | |
1658 | 752 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 753 x_max++; |
754 } | |
755 else | |
756 { | |
757 ld_max = 1; | |
1658 | 758 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 759 x_max = -x_max + 1; |
760 } | |
761 | |
762 int ld_min, rd_min; | |
763 if (x_min > 0) | |
764 { | |
765 ld_min = x_min; | |
1658 | 766 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 767 x_min++; |
768 } | |
769 else | |
770 { | |
771 ld_min = 1; | |
1658 | 772 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 773 x_min = -x_min + 1; |
774 } | |
775 | |
776 ld = ld_max > ld_min ? ld_max : ld_min; | |
777 rd = rd_max > rd_min ? rd_max : rd_min; | |
778 | |
5945 | 779 i_fw = ld + 1 + rd; |
780 r_fw = i_fw + 1; | |
781 if (inf_or_nan && i_fw < 3) | |
782 { | |
783 i_fw = 3; | |
784 r_fw = 4; | |
785 } | |
1 | 786 } |
787 | |
6788 | 788 if (! (rat_format || bank_format || hex_format || bit_format) |
4509 | 789 && (r_fw > Voutput_max_field_width || print_e || print_g)) |
1 | 790 { |
4509 | 791 if (print_g) |
792 { | |
793 r_fmt = float_format (); | |
794 i_fmt = float_format (); | |
795 } | |
796 else | |
797 { | |
798 int exp_field = 4; | |
799 if (x_max > 100 || x_min > 100) | |
800 exp_field++; | |
1 | 801 |
5945 | 802 i_fw = prec + exp_field; |
803 r_fw = i_fw + 1; | |
804 if (inf_or_nan && i_fw < 3) | |
805 { | |
806 i_fw = 3; | |
807 r_fw = 4; | |
808 } | |
1 | 809 |
4509 | 810 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
811 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); | |
812 } | |
3608 | 813 |
1 | 814 if (print_big_e) |
815 { | |
3608 | 816 r_fmt.uppercase (); |
817 i_fmt.uppercase (); | |
1 | 818 } |
819 } | |
5086 | 820 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 821 { |
822 r_fmt = float_format (r_fw, rd); | |
823 i_fmt = float_format (i_fw, rd); | |
824 } | |
1 | 825 else |
826 { | |
3608 | 827 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
828 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 829 } |
830 | |
3608 | 831 curr_real_fmt = &r_fmt; |
832 curr_imag_fmt = &i_fmt; | |
1 | 833 } |
834 | |
1658 | 835 static void |
836 set_format (const Complex& c, int& r_fw, int& i_fw) | |
837 { | |
838 curr_real_fmt = 0; | |
839 curr_imag_fmt = 0; | |
840 | |
841 if (free_format) | |
842 return; | |
843 | |
844 double rp = c.real (); | |
845 double ip = c.imag (); | |
846 | |
2387 | 847 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658 | 848 |
2387 | 849 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658 | 850 |
851 double r_abs = rp < 0.0 ? -rp : rp; | |
852 double i_abs = ip < 0.0 ? -ip : ip; | |
853 | |
2800 | 854 int r_x = r_abs == 0.0 |
855 ? 0 : static_cast<int> (floor (log10 (r_abs) + 1.0)); | |
856 | |
857 int i_x = i_abs == 0.0 | |
858 ? 0 : static_cast<int> (floor (log10 (i_abs) + 1.0)); | |
1658 | 859 |
860 int x_max, x_min; | |
861 | |
862 if (r_x > i_x) | |
863 { | |
864 x_max = r_x; | |
865 x_min = i_x; | |
866 } | |
867 else | |
868 { | |
869 x_max = i_x; | |
870 x_min = r_x; | |
871 } | |
872 | |
6959 | 873 set_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, r_fw, i_fw); |
1658 | 874 } |
875 | |
1 | 876 static inline void |
164 | 877 set_format (const Complex& c) |
1 | 878 { |
879 int r_fw, i_fw; | |
880 set_format (c, r_fw, i_fw); | |
881 } | |
882 | |
883 static void | |
6959 | 884 set_complex_matrix_format (int x_max, int x_min, int r_x_max, |
885 int r_x_min, bool inf_or_nan, | |
1715 | 886 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1 | 887 { |
3608 | 888 static float_format r_fmt; |
889 static float_format i_fmt; | |
1 | 890 |
2165 | 891 int prec = Voutput_precision; |
1 | 892 |
893 int ld, rd; | |
894 | |
6788 | 895 if (rat_format) |
896 { | |
897 i_fw = 9; | |
898 r_fw = 9; | |
899 rd = 0; | |
900 } | |
901 else if (bank_format) | |
1 | 902 { |
903 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; | |
904 i_fw = 0; | |
905 r_fw = digits <= 0 ? 4 : digits + 3; | |
5945 | 906 if (inf_or_nan && r_fw < 4) |
907 r_fw = 4; | |
1 | 908 rd = 2; |
909 } | |
1282 | 910 else if (hex_format) |
911 { | |
912 r_fw = 2 * sizeof (double); | |
913 i_fw = 2 * sizeof (double); | |
914 rd = 0; | |
915 } | |
1309 | 916 else if (bit_format) |
917 { | |
918 r_fw = 8 * sizeof (double); | |
919 i_fw = 8 * sizeof (double); | |
920 rd = 0; | |
921 } | |
4509 | 922 else if (Vfixed_point_format && ! print_g) |
3268 | 923 { |
924 rd = prec; | |
5945 | 925 i_fw = rd + 1; |
926 r_fw = i_fw + 1; | |
927 if (inf_or_nan && i_fw < 3) | |
928 { | |
929 i_fw = 3; | |
930 r_fw = 4; | |
931 } | |
3268 | 932 } |
1715 | 933 else if (int_or_inf_or_nan) |
1 | 934 { |
935 int digits = x_max > x_min ? x_max : x_min; | |
5945 | 936 i_fw = digits <= 0 ? 1 : digits; |
937 r_fw = i_fw + 1; | |
938 if (inf_or_nan && i_fw < 3) | |
939 { | |
940 i_fw = 3; | |
941 r_fw = 4; | |
942 } | |
3682 | 943 rd = r_fw; |
1 | 944 } |
945 else | |
946 { | |
947 int ld_max, rd_max; | |
948 if (x_max > 0) | |
949 { | |
950 ld_max = x_max; | |
1658 | 951 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 952 x_max++; |
953 } | |
954 else | |
955 { | |
956 ld_max = 1; | |
1658 | 957 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 958 x_max = -x_max + 1; |
959 } | |
960 | |
961 int ld_min, rd_min; | |
962 if (x_min > 0) | |
963 { | |
964 ld_min = x_min; | |
1658 | 965 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 966 x_min++; |
967 } | |
968 else | |
969 { | |
970 ld_min = 1; | |
1658 | 971 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 972 x_min = -x_min + 1; |
973 } | |
974 | |
975 ld = ld_max > ld_min ? ld_max : ld_min; | |
976 rd = rd_max > rd_min ? rd_max : rd_min; | |
977 | |
5945 | 978 i_fw = ld + 1 + rd; |
979 r_fw = i_fw + 1; | |
980 if (inf_or_nan && i_fw < 3) | |
981 { | |
982 i_fw = 3; | |
983 r_fw = 4; | |
984 } | |
1 | 985 } |
986 | |
6788 | 987 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 988 && (print_e |
4509 | 989 || print_g |
3105 | 990 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1 | 991 { |
4509 | 992 if (print_g) |
993 { | |
994 r_fmt = float_format (); | |
995 i_fmt = float_format (); | |
996 } | |
997 else | |
998 { | |
999 int exp_field = 4; | |
1000 if (x_max > 100 || x_min > 100) | |
1001 exp_field++; | |
1 | 1002 |
5945 | 1003 i_fw = prec + exp_field; |
1004 r_fw = i_fw + 1; | |
1005 if (inf_or_nan && i_fw < 3) | |
1006 { | |
1007 i_fw = 3; | |
1008 r_fw = 4; | |
1009 } | |
1 | 1010 |
4509 | 1011 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific); |
1012 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific); | |
1013 } | |
3608 | 1014 |
1 | 1015 if (print_big_e) |
1016 { | |
3608 | 1017 r_fmt.uppercase (); |
1018 i_fmt.uppercase (); | |
1 | 1019 } |
1020 } | |
5086 | 1021 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1022 { |
1023 r_fmt = float_format (r_fw, rd); | |
1024 i_fmt = float_format (i_fw, rd); | |
1025 } | |
1 | 1026 else |
1027 { | |
3608 | 1028 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1029 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1030 } |
1031 | |
3608 | 1032 curr_real_fmt = &r_fmt; |
1033 curr_imag_fmt = &i_fmt; | |
1 | 1034 } |
1035 | |
1658 | 1036 static void |
3105 | 1037 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658 | 1038 { |
1039 curr_real_fmt = 0; | |
1040 curr_imag_fmt = 0; | |
1041 | |
1042 if (free_format) | |
1043 return; | |
1044 | |
1045 Matrix rp = real (cm); | |
1046 Matrix ip = imag (cm); | |
1047 | |
2387 | 1048 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1049 |
2387 | 1050 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () |
1051 && ip.all_elements_are_int_or_inf_or_nan ()); | |
1658 | 1052 |
2387 | 1053 Matrix r_m_abs = rp.abs (); |
1658 | 1054 double r_max_abs = pr_max_internal (r_m_abs); |
1055 double r_min_abs = pr_min_internal (r_m_abs); | |
1056 | |
2387 | 1057 Matrix i_m_abs = ip.abs (); |
1658 | 1058 double i_max_abs = pr_max_internal (i_m_abs); |
1059 double i_min_abs = pr_min_internal (i_m_abs); | |
1060 | |
2800 | 1061 int r_x_max = r_max_abs == 0.0 |
1062 ? 0 : static_cast<int> (floor (log10 (r_max_abs) + 1.0)); | |
1063 | |
1064 int r_x_min = r_min_abs == 0.0 | |
1065 ? 0 : static_cast<int> (floor (log10 (r_min_abs) + 1.0)); | |
1658 | 1066 |
2800 | 1067 int i_x_max = i_max_abs == 0.0 |
1068 ? 0 : static_cast<int> (floor (log10 (i_max_abs) + 1.0)); | |
1069 | |
1070 int i_x_min = i_min_abs == 0.0 | |
1071 ? 0 : static_cast<int> (floor (log10 (i_min_abs) + 1.0)); | |
1658 | 1072 |
1073 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; | |
1074 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; | |
1075 | |
4270 | 1076 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : std::pow (10.0, x_max - 1); |
3105 | 1077 |
6959 | 1078 set_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, inf_or_nan, |
1079 int_or_inf_or_nan, r_fw, i_fw); | |
1658 | 1080 } |
1081 | |
1 | 1082 static inline void |
164 | 1083 set_format (const ComplexMatrix& cm) |
1 | 1084 { |
1085 int r_fw, i_fw; | |
3105 | 1086 double scale; |
1087 set_format (cm, r_fw, i_fw, scale); | |
1 | 1088 } |
1089 | |
1090 static void | |
3608 | 1091 set_range_format (bool sign, int x_max, int x_min, int all_ints, int& fw) |
1 | 1092 { |
3608 | 1093 static float_format fmt; |
1 | 1094 |
2165 | 1095 int prec = Voutput_precision; |
1 | 1096 |
1097 int ld, rd; | |
1098 | |
6788 | 1099 if (rat_format) |
1100 { | |
1101 fw = 9; | |
1102 rd = 0; | |
1103 } | |
1104 else if (bank_format) | |
1 | 1105 { |
1106 int digits = x_max > x_min ? x_max : x_min; | |
1107 fw = sign + digits < 0 ? 4 : digits + 3; | |
1108 rd = 2; | |
1109 } | |
1282 | 1110 else if (hex_format) |
1111 { | |
1112 fw = 2 * sizeof (double); | |
1113 rd = 0; | |
1114 } | |
1309 | 1115 else if (bit_format) |
1116 { | |
1117 fw = 8 * sizeof (double); | |
1118 rd = 0; | |
1119 } | |
1658 | 1120 else if (all_ints) |
1 | 1121 { |
1122 int digits = x_max > x_min ? x_max : x_min; | |
1123 fw = sign + digits; | |
3682 | 1124 rd = fw; |
1 | 1125 } |
4509 | 1126 else if (Vfixed_point_format && ! print_g) |
3105 | 1127 { |
1128 rd = prec; | |
1129 fw = rd + 2 + sign; | |
1130 } | |
1 | 1131 else |
1132 { | |
1133 int ld_max, rd_max; | |
1134 if (x_max > 0) | |
1135 { | |
1136 ld_max = x_max; | |
1658 | 1137 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 1138 x_max++; |
1139 } | |
1140 else | |
1141 { | |
1142 ld_max = 1; | |
1658 | 1143 rd_max = prec > x_max ? prec - x_max : prec; |
1 | 1144 x_max = -x_max + 1; |
1145 } | |
1146 | |
1147 int ld_min, rd_min; | |
1148 if (x_min > 0) | |
1149 { | |
1150 ld_min = x_min; | |
1658 | 1151 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 1152 x_min++; |
1153 } | |
1154 else | |
1155 { | |
1156 ld_min = 1; | |
1658 | 1157 rd_min = prec > x_min ? prec - x_min : prec; |
1 | 1158 x_min = -x_min + 1; |
1159 } | |
1160 | |
1161 ld = ld_max > ld_min ? ld_max : ld_min; | |
1162 rd = rd_max > rd_min ? rd_max : rd_min; | |
1163 | |
5832 | 1164 fw = sign + 1 + ld + 1 + rd; |
1 | 1165 } |
1166 | |
6788 | 1167 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1168 && (print_e |
4509 | 1169 || print_g |
3105 | 1170 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1 | 1171 { |
4509 | 1172 if (print_g) |
1173 fmt = float_format (); | |
1174 else | |
1175 { | |
1176 int exp_field = 4; | |
1177 if (x_max > 100 || x_min > 100) | |
1178 exp_field++; | |
1 | 1179 |
4509 | 1180 fw = sign + 2 + prec + exp_field; |
1 | 1181 |
4509 | 1182 fmt = float_format (fw, prec - 1, std::ios::scientific); |
1183 } | |
3608 | 1184 |
1 | 1185 if (print_big_e) |
3608 | 1186 fmt.uppercase (); |
1 | 1187 } |
5086 | 1188 else if (! bank_format && all_ints) |
3611 | 1189 fmt = float_format (fw, rd); |
1 | 1190 else |
3608 | 1191 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1192 |
3608 | 1193 curr_real_fmt = &fmt; |
1 | 1194 } |
1195 | |
1658 | 1196 static void |
3105 | 1197 set_format (const Range& r, int& fw, double& scale) |
1658 | 1198 { |
1199 curr_real_fmt = 0; | |
1200 curr_imag_fmt = 0; | |
1201 | |
1202 if (free_format) | |
1203 return; | |
1204 | |
1205 double r_min = r.base (); | |
1206 double r_max = r.limit (); | |
1207 | |
1208 if (r_max < r_min) | |
1209 { | |
1210 double tmp = r_max; | |
1211 r_max = r_min; | |
1212 r_min = tmp; | |
1213 } | |
1214 | |
2387 | 1215 bool sign = (r_min < 0.0); |
1658 | 1216 |
2387 | 1217 bool all_ints = r.all_elements_are_ints (); |
1658 | 1218 |
1219 double max_abs = r_max < 0.0 ? -r_max : r_max; | |
1220 double min_abs = r_min < 0.0 ? -r_min : r_min; | |
1221 | |
2800 | 1222 int x_max = max_abs == 0.0 |
1223 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); | |
1224 | |
1225 int x_min = min_abs == 0.0 | |
1226 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); | |
1658 | 1227 |
4270 | 1228 scale = (x_max == 0 || all_ints) ? 1.0 : std::pow (10.0, x_max - 1); |
3105 | 1229 |
1658 | 1230 set_range_format (sign, x_max, x_min, all_ints, fw); |
1231 } | |
1232 | |
1 | 1233 static inline void |
164 | 1234 set_format (const Range& r) |
1 | 1235 { |
1236 int fw; | |
3105 | 1237 double scale; |
1238 set_format (r, fw, scale); | |
1 | 1239 } |
1240 | |
1282 | 1241 union equiv |
1242 { | |
1243 double d; | |
1244 unsigned char i[sizeof (double)]; | |
1245 }; | |
1246 | |
1309 | 1247 #define PRINT_CHAR_BITS(os, c) \ |
1248 do \ | |
1249 { \ | |
1250 unsigned char ctmp = c; \ | |
1251 char stmp[9]; \ | |
1488 | 1252 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
1253 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ | |
1254 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ | |
1255 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ | |
1256 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ | |
1257 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ | |
1258 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ | |
1259 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ | |
1309 | 1260 stmp[8] = '\0'; \ |
3013 | 1261 os << stmp; \ |
1309 | 1262 } \ |
1263 while (0) | |
1264 | |
1265 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ | |
1266 do \ | |
1267 { \ | |
1268 unsigned char ctmp = c; \ | |
1269 char stmp[9]; \ | |
1488 | 1270 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
1271 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ | |
1272 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ | |
1273 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ | |
1274 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ | |
1275 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ | |
1276 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ | |
1277 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ | |
1309 | 1278 stmp[8] = '\0'; \ |
3013 | 1279 os << stmp; \ |
1309 | 1280 } \ |
1281 while (0) | |
1282 | |
2522 | 1283 static void |
3608 | 1284 pr_any_float (const float_format *fmt, std::ostream& os, double d, int fw = 0) |
1 | 1285 { |
529 | 1286 if (fmt) |
1 | 1287 { |
5544 | 1288 // Unless explicitly asked for, always print in big-endian |
1289 // format for hex and bit formats. | |
1290 // | |
1291 // {bit,hex}_format == 1: print big-endian | |
1292 // {bit,hex}_format == 2: print native | |
1293 | |
1282 | 1294 if (hex_format) |
1295 { | |
1296 equiv tmp; | |
1297 tmp.d = d; | |
1298 | |
1299 // Unless explicitly asked for, always print in big-endian | |
1300 // format. | |
1301 | |
5775 | 1302 // FIXME -- is it correct to swap bytes for VAX |
1282 | 1303 // formats and not for Cray? |
1304 | |
5775 | 1305 // FIXME -- will bad things happen if we are |
3013 | 1306 // interrupted before resetting the format flags and fill |
1307 // character? | |
1308 | |
2317 | 1309 oct_mach_info::float_format flt_fmt = |
1310 oct_mach_info::native_float_format (); | |
1311 | |
3013 | 1312 char ofill = os.fill ('0'); |
1313 | |
3608 | 1314 std::ios::fmtflags oflags |
1315 = os.flags (std::ios::right | std::ios::hex); | |
3013 | 1316 |
1282 | 1317 if (hex_format > 1 |
4574 | 1318 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
1319 || flt_fmt == oct_mach_info::flt_fmt_cray | |
1320 || flt_fmt == oct_mach_info::flt_fmt_unknown) | |
1282 | 1321 { |
1322 | 1322 for (size_t i = 0; i < sizeof (double); i++) |
3548 | 1323 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282 | 1324 } |
1325 else | |
1326 { | |
1328 | 1327 for (int i = sizeof (double) - 1; i >= 0; i--) |
3548 | 1328 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282 | 1329 } |
3013 | 1330 |
1331 os.fill (ofill); | |
1332 os.setf (oflags); | |
1282 | 1333 } |
1309 | 1334 else if (bit_format) |
1335 { | |
1336 equiv tmp; | |
1337 tmp.d = d; | |
1338 | |
5775 | 1339 // FIXME -- is it correct to swap bytes for VAX |
1309 | 1340 // formats and not for Cray? |
1341 | |
2317 | 1342 oct_mach_info::float_format flt_fmt = |
1343 oct_mach_info::native_float_format (); | |
1344 | |
4574 | 1345 if (flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian |
1346 || flt_fmt == oct_mach_info::flt_fmt_cray | |
1347 || flt_fmt == oct_mach_info::flt_fmt_unknown) | |
1309 | 1348 { |
1322 | 1349 for (size_t i = 0; i < sizeof (double); i++) |
1309 | 1350 PRINT_CHAR_BITS (os, tmp.i[i]); |
1351 } | |
1352 else | |
1353 { | |
1354 if (bit_format > 1) | |
1355 { | |
1328 | 1356 for (size_t i = 0; i < sizeof (double); i++) |
1309 | 1357 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
1358 } | |
1359 else | |
1360 { | |
1361 for (int i = sizeof (double) - 1; i >= 0; i--) | |
1362 PRINT_CHAR_BITS (os, tmp.i[i]); | |
1363 } | |
1364 } | |
1365 } | |
6788 | 1366 else if (octave_is_NA (d)) |
1367 { | |
1368 if (fw > 0) | |
1369 os << std::setw (fw) << "NA"; | |
1370 else | |
1371 os << "NA"; | |
1372 } | |
1373 else if (rat_format) | |
1374 os << pr_rational_float (*fmt, d); | |
1282 | 1375 else if (xisinf (d)) |
1 | 1376 { |
2804 | 1377 const char *s; |
1 | 1378 if (d < 0.0) |
1379 s = "-Inf"; | |
1380 else | |
1381 s = "Inf"; | |
1382 | |
1383 if (fw > 0) | |
3548 | 1384 os << std::setw (fw) << s; |
1 | 1385 else |
1386 os << s; | |
1387 } | |
1388 else if (xisnan (d)) | |
1389 { | |
1390 if (fw > 0) | |
3548 | 1391 os << std::setw (fw) << "NaN"; |
1 | 1392 else |
1393 os << "NaN"; | |
1394 } | |
1395 else | |
3608 | 1396 os << pr_formatted_float (*fmt, d); |
1 | 1397 } |
529 | 1398 else |
1399 os << d; | |
1 | 1400 } |
1401 | |
1402 static inline void | |
3608 | 1403 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
1 | 1404 { |
4509 | 1405 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608 | 1406 d /= scale; |
1407 | |
1 | 1408 pr_any_float (curr_real_fmt, os, d, fw); |
1409 } | |
1410 | |
1411 static inline void | |
3523 | 1412 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1 | 1413 { |
1414 pr_any_float (curr_imag_fmt, os, d, fw); | |
1415 } | |
1416 | |
2522 | 1417 static void |
3608 | 1418 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, |
1419 int i_fw = 0, double scale = 1.0) | |
1 | 1420 { |
4509 | 1421 Complex tmp |
1422 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; | |
3608 | 1423 |
1424 double r = tmp.real (); | |
1425 | |
1 | 1426 pr_float (os, r, r_fw); |
3608 | 1427 |
1 | 1428 if (! bank_format) |
1429 { | |
3608 | 1430 double i = tmp.imag (); |
4349 | 1431 if (! (hex_format || bit_format) && lo_ieee_signbit (i)) |
1 | 1432 { |
1433 os << " - "; | |
1434 i = -i; | |
1435 pr_imag_float (os, i, i_fw); | |
1436 } | |
1437 else | |
1438 { | |
1309 | 1439 if (hex_format || bit_format) |
1282 | 1440 os << " "; |
1441 else | |
1442 os << " + "; | |
1443 | |
1 | 1444 pr_imag_float (os, i, i_fw); |
1445 } | |
1446 os << "i"; | |
1447 } | |
1448 } | |
1449 | |
626 | 1450 static void |
5275 | 1451 print_empty_matrix (std::ostream& os, octave_idx_type nr, octave_idx_type nc, bool pr_as_read_syntax) |
626 | 1452 { |
1453 assert (nr == 0 || nc == 0); | |
1454 | |
1455 if (pr_as_read_syntax) | |
1456 { | |
1457 if (nr == 0 && nc == 0) | |
1458 os << "[]"; | |
1459 else | |
1460 os << "zeros (" << nr << ", " << nc << ")"; | |
1461 } | |
1462 else | |
1463 { | |
1464 os << "[]"; | |
4559 | 1465 |
2165 | 1466 if (Vprint_empty_dimensions) |
626 | 1467 os << "(" << nr << "x" << nc << ")"; |
1468 } | |
1469 } | |
1470 | |
1186 | 1471 static void |
4559 | 1472 print_empty_nd_array (std::ostream& os, const dim_vector& dims, |
1473 bool pr_as_read_syntax) | |
1474 { | |
1475 assert (dims.any_zero ()); | |
1476 | |
1477 if (pr_as_read_syntax) | |
1478 os << "zeros (" << dims.str (',') << ")"; | |
1479 else | |
1480 { | |
1481 os << "[]"; | |
1482 | |
1483 if (Vprint_empty_dimensions) | |
1484 os << "(" << dims.str () << ")"; | |
1485 } | |
1486 } | |
1487 | |
1488 static void | |
3523 | 1489 pr_scale_header (std::ostream& os, double scale) |
3105 | 1490 { |
4509 | 1491 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105 | 1492 { |
3568 | 1493 os << " " |
1494 << std::setw (8) << std::setprecision (1) | |
1495 << std::setiosflags (std::ios::scientific|std::ios::left) | |
1496 << scale | |
1497 << std::resetiosflags (std::ios::scientific|std::ios::left) | |
1498 << " *\n"; | |
3105 | 1499 |
1500 if (! compact_format) | |
1501 os << "\n"; | |
1502 } | |
1503 } | |
1504 | |
1505 static void | |
5275 | 1506 pr_col_num_header (std::ostream& os, octave_idx_type total_width, int max_width, |
1507 octave_idx_type lim, octave_idx_type col, int extra_indent) | |
1186 | 1508 { |
2165 | 1509 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1510 { |
4833 | 1511 if (col != 0) |
1512 { | |
1513 if (compact_format) | |
1514 os << "\n"; | |
1515 else | |
1516 os << "\n\n"; | |
1517 } | |
1186 | 1518 |
5275 | 1519 octave_idx_type num_cols = lim - col; |
1186 | 1520 |
3548 | 1521 os << std::setw (extra_indent) << ""; |
1972 | 1522 |
1186 | 1523 if (num_cols == 1) |
1524 os << " Column " << col + 1 << ":\n"; | |
1525 else if (num_cols == 2) | |
1526 os << " Columns " << col + 1 << " and " << lim << ":\n"; | |
1527 else | |
1528 os << " Columns " << col + 1 << " through " << lim << ":\n"; | |
2915 | 1529 |
1530 if (! compact_format) | |
1531 os << "\n"; | |
1186 | 1532 } |
1533 } | |
1534 | |
5030 | 1535 template <class T> |
6018 | 1536 /* static */ inline void |
5030 | 1537 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1538 { |
5030 | 1539 if (val > T (0)) |
4632 | 1540 os << plus_format_chars[0]; |
5030 | 1541 else if (val < T (0)) |
4632 | 1542 os << plus_format_chars[1]; |
3248 | 1543 else |
4632 | 1544 os << plus_format_chars[2]; |
3248 | 1545 } |
1546 | |
1 | 1547 void |
4661 | 1548 octave_print_internal (std::ostream& os, double d, |
1549 bool /* pr_as_read_syntax */) | |
1 | 1550 { |
1551 if (plus_format) | |
1552 { | |
3608 | 1553 pr_plus_format (os, d); |
1 | 1554 } |
1555 else | |
1556 { | |
1557 set_format (d); | |
1558 if (free_format) | |
1559 os << d; | |
1560 else | |
1561 pr_float (os, d); | |
1562 } | |
1563 } | |
1564 | |
1565 void | |
3608 | 1566 octave_print_internal (std::ostream& os, const Matrix& m, |
1567 bool pr_as_read_syntax, int extra_indent) | |
1 | 1568 { |
5275 | 1569 octave_idx_type nr = m.rows (); |
1570 octave_idx_type nc = m.columns (); | |
1 | 1571 |
2408 | 1572 if (nr == 0 || nc == 0) |
626 | 1573 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1574 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1575 { |
5275 | 1576 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1577 { |
5275 | 1578 for (octave_idx_type j = 0; j < nc; j++) |
1 | 1579 { |
4153 | 1580 OCTAVE_QUIT; |
1581 | |
3608 | 1582 pr_plus_format (os, m(i,j)); |
1 | 1583 } |
2907 | 1584 |
1585 if (i < nr - 1) | |
1586 os << "\n"; | |
1 | 1587 } |
1588 } | |
1589 else | |
1590 { | |
1591 int fw; | |
3105 | 1592 double scale = 1.0; |
1593 set_format (m, fw, scale); | |
1 | 1594 int column_width = fw + 2; |
5275 | 1595 octave_idx_type total_width = nc * column_width; |
1596 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 1597 |
626 | 1598 if (pr_as_read_syntax) |
1599 max_width -= 4; | |
1972 | 1600 else |
1601 max_width -= extra_indent; | |
1602 | |
1603 if (max_width < 0) | |
1604 max_width = 0; | |
626 | 1605 |
1 | 1606 if (free_format) |
1607 { | |
626 | 1608 if (pr_as_read_syntax) |
1609 os << "[\n"; | |
1610 | |
1 | 1611 os << m; |
626 | 1612 |
1613 if (pr_as_read_syntax) | |
1614 os << "]"; | |
1615 | |
1 | 1616 return; |
1617 } | |
1618 | |
5275 | 1619 octave_idx_type inc = nc; |
2165 | 1620 if (total_width > max_width && Vsplit_long_rows) |
1 | 1621 { |
1622 inc = max_width / column_width; | |
1623 if (inc == 0) | |
1624 inc++; | |
1625 } | |
1626 | |
626 | 1627 if (pr_as_read_syntax) |
1 | 1628 { |
5275 | 1629 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1630 { |
5275 | 1631 octave_idx_type col = 0; |
626 | 1632 while (col < nc) |
1 | 1633 { |
5275 | 1634 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
1635 | |
1636 for (octave_idx_type j = col; j < lim; j++) | |
626 | 1637 { |
4153 | 1638 OCTAVE_QUIT; |
1639 | |
626 | 1640 if (i == 0 && j == 0) |
1641 os << "[ "; | |
1642 else | |
1643 { | |
1644 if (j > col && j < lim) | |
1645 os << ", "; | |
1646 else | |
1647 os << " "; | |
1648 } | |
1649 | |
3608 | 1650 pr_float (os, m(i,j)); |
626 | 1651 } |
1652 | |
1653 col += inc; | |
1654 | |
1655 if (col >= nc) | |
1656 { | |
1657 if (i == nr - 1) | |
1658 os << " ]"; | |
1659 else | |
1660 os << ";\n"; | |
1661 } | |
1662 else | |
1663 os << " ...\n"; | |
1 | 1664 } |
1665 } | |
626 | 1666 } |
1667 else | |
1668 { | |
3105 | 1669 pr_scale_header (os, scale); |
1670 | |
5275 | 1671 for (octave_idx_type col = 0; col < nc; col += inc) |
626 | 1672 { |
5275 | 1673 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
626 | 1674 |
1972 | 1675 pr_col_num_header (os, total_width, max_width, lim, col, |
1676 extra_indent); | |
626 | 1677 |
5275 | 1678 for (octave_idx_type i = 0; i < nr; i++) |
626 | 1679 { |
3548 | 1680 os << std::setw (extra_indent) << ""; |
1972 | 1681 |
5275 | 1682 for (octave_idx_type j = col; j < lim; j++) |
626 | 1683 { |
4153 | 1684 OCTAVE_QUIT; |
1685 | |
626 | 1686 os << " "; |
1687 | |
3608 | 1688 pr_float (os, m(i,j), fw, scale); |
626 | 1689 } |
1690 | |
2907 | 1691 if (i < nr - 1) |
1692 os << "\n"; | |
626 | 1693 } |
1694 } | |
1 | 1695 } |
1696 } | |
1697 } | |
1698 | |
4532 | 1699 #define PRINT_ND_ARRAY(os, nda, NDA_T, ELT_T, MAT_T) \ |
1700 do \ | |
1701 { \ | |
4559 | 1702 if (nda.is_empty ()) \ |
1703 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); \ | |
1704 else \ | |
1705 { \ | |
4532 | 1706 \ |
4559 | 1707 int ndims = nda.ndims (); \ |
1708 \ | |
1709 dim_vector dims = nda.dims (); \ | |
4532 | 1710 \ |
5275 | 1711 Array<octave_idx_type> ra_idx (ndims, 0); \ |
4532 | 1712 \ |
5275 | 1713 octave_idx_type m = 1; \ |
4532 | 1714 \ |
4559 | 1715 for (int i = 2; i < ndims; i++) \ |
1716 m *= dims(i); \ | |
1717 \ | |
5275 | 1718 octave_idx_type nr = dims(0); \ |
1719 octave_idx_type nc = dims(1); \ | |
4532 | 1720 \ |
5275 | 1721 for (octave_idx_type i = 0; i < m; i++) \ |
4559 | 1722 { \ |
4655 | 1723 OCTAVE_QUIT; \ |
1724 \ | |
4559 | 1725 std::string nm = "ans"; \ |
4532 | 1726 \ |
4559 | 1727 if (m > 1) \ |
1728 { \ | |
1729 nm += "(:,:,"; \ | |
4532 | 1730 \ |
5765 | 1731 std::ostringstream buf; \ |
4532 | 1732 \ |
4559 | 1733 for (int k = 2; k < ndims; k++) \ |
1734 { \ | |
1735 buf << ra_idx(k) + 1; \ | |
4532 | 1736 \ |
4559 | 1737 if (k < ndims - 1) \ |
1738 buf << ","; \ | |
1739 else \ | |
1740 buf << ")"; \ | |
1741 } \ | |
4532 | 1742 \ |
5765 | 1743 nm += buf.str (); \ |
4559 | 1744 } \ |
4532 | 1745 \ |
4559 | 1746 Array<idx_vector> idx (ndims); \ |
4532 | 1747 \ |
4559 | 1748 idx(0) = idx_vector (':'); \ |
1749 idx(1) = idx_vector (':'); \ | |
1750 \ | |
1751 for (int k = 2; k < ndims; k++) \ | |
1752 idx(k) = idx_vector (ra_idx(k) + 1); \ | |
4532 | 1753 \ |
4559 | 1754 octave_value page \ |
1755 = MAT_T (Array2<ELT_T> (nda.index (idx), nr, nc)); \ | |
1756 \ | |
1757 page.print_with_name (os, nm); \ | |
4532 | 1758 \ |
4559 | 1759 if (i < m) \ |
1760 NDA_T::increment_index (ra_idx, dims, 2); \ | |
1761 } \ | |
1762 } \ | |
4532 | 1763 } \ |
1764 while (0) | |
1765 | |
4513 | 1766 void |
1767 octave_print_internal (std::ostream& os, const NDArray& nda, | |
1768 bool pr_as_read_syntax, int extra_indent) | |
1769 { | |
1770 switch (nda.ndims ()) | |
1771 { | |
1772 case 1: | |
1773 case 2: | |
1774 octave_print_internal (os, nda.matrix_value (), | |
1775 pr_as_read_syntax, extra_indent); | |
1776 break; | |
1777 | |
1778 default: | |
4532 | 1779 PRINT_ND_ARRAY (os, nda, NDArray, double, Matrix); |
4513 | 1780 break; |
1781 } | |
1782 } | |
1783 | |
5030 | 1784 template <> |
6018 | 1785 /* static */ inline void |
6015 | 1786 pr_plus_format<> (std::ostream& os, const Complex& c) |
3248 | 1787 { |
1788 double rp = c.real (); | |
1789 double ip = c.imag (); | |
1790 | |
1791 if (rp == 0.0) | |
1792 { | |
1793 if (ip == 0.0) | |
1794 os << " "; | |
1795 else | |
1796 os << "i"; | |
1797 } | |
1798 else if (ip == 0.0) | |
3608 | 1799 pr_plus_format (os, rp); |
3248 | 1800 else |
1801 os << "c"; | |
1802 } | |
1803 | |
1 | 1804 void |
3523 | 1805 octave_print_internal (std::ostream& os, const Complex& c, |
4661 | 1806 bool /* pr_as_read_syntax */) |
1 | 1807 { |
1808 if (plus_format) | |
1809 { | |
3608 | 1810 pr_plus_format (os, c); |
1 | 1811 } |
1812 else | |
1813 { | |
1814 set_format (c); | |
1815 if (free_format) | |
1816 os << c; | |
1817 else | |
1818 pr_complex (os, c); | |
1819 } | |
1820 } | |
1821 | |
1822 void | |
3523 | 1823 octave_print_internal (std::ostream& os, const ComplexMatrix& cm, |
1972 | 1824 bool pr_as_read_syntax, int extra_indent) |
1 | 1825 { |
5275 | 1826 octave_idx_type nr = cm.rows (); |
1827 octave_idx_type nc = cm.columns (); | |
1 | 1828 |
2408 | 1829 if (nr == 0 || nc == 0) |
626 | 1830 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1831 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1832 { |
5275 | 1833 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1834 { |
5275 | 1835 for (octave_idx_type j = 0; j < nc; j++) |
1 | 1836 { |
4153 | 1837 OCTAVE_QUIT; |
1838 | |
3608 | 1839 pr_plus_format (os, cm(i,j)); |
1 | 1840 } |
2907 | 1841 |
1842 if (i < nr - 1) | |
1843 os << "\n"; | |
1 | 1844 } |
1845 } | |
1846 else | |
1847 { | |
1848 int r_fw, i_fw; | |
3105 | 1849 double scale = 1.0; |
1850 set_format (cm, r_fw, i_fw, scale); | |
1 | 1851 int column_width = i_fw + r_fw; |
6788 | 1852 column_width += (rat_format || bank_format || hex_format |
1853 || bit_format) ? 2 : 7; | |
5275 | 1854 octave_idx_type total_width = nc * column_width; |
1855 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 1856 |
626 | 1857 if (pr_as_read_syntax) |
1858 max_width -= 4; | |
1972 | 1859 else |
1860 max_width -= extra_indent; | |
1861 | |
1862 if (max_width < 0) | |
1863 max_width = 0; | |
626 | 1864 |
1 | 1865 if (free_format) |
1866 { | |
626 | 1867 if (pr_as_read_syntax) |
1868 os << "[\n"; | |
1869 | |
1 | 1870 os << cm; |
626 | 1871 |
1872 if (pr_as_read_syntax) | |
1873 os << "]"; | |
1874 | |
1 | 1875 return; |
1876 } | |
1877 | |
5275 | 1878 octave_idx_type inc = nc; |
2165 | 1879 if (total_width > max_width && Vsplit_long_rows) |
1 | 1880 { |
1881 inc = max_width / column_width; | |
1882 if (inc == 0) | |
1883 inc++; | |
1884 } | |
1885 | |
626 | 1886 if (pr_as_read_syntax) |
1 | 1887 { |
5275 | 1888 for (octave_idx_type i = 0; i < nr; i++) |
1 | 1889 { |
5275 | 1890 octave_idx_type col = 0; |
626 | 1891 while (col < nc) |
1 | 1892 { |
5275 | 1893 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
1894 | |
1895 for (octave_idx_type j = col; j < lim; j++) | |
626 | 1896 { |
4153 | 1897 OCTAVE_QUIT; |
1898 | |
626 | 1899 if (i == 0 && j == 0) |
1900 os << "[ "; | |
1901 else | |
1902 { | |
1903 if (j > col && j < lim) | |
1904 os << ", "; | |
1905 else | |
1906 os << " "; | |
1907 } | |
1908 | |
3608 | 1909 pr_complex (os, cm(i,j)); |
626 | 1910 } |
1911 | |
1912 col += inc; | |
1913 | |
1914 if (col >= nc) | |
1915 { | |
1916 if (i == nr - 1) | |
1917 os << " ]"; | |
1918 else | |
1919 os << ";\n"; | |
1920 } | |
1 | 1921 else |
626 | 1922 os << " ...\n"; |
1 | 1923 } |
1924 } | |
626 | 1925 } |
1926 else | |
1927 { | |
3105 | 1928 pr_scale_header (os, scale); |
1929 | |
5275 | 1930 for (octave_idx_type col = 0; col < nc; col += inc) |
626 | 1931 { |
5275 | 1932 octave_idx_type lim = col + inc < nc ? col + inc : nc; |
626 | 1933 |
1972 | 1934 pr_col_num_header (os, total_width, max_width, lim, col, |
1935 extra_indent); | |
626 | 1936 |
5275 | 1937 for (octave_idx_type i = 0; i < nr; i++) |
626 | 1938 { |
3548 | 1939 os << std::setw (extra_indent) << ""; |
1972 | 1940 |
5275 | 1941 for (octave_idx_type j = col; j < lim; j++) |
626 | 1942 { |
4153 | 1943 OCTAVE_QUIT; |
1944 | |
626 | 1945 os << " "; |
1946 | |
3608 | 1947 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
626 | 1948 } |
2907 | 1949 |
1950 if (i < nr - 1) | |
1951 os << "\n"; | |
626 | 1952 } |
1953 } | |
1 | 1954 } |
1955 } | |
1956 } | |
1957 | |
1958 void | |
4513 | 1959 octave_print_internal (std::ostream& os, const ComplexNDArray& nda, |
1960 bool pr_as_read_syntax, int extra_indent) | |
1961 { | |
1962 switch (nda.ndims ()) | |
1963 { | |
1964 case 1: | |
1965 case 2: | |
1966 octave_print_internal (os, nda.matrix_value (), | |
1967 pr_as_read_syntax, extra_indent); | |
1968 break; | |
1969 | |
1970 default: | |
4532 | 1971 PRINT_ND_ARRAY (os, nda, ComplexNDArray, Complex, ComplexMatrix); |
4513 | 1972 break; |
1973 } | |
1974 } | |
1975 | |
1976 void | |
3523 | 1977 octave_print_internal (std::ostream& os, const Range& r, |
1972 | 1978 bool pr_as_read_syntax, int extra_indent) |
1 | 1979 { |
626 | 1980 double base = r.base (); |
1 | 1981 double increment = r.inc (); |
626 | 1982 double limit = r.limit (); |
5275 | 1983 octave_idx_type num_elem = r.nelem (); |
1 | 1984 |
626 | 1985 if (plus_format && ! pr_as_read_syntax) |
1 | 1986 { |
5275 | 1987 for (octave_idx_type i = 0; i < num_elem; i++) |
1 | 1988 { |
4153 | 1989 OCTAVE_QUIT; |
1990 | |
626 | 1991 double val = base + i * increment; |
4632 | 1992 |
1993 pr_plus_format (os, val); | |
1 | 1994 } |
1995 } | |
1996 else | |
1997 { | |
1998 int fw; | |
3105 | 1999 double scale = 1.0; |
2000 set_format (r, fw, scale); | |
1 | 2001 |
626 | 2002 if (pr_as_read_syntax) |
1 | 2003 { |
626 | 2004 if (free_format) |
2005 { | |
2006 os << base << " : "; | |
2007 if (increment != 1.0) | |
2008 os << increment << " : "; | |
2009 os << limit; | |
2010 } | |
2011 else | |
2012 { | |
2013 pr_float (os, base, fw); | |
2014 os << " : "; | |
2015 if (increment != 1.0) | |
2016 { | |
2017 pr_float (os, increment, fw); | |
2018 os << " : "; | |
2019 } | |
2020 pr_float (os, limit, fw); | |
2021 } | |
1 | 2022 } |
626 | 2023 else |
2024 { | |
2025 int column_width = fw + 2; | |
5275 | 2026 octave_idx_type total_width = num_elem * column_width; |
2027 octave_idx_type max_width = command_editor::terminal_cols (); | |
1 | 2028 |
626 | 2029 if (free_format) |
2030 { | |
2031 os << r; | |
2032 return; | |
2033 } | |
1 | 2034 |
5275 | 2035 octave_idx_type inc = num_elem; |
2165 | 2036 if (total_width > max_width && Vsplit_long_rows) |
1 | 2037 { |
626 | 2038 inc = max_width / column_width; |
2039 if (inc == 0) | |
2040 inc++; | |
1 | 2041 } |
2042 | |
1972 | 2043 max_width -= extra_indent; |
2044 | |
2045 if (max_width < 0) | |
2046 max_width = 0; | |
2047 | |
3105 | 2048 pr_scale_header (os, scale); |
2049 | |
5275 | 2050 octave_idx_type col = 0; |
626 | 2051 while (col < num_elem) |
1 | 2052 { |
5275 | 2053 octave_idx_type lim = col + inc < num_elem ? col + inc : num_elem; |
626 | 2054 |
1972 | 2055 pr_col_num_header (os, total_width, max_width, lim, col, |
2056 extra_indent); | |
2057 | |
3548 | 2058 os << std::setw (extra_indent) << ""; |
626 | 2059 |
5275 | 2060 for (octave_idx_type i = col; i < lim; i++) |
626 | 2061 { |
4153 | 2062 OCTAVE_QUIT; |
2063 | |
626 | 2064 double val = base + i * increment; |
3105 | 2065 |
4791 | 2066 if (i == num_elem - 1) |
2067 { | |
2068 // See the comments in Range::matrix_value. | |
2069 | |
2070 if ((increment > 0 && val > limit) | |
2071 || (increment < 0 && val < limit)) | |
2072 val = limit; | |
2073 } | |
2074 | |
626 | 2075 os << " "; |
3105 | 2076 |
3608 | 2077 pr_float (os, val, fw, scale); |
626 | 2078 } |
2079 | |
2907 | 2080 col += inc; |
1 | 2081 } |
2082 } | |
2083 } | |
2084 } | |
2085 | |
1343 | 2086 void |
3523 | 2087 octave_print_internal (std::ostream& os, const boolMatrix& bm, |
3215 | 2088 bool pr_as_read_syntax, |
2089 int extra_indent) | |
2090 { | |
2091 Matrix tmp (bm); | |
2092 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); | |
2093 } | |
2094 | |
2095 void | |
4513 | 2096 octave_print_internal (std::ostream& os, const boolNDArray& nda, |
2097 bool pr_as_read_syntax, | |
2098 int extra_indent) | |
2099 { | |
2100 switch (nda.ndims ()) | |
2101 { | |
2102 case 1: | |
2103 case 2: | |
2104 octave_print_internal (os, nda.matrix_value (), | |
2105 pr_as_read_syntax, extra_indent); | |
2106 break; | |
2107 | |
2108 default: | |
4532 | 2109 PRINT_ND_ARRAY (os, nda, boolNDArray, bool, boolMatrix); |
4513 | 2110 break; |
2111 } | |
2112 } | |
2113 | |
2114 void | |
3523 | 2115 octave_print_internal (std::ostream& os, const charMatrix& chm, |
3215 | 2116 bool pr_as_read_syntax, |
5775 | 2117 int /* extra_indent FIXME */, |
3215 | 2118 bool pr_as_string) |
1343 | 2119 { |
1572 | 2120 if (pr_as_string) |
2121 { | |
5275 | 2122 octave_idx_type nstr = chm.rows (); |
1343 | 2123 |
1572 | 2124 if (pr_as_read_syntax && nstr > 1) |
2125 os << "[ "; | |
1343 | 2126 |
2907 | 2127 if (nstr != 0) |
1343 | 2128 { |
5275 | 2129 for (octave_idx_type i = 0; i < nstr; i++) |
1572 | 2130 { |
4153 | 2131 OCTAVE_QUIT; |
2132 | |
3523 | 2133 std::string row = chm.row_as_string (i); |
2664 | 2134 |
2135 if (pr_as_read_syntax) | |
2136 { | |
2137 os << "\"" << undo_string_escapes (row) << "\""; | |
1343 | 2138 |
2664 | 2139 if (i < nstr - 1) |
2140 os << "; "; | |
2141 } | |
2142 else | |
2907 | 2143 { |
2144 os << row; | |
2145 | |
2146 if (i < nstr - 1) | |
2147 os << "\n"; | |
2148 } | |
1572 | 2149 } |
1343 | 2150 } |
1572 | 2151 |
2152 if (pr_as_read_syntax && nstr > 1) | |
2153 os << " ]"; | |
1343 | 2154 } |
1572 | 2155 else |
2156 { | |
2157 os << "sorry, printing char matrices not implemented yet\n"; | |
2158 } | |
1343 | 2159 } |
2160 | |
4513 | 2161 void |
2162 octave_print_internal (std::ostream& os, const charNDArray& nda, | |
4663 | 2163 bool pr_as_read_syntax, int extra_indent, |
4513 | 2164 bool pr_as_string) |
2165 { | |
2166 switch (nda.ndims ()) | |
2167 { | |
2168 case 1: | |
2169 case 2: | |
2170 octave_print_internal (os, nda.matrix_value (), | |
2171 pr_as_read_syntax, extra_indent, pr_as_string); | |
2172 break; | |
2173 | |
2174 default: | |
4532 | 2175 PRINT_ND_ARRAY (os, nda, charNDArray, char, charMatrix); |
4513 | 2176 break; |
2177 } | |
2178 } | |
2179 | |
4655 | 2180 void |
4925 | 2181 octave_print_internal (std::ostream& os, const std::string& s, |
2182 bool pr_as_read_syntax, int extra_indent) | |
2183 { | |
2184 ArrayN<std::string> nda (dim_vector (1, 1), s); | |
2185 | |
2186 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2187 } | |
2188 | |
2189 void | |
4655 | 2190 octave_print_internal (std::ostream& os, const ArrayN<std::string>& nda, |
4663 | 2191 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2192 { |
5775 | 2193 // FIXME -- this mostly duplicates the code in the |
4655 | 2194 // PRINT_ND_ARRAY macro. |
2195 | |
2196 if (nda.is_empty ()) | |
2197 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
2198 else if (nda.length () == 1) | |
2199 { | |
2200 os << nda(0); | |
2201 } | |
2202 else | |
2203 { | |
2204 int ndims = nda.ndims (); | |
2205 | |
2206 dim_vector dims = nda.dims (); | |
2207 | |
5275 | 2208 Array<octave_idx_type> ra_idx (ndims, 0); |
2209 | |
2210 octave_idx_type m = 1; | |
4655 | 2211 |
2212 for (int i = 2; i < ndims; i++) | |
2213 m *= dims(i); | |
2214 | |
5275 | 2215 octave_idx_type nr = dims(0); |
2216 octave_idx_type nc = dims(1); | |
2217 | |
2218 for (octave_idx_type i = 0; i < m; i++) | |
4655 | 2219 { |
2220 std::string nm = "ans"; | |
2221 | |
2222 if (m > 1) | |
2223 { | |
2224 nm += "(:,:,"; | |
2225 | |
5765 | 2226 std::ostringstream buf; |
4655 | 2227 |
2228 for (int k = 2; k < ndims; k++) | |
2229 { | |
2230 buf << ra_idx(k) + 1; | |
2231 | |
2232 if (k < ndims - 1) | |
2233 buf << ","; | |
2234 else | |
2235 buf << ")"; | |
2236 } | |
2237 | |
5765 | 2238 nm += buf.str (); |
4655 | 2239 } |
2240 | |
2241 Array<idx_vector> idx (ndims); | |
2242 | |
2243 idx(0) = idx_vector (':'); | |
2244 idx(1) = idx_vector (':'); | |
2245 | |
2246 for (int k = 2; k < ndims; k++) | |
2247 idx(k) = idx_vector (ra_idx(k) + 1); | |
2248 | |
2249 Array2<std::string> page (nda.index (idx), nr, nc); | |
2250 | |
5775 | 2251 // FIXME -- need to do some more work to put these |
4655 | 2252 // in neatly aligned columns... |
2253 | |
5275 | 2254 octave_idx_type n_rows = page.rows (); |
2255 octave_idx_type n_cols = page.cols (); | |
4655 | 2256 |
2257 os << nm << " =\n\n"; | |
2258 | |
5275 | 2259 for (octave_idx_type ii = 0; ii < n_rows; ii++) |
4655 | 2260 { |
5275 | 2261 for (octave_idx_type jj = 0; jj < n_cols; jj++) |
4655 | 2262 os << " " << page(ii,jj); |
2263 | |
2264 os << "\n"; | |
2265 } | |
2266 | |
2267 if (i < m - 1) | |
2268 os << "\n"; | |
2269 | |
2270 if (i < m) | |
2271 increment_index (ra_idx, dims, 2); | |
2272 } | |
2273 } | |
2274 } | |
2275 | |
4901 | 2276 template <class T> |
2277 class | |
2278 octave_print_conv | |
2279 { | |
2280 public: | |
2281 typedef T print_conv_type; | |
2282 }; | |
2283 | |
2284 #define PRINT_CONV(T1, T2) \ | |
2285 template <> \ | |
2286 class \ | |
2287 octave_print_conv<T1> \ | |
2288 { \ | |
2289 public: \ | |
2290 typedef T2 print_conv_type; \ | |
2291 } | |
2292 | |
2293 PRINT_CONV (octave_int8, octave_int16); | |
2294 PRINT_CONV (octave_uint8, octave_uint16); | |
2295 | |
2296 #undef PRINT_CONV | |
2297 | |
2298 template <class T> | |
6018 | 2299 /* static */ inline void |
4949 | 2300 pr_int (std::ostream& os, const T& d, int fw = 0) |
2301 { | |
2302 size_t sz = d.byte_size(); | |
2303 const unsigned char * tmpi = d.iptr(); | |
2304 | |
5544 | 2305 // Unless explicitly asked for, always print in big-endian |
2306 // format for hex and bit formats. | |
2307 // | |
2308 // {bit,hex}_format == 1: print big-endian | |
2309 // {bit,hex}_format == 2: print native | |
2310 | |
4949 | 2311 if (hex_format) |
2312 { | |
2313 char ofill = os.fill ('0'); | |
2314 | |
2315 std::ios::fmtflags oflags | |
2316 = os.flags (std::ios::right | std::ios::hex); | |
2317 | |
2318 if (hex_format > 1 || oct_mach_info::words_big_endian ()) | |
2319 { | |
2320 for (size_t i = 0; i < sz; i++) | |
2321 os << std::setw (2) << static_cast<int> (tmpi[i]); | |
2322 } | |
2323 else | |
2324 { | |
2325 for (int i = sz - 1; i >= 0; i--) | |
2326 os << std::setw (2) << static_cast<int> (tmpi[i]); | |
2327 } | |
2328 | |
2329 os.fill (ofill); | |
2330 os.setf (oflags); | |
2331 } | |
2332 else if (bit_format) | |
2333 { | |
5544 | 2334 if (oct_mach_info::words_big_endian ()) |
4949 | 2335 { |
2336 for (size_t i = 0; i < sz; i++) | |
5544 | 2337 PRINT_CHAR_BITS (os, tmpi[i]); |
4949 | 2338 } |
2339 else | |
2340 { | |
5544 | 2341 if (bit_format > 1) |
2342 { | |
2343 for (size_t i = 0; i < sz; i++) | |
2344 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); | |
2345 } | |
2346 else | |
2347 { | |
2348 for (int i = sz - 1; i >= 0; i--) | |
2349 PRINT_CHAR_BITS (os, tmpi[i]); | |
2350 } | |
4949 | 2351 } |
2352 } | |
2353 else | |
2354 { | |
2355 os << std::setw (fw) | |
2356 << typename octave_print_conv<T>::print_conv_type (d); | |
2357 | |
2358 if (bank_format) | |
2359 os << ".00"; | |
2360 } | |
2361 } | |
2362 | |
6120 | 2363 // FIXME -- all this mess with abs is an attempt to avoid seeing |
2364 // | |
2365 // warning: comparison of unsigned expression < 0 is always false | |
2366 // | |
2367 // from GCC. Isn't there a better way | |
2368 | |
4949 | 2369 template <class T> |
6018 | 2370 /* static */ inline T |
6008 | 2371 abs (T x) |
2372 { | |
6120 | 2373 return x < 0 ? -x : x; |
6008 | 2374 } |
2375 | |
6120 | 2376 #define INSTANTIATE_ABS(T) \ |
2377 template /* static */ inline T abs (T) | |
2378 | |
2379 INSTANTIATE_ABS(signed char); | |
2380 INSTANTIATE_ABS(short); | |
2381 INSTANTIATE_ABS(int); | |
2382 INSTANTIATE_ABS(long); | |
2383 INSTANTIATE_ABS(long long); | |
2384 | |
2385 #define SPECIALIZE_UABS(T) \ | |
2386 template <> \ | |
2387 /* static */ inline unsigned T \ | |
2388 abs (unsigned T x) \ | |
2389 { \ | |
2390 return x; \ | |
2391 } | |
2392 | |
2393 SPECIALIZE_UABS(char) | |
2394 SPECIALIZE_UABS(short) | |
2395 SPECIALIZE_UABS(int) | |
2396 SPECIALIZE_UABS(long) | |
2397 SPECIALIZE_UABS(long long) | |
6008 | 2398 |
7215 | 2399 template void |
2400 pr_int (std::ostream&, const octave_int8&, int); | |
2401 | |
2402 template void | |
2403 pr_int (std::ostream&, const octave_int16&, int); | |
2404 | |
2405 template void | |
2406 pr_int (std::ostream&, const octave_int32&, int); | |
2407 | |
2408 template void | |
2409 pr_int (std::ostream&, const octave_int64&, int); | |
2410 | |
2411 template void | |
2412 pr_int (std::ostream&, const octave_uint8&, int); | |
2413 | |
2414 template void | |
2415 pr_int (std::ostream&, const octave_uint16&, int); | |
2416 | |
2417 template void | |
2418 pr_int (std::ostream&, const octave_uint32&, int); | |
2419 | |
2420 template void | |
2421 pr_int (std::ostream&, const octave_uint64&, int); | |
2422 | |
6008 | 2423 template <class T> |
4901 | 2424 void |
7215 | 2425 octave_print_internal_template (std::ostream& os, const octave_int<T>& val, |
2426 bool) | |
2427 { | |
2428 if (plus_format) | |
2429 { | |
2430 pr_plus_format (os, val); | |
2431 } | |
2432 else | |
2433 { | |
2434 if (free_format) | |
2435 os << typename octave_print_conv<octave_int<T> >::print_conv_type (val); | |
2436 else | |
2437 pr_int (os, val); | |
2438 } | |
2439 } | |
2440 | |
2441 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ | |
2442 OCTINTERP_API void \ | |
2443 octave_print_internal (std::ostream& os, const octave_int<TYPE>& val, bool dummy) \ | |
2444 { \ | |
2445 octave_print_internal_template (os, val, dummy); \ | |
2446 } | |
2447 | |
2448 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
2449 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
2450 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
2451 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
2452 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
2453 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
2454 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
2455 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
2456 | |
2457 template <class T> | |
2458 /* static */ inline void | |
2459 octave_print_internal_template (std::ostream& os, const intNDArray<T>& nda, | |
2460 bool pr_as_read_syntax, int extra_indent) | |
4901 | 2461 { |
5775 | 2462 // FIXME -- this mostly duplicates the code in the |
4901 | 2463 // PRINT_ND_ARRAY macro. |
2464 | |
2465 if (nda.is_empty ()) | |
2466 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax); | |
2467 else if (nda.length () == 1) | |
7215 | 2468 octave_print_internal_template (os, nda(0), pr_as_read_syntax); |
4949 | 2469 else if (plus_format && ! pr_as_read_syntax) |
4901 | 2470 { |
2471 int ndims = nda.ndims (); | |
2472 | |
5275 | 2473 Array<octave_idx_type> ra_idx (ndims, 0); |
4949 | 2474 |
4901 | 2475 dim_vector dims = nda.dims (); |
2476 | |
5275 | 2477 octave_idx_type m = 1; |
4901 | 2478 |
2479 for (int i = 2; i < ndims; i++) | |
2480 m *= dims(i); | |
2481 | |
5275 | 2482 octave_idx_type nr = dims(0); |
2483 octave_idx_type nc = dims(1); | |
2484 | |
2485 for (octave_idx_type i = 0; i < m; i++) | |
4901 | 2486 { |
2487 if (m > 1) | |
2488 { | |
4949 | 2489 std::string nm = "ans(:,:,"; |
4901 | 2490 |
5765 | 2491 std::ostringstream buf; |
4901 | 2492 |
2493 for (int k = 2; k < ndims; k++) | |
2494 { | |
2495 buf << ra_idx(k) + 1; | |
2496 | |
2497 if (k < ndims - 1) | |
2498 buf << ","; | |
2499 else | |
2500 buf << ")"; | |
2501 } | |
2502 | |
5765 | 2503 nm += buf.str (); |
4949 | 2504 |
2505 os << nm << " =\n\n"; | |
4901 | 2506 } |
2507 | |
2508 Array<idx_vector> idx (ndims); | |
2509 | |
2510 idx(0) = idx_vector (':'); | |
2511 idx(1) = idx_vector (':'); | |
2512 | |
2513 for (int k = 2; k < ndims; k++) | |
2514 idx(k) = idx_vector (ra_idx(k) + 1); | |
2515 | |
2516 Array2<T> page (nda.index (idx), nr, nc); | |
2517 | |
5275 | 2518 for (octave_idx_type ii = 0; ii < nr; ii++) |
4901 | 2519 { |
5275 | 2520 for (octave_idx_type jj = 0; jj < nc; jj++) |
4949 | 2521 { |
2522 OCTAVE_QUIT; | |
2523 | |
2524 pr_plus_format (os, page(ii,jj)); | |
2525 } | |
2526 | |
2527 if ((ii < nr - 1) || (i < m -1)) | |
2528 os << "\n"; | |
4901 | 2529 } |
2530 | |
2531 if (i < m - 1) | |
4949 | 2532 { |
2533 os << "\n"; | |
2534 increment_index (ra_idx, dims, 2); | |
2535 } | |
2536 } | |
2537 } | |
2538 else | |
2539 { | |
2540 int ndims = nda.ndims (); | |
2541 | |
2542 dim_vector dims = nda.dims (); | |
2543 | |
5275 | 2544 Array<octave_idx_type> ra_idx (ndims, 0); |
2545 | |
2546 octave_idx_type m = 1; | |
4949 | 2547 |
2548 for (int i = 2; i < ndims; i++) | |
2549 m *= dims(i); | |
2550 | |
5275 | 2551 octave_idx_type nr = dims(0); |
2552 octave_idx_type nc = dims(1); | |
4949 | 2553 |
2554 int fw = 0; | |
2555 if (hex_format) | |
2556 fw = 2 * nda(0).byte_size (); | |
2557 else if (bit_format) | |
2558 fw = nda(0).nbits (); | |
2559 else | |
2560 { | |
2561 bool isneg = false; | |
2562 int digits = 0; | |
2563 | |
5275 | 2564 for (octave_idx_type i = 0; i < dims.numel (); i++) |
4949 | 2565 { |
2566 int new_digits = static_cast<int> | |
2567 (floor (log10 (double (abs (nda(i).value ()))) + 1.0)); | |
2568 | |
2569 if (new_digits > digits) | |
2570 digits = new_digits; | |
2571 | |
2572 if (! isneg) | |
2573 isneg = (abs (nda(i).value ()) != nda(i).value ()); | |
2574 } | |
2575 | |
2576 fw = digits + isneg; | |
2577 } | |
2578 | |
6788 | 2579 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 2580 octave_idx_type total_width = nc * column_width; |
4949 | 2581 int max_width = command_editor::terminal_cols () - extra_indent; |
5275 | 2582 octave_idx_type inc = nc; |
4949 | 2583 if (total_width > max_width && Vsplit_long_rows) |
2584 { | |
2585 inc = max_width / column_width; | |
2586 if (inc == 0) | |
2587 inc++; | |
2588 } | |
2589 | |
5275 | 2590 for (octave_idx_type i = 0; i < m; i++) |
4949 | 2591 { |
2592 if (m > 1) | |
2593 { | |
2594 std::string nm = "ans(:,:,"; | |
2595 | |
5765 | 2596 std::ostringstream buf; |
4949 | 2597 |
2598 for (int k = 2; k < ndims; k++) | |
2599 { | |
2600 buf << ra_idx(k) + 1; | |
2601 | |
2602 if (k < ndims - 1) | |
2603 buf << ","; | |
2604 else | |
2605 buf << ")"; | |
2606 } | |
2607 | |
5765 | 2608 nm += buf.str (); |
4949 | 2609 |
2610 os << nm << " =\n\n"; | |
2611 } | |
2612 | |
2613 Array<idx_vector> idx (ndims); | |
2614 | |
2615 idx(0) = idx_vector (':'); | |
2616 idx(1) = idx_vector (':'); | |
2617 | |
2618 for (int k = 2; k < ndims; k++) | |
2619 idx(k) = idx_vector (ra_idx(k) + 1); | |
2620 | |
2621 Array2<T> page (nda.index (idx), nr, nc); | |
2622 | |
2623 if (free_format) | |
2624 { | |
2625 if (pr_as_read_syntax) | |
2626 os << "[\n"; | |
2627 | |
5275 | 2628 for (octave_idx_type ii = 0; ii < nr; ii++) |
4949 | 2629 { |
5275 | 2630 for (octave_idx_type jj = 0; jj < nc; jj++) |
4949 | 2631 { |
2632 OCTAVE_QUIT; | |
2633 os << " "; | |
2634 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj)); | |
2635 } | |
2636 os << "\n"; | |
2637 } | |
2638 | |
2639 if (pr_as_read_syntax) | |
2640 os << "]"; | |
2641 } | |
2642 else | |
2643 { | |
5275 | 2644 octave_idx_type n_rows = page.rows (); |
2645 octave_idx_type n_cols = page.cols (); | |
2646 | |
2647 for (octave_idx_type col = 0; col < n_cols; col += inc) | |
4949 | 2648 { |
5275 | 2649 octave_idx_type lim = col + inc < n_cols ? col + inc : n_cols; |
4949 | 2650 |
2651 pr_col_num_header (os, total_width, max_width, lim, col, | |
2652 extra_indent); | |
2653 | |
5275 | 2654 for (octave_idx_type ii = 0; ii < n_rows; ii++) |
4949 | 2655 { |
2656 os << std::setw (extra_indent) << ""; | |
2657 | |
5275 | 2658 for (octave_idx_type jj = col; jj < lim; jj++) |
4949 | 2659 { |
2660 OCTAVE_QUIT; | |
2661 os << " "; | |
2662 pr_int (os, page(ii,jj), fw); | |
2663 } | |
2664 if ((ii < n_rows - 1) || (i < m -1)) | |
2665 os << "\n"; | |
2666 } | |
2667 } | |
2668 } | |
2669 | |
2670 if (i < m - 1) | |
2671 { | |
2672 os << "\n"; | |
2673 increment_index (ra_idx, dims, 2); | |
2674 } | |
4901 | 2675 } |
2676 } | |
2677 } | |
2678 | |
7215 | 2679 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
2680 OCTINTERP_API void \ | |
2681 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \ | |
2682 bool pr_as_read_syntax, int extra_indent) \ | |
2683 { \ | |
2684 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ | |
2685 } | |
2686 | |
2687 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
2688 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
2689 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
2690 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
2691 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
2692 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
2693 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
2694 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 2695 |
3933 | 2696 extern void |
2697 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) | |
3928 | 2698 { |
3933 | 2699 panic_impossible (); |
3928 | 2700 } |
2701 | |
6788 | 2702 DEFUN (rats, args, nargout, |
2703 "-*- texinfo -*-\n\ | |
2704 @deftypefn {Built-in Function} {} rats (@var{x}, @var{len})\n\ | |
2705 Convert @var{x} into a rational approximation represented as a string.\n\ | |
2706 You can convert the string back into a matrix as follows:\n\ | |
2707 \n\ | |
2708 @example\n\ | |
7097 | 2709 r = rats(hilb(4));\n\ |
2710 x = str2num(r)\n\ | |
6788 | 2711 @end example\n\ |
2712 \n\ | |
2713 The optional second argument defines the maximum length of the string\n\ | |
2714 representing the elements of @var{x}. By default @var{len} is 9.\n\ | |
2715 @seealso{format, rat}\n\ | |
2716 @end deftypefn") | |
2717 { | |
2718 octave_value retval; | |
6803 | 2719 |
6788 | 2720 int nargin = args.length (); |
2721 | |
6803 | 2722 unwind_protect::begin_frame ("Frats"); |
2723 | |
2724 unwind_protect_int (rat_string_len); | |
2725 | |
6788 | 2726 rat_string_len = 9; |
6803 | 2727 |
6788 | 2728 if (nargin == 2) |
2729 rat_string_len = args(1).nint_value (); | |
2730 | |
6803 | 2731 if (! error_state) |
6788 | 2732 { |
2733 if (nargin < 3 && nargout < 2) | |
2734 { | |
6803 | 2735 octave_value arg = args(0); |
2736 | |
2737 if (arg.is_numeric_type ()) | |
2738 { | |
2739 unwind_protect_bool (rat_format); | |
2740 | |
2741 rat_format = true; | |
2742 | |
2743 std::ostringstream buf; | |
2744 args(0).print (buf); | |
2745 std::string s = buf.str (); | |
2746 | |
2747 std::list<std::string> lst; | |
2748 | |
2749 size_t n = 0; | |
2750 size_t s_len = s.length (); | |
2751 | |
2752 while (n < s_len) | |
2753 { | |
2754 size_t m = s.find ('\n', n); | |
2755 | |
2756 if (m == NPOS) | |
2757 { | |
2758 lst.push_back (s.substr (n)); | |
2759 break; | |
2760 } | |
2761 else | |
2762 { | |
2763 lst.push_back (s.substr (n, m - n)); | |
2764 n = m + 1; | |
2765 } | |
2766 } | |
2767 | |
2768 retval = string_vector (lst); | |
2769 } | |
2770 else | |
2771 error ("rats: expecting numeric input"); | |
6788 | 2772 } |
2773 else | |
2774 print_usage (); | |
2775 } | |
2776 | |
6803 | 2777 unwind_protect::run_frame ("Frats"); |
2778 | |
6788 | 2779 return retval; |
2780 } | |
2781 | |
3685 | 2782 DEFUN (disp, args, nargout, |
2783 "-*- texinfo -*-\n\ | |
2784 @deftypefn {Built-in Function} {} disp (@var{x})\n\ | |
2785 Display the value of @var{x}. For example,\n\ | |
2786 \n\ | |
2787 @example\n\ | |
2788 disp (\"The value of pi is:\"), disp (pi)\n\ | |
2789 \n\ | |
2790 @print{} the value of pi is:\n\ | |
2791 @print{} 3.1416\n\ | |
2792 @end example\n\ | |
2793 \n\ | |
2794 @noindent\n\ | |
2795 Note that the output from @code{disp} always ends with a newline.\n\ | |
2796 \n\ | |
2797 If an output value is requested, @code{disp} prints nothing and\n\ | |
2798 returns the formatted output in a string.\n\ | |
5642 | 2799 @seealso{fdisp}\n\ |
2800 @end deftypefn") | |
3685 | 2801 { |
2802 octave_value retval; | |
2803 | |
2804 int nargin = args.length (); | |
2805 | |
2806 if (nargin == 1 && nargout < 2) | |
2807 { | |
2808 if (nargout == 0) | |
2809 args(0).print (octave_stdout); | |
2810 else | |
2811 { | |
11756
d68fc0ca4ece
disp: produce sq-string unless arg is a dq-string
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
2812 octave_value arg = args(0); |
5765 | 2813 std::ostringstream buf; |
11756
d68fc0ca4ece
disp: produce sq-string unless arg is a dq-string
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
2814 arg.print (buf); |
d68fc0ca4ece
disp: produce sq-string unless arg is a dq-string
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
2815 retval = octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''); |
3685 | 2816 } |
2817 } | |
2818 else | |
5823 | 2819 print_usage (); |
3685 | 2820 |
2821 return retval; | |
2822 } | |
2823 | |
2824 DEFUN (fdisp, args, , | |
2825 "-*- texinfo -*-\n\ | |
2826 @deftypefn {Built-in Function} {} fdisp (@var{fid}, @var{x})\n\ | |
2827 Display the value of @var{x} on the stream @var{fid}. For example,\n\ | |
2828 \n\ | |
2829 @example\n\ | |
4869 | 2830 fdisp (stdout, \"The value of pi is:\"), fdisp (stdout, pi)\n\ |
3685 | 2831 \n\ |
2832 @print{} the value of pi is:\n\ | |
2833 @print{} 3.1416\n\ | |
2834 @end example\n\ | |
2835 \n\ | |
2836 @noindent\n\ | |
4869 | 2837 Note that the output from @code{fdisp} always ends with a newline.\n\ |
5642 | 2838 @seealso{disp}\n\ |
2839 @end deftypefn") | |
3685 | 2840 { |
2841 octave_value retval; | |
2842 | |
2843 int nargin = args.length (); | |
2844 | |
2845 if (nargin == 2) | |
2846 { | |
2847 int fid = octave_stream_list::get_file_number (args (0)); | |
2848 | |
2849 octave_stream os = octave_stream_list::lookup (fid, "fdisp"); | |
2850 | |
2851 if (! error_state) | |
2852 { | |
3769 | 2853 std::ostream *osp = os.output_stream (); |
3685 | 2854 |
2855 if (osp) | |
2856 args(1).print (*osp); | |
2857 else | |
2858 error ("fdisp: stream not open for writing"); | |
2859 } | |
2860 } | |
2861 else | |
5823 | 2862 print_usage (); |
3685 | 2863 |
2864 return retval; | |
2865 } | |
2866 | |
1 | 2867 static void |
2868 init_format_state (void) | |
2869 { | |
2387 | 2870 free_format = false; |
2871 plus_format = false; | |
6788 | 2872 rat_format = false; |
2387 | 2873 bank_format = false; |
3608 | 2874 hex_format = 0; |
1309 | 2875 bit_format = 0; |
4833 | 2876 compact_format = false; |
2387 | 2877 print_e = false; |
2878 print_big_e = false; | |
4509 | 2879 print_g = false; |
1 | 2880 } |
2881 | |
2882 static void | |
2883 set_output_prec_and_fw (int prec, int fw) | |
2884 { | |
5794 | 2885 Voutput_precision = prec; |
2886 Voutput_max_field_width = fw; | |
1 | 2887 } |
2888 | |
1755 | 2889 static void |
2890 set_format_style (int argc, const string_vector& argv) | |
1 | 2891 { |
1755 | 2892 int idx = 1; |
2893 | |
1899 | 2894 if (--argc > 0) |
1 | 2895 { |
3523 | 2896 std::string arg = argv[idx++]; |
2584 | 2897 |
1755 | 2898 if (arg == "short") |
1 | 2899 { |
1755 | 2900 if (--argc > 0) |
1 | 2901 { |
1755 | 2902 arg = argv[idx++]; |
2903 | |
2904 if (arg == "e") | |
1 | 2905 { |
1755 | 2906 init_format_state (); |
2387 | 2907 print_e = true; |
1755 | 2908 } |
2909 else if (arg == "E") | |
2910 { | |
2911 init_format_state (); | |
2387 | 2912 print_e = true; |
2913 print_big_e = true; | |
1 | 2914 } |
4509 | 2915 else if (arg == "g") |
2916 { | |
2917 init_format_state (); | |
2918 print_g = true; | |
2919 } | |
2920 else if (arg == "G") | |
2921 { | |
2922 init_format_state (); | |
2923 print_g = true; | |
2924 print_big_e = true; | |
2925 } | |
1 | 2926 else |
2927 { | |
1755 | 2928 error ("format: unrecognized option `short %s'", |
2929 arg.c_str ()); | |
2930 return; | |
2931 } | |
2932 } | |
2933 else | |
2934 init_format_state (); | |
2935 | |
4509 | 2936 set_output_prec_and_fw (5, 10); |
1755 | 2937 } |
2938 else if (arg == "long") | |
2939 { | |
2940 if (--argc > 0) | |
2941 { | |
2942 arg = argv[idx++]; | |
2943 | |
2944 if (arg == "e") | |
2945 { | |
2946 init_format_state (); | |
2387 | 2947 print_e = true; |
1755 | 2948 } |
2949 else if (arg == "E") | |
2950 { | |
2951 init_format_state (); | |
2387 | 2952 print_e = true; |
2953 print_big_e = true; | |
1 | 2954 } |
4509 | 2955 else if (arg == "g") |
2956 { | |
2957 init_format_state (); | |
2958 print_g = true; | |
2959 } | |
2960 else if (arg == "G") | |
2961 { | |
2962 init_format_state (); | |
2963 print_g = true; | |
2964 print_big_e = true; | |
2965 } | |
1 | 2966 else |
1755 | 2967 { |
2968 error ("format: unrecognized option `long %s'", | |
2969 arg.c_str ()); | |
2970 return; | |
2971 } | |
1186 | 2972 } |
1 | 2973 else |
1755 | 2974 init_format_state (); |
2975 | |
4509 | 2976 set_output_prec_and_fw (15, 20); |
1755 | 2977 } |
2978 else if (arg == "hex") | |
2979 { | |
2980 init_format_state (); | |
3608 | 2981 hex_format = 1; |
1755 | 2982 } |
2983 else if (arg == "native-hex") | |
2984 { | |
2985 init_format_state (); | |
2986 hex_format = 2; | |
2987 } | |
2988 else if (arg == "bit") | |
2989 { | |
2990 init_format_state (); | |
2991 bit_format = 1; | |
2992 } | |
2993 else if (arg == "native-bit") | |
2994 { | |
2995 init_format_state (); | |
2996 bit_format = 2; | |
2997 } | |
2998 else if (arg == "+" || arg == "plus") | |
2999 { | |
4632 | 3000 if (--argc > 0) |
3001 { | |
3002 arg = argv[idx++]; | |
3003 | |
3004 if (arg.length () == 3) | |
3005 plus_format_chars = arg; | |
3006 else | |
3007 { | |
3008 error ("format: invalid option for plus format"); | |
3009 return; | |
3010 } | |
3011 } | |
3012 else | |
3013 plus_format_chars = "+ "; | |
3014 | |
1755 | 3015 init_format_state (); |
2387 | 3016 plus_format = true; |
1755 | 3017 } |
6788 | 3018 else if (arg == "rat") |
3019 { | |
3020 init_format_state (); | |
3021 rat_format = true; | |
3022 } | |
1755 | 3023 else if (arg == "bank") |
3024 { | |
3025 init_format_state (); | |
2387 | 3026 bank_format = true; |
1755 | 3027 } |
3028 else if (arg == "free") | |
3029 { | |
3030 init_format_state (); | |
2387 | 3031 free_format = true; |
1755 | 3032 } |
3033 else if (arg == "none") | |
3034 { | |
3035 init_format_state (); | |
2387 | 3036 free_format = true; |
1755 | 3037 } |
3038 else if (arg == "compact") | |
3039 { | |
2387 | 3040 compact_format = true; |
1755 | 3041 } |
3042 else if (arg == "loose") | |
3043 { | |
2387 | 3044 compact_format = false; |
1 | 3045 } |
3046 else | |
1755 | 3047 error ("format: unrecognized format state `%s'", arg.c_str ()); |
1 | 3048 } |
3049 else | |
3050 { | |
3051 init_format_state (); | |
3052 set_output_prec_and_fw (5, 10); | |
3053 } | |
3054 } | |
3055 | |
4208 | 3056 DEFCMD (format, args, , |
3372 | 3057 "-*- texinfo -*-\n\ |
3058 @deffn {Command} format options\n\ | |
3059 Control the format of the output produced by @code{disp} and Octave's\n\ | |
3060 normal echoing mechanism. Valid options are listed in the following\n\ | |
3061 table.\n\ | |
3062 \n\ | |
3063 @table @code\n\ | |
3064 @item short\n\ | |
3065 Octave will try to print numbers with at\n\ | |
4509 | 3066 least 5 significant figures within a field that is a maximum of 10\n\ |
3067 characters wide (not counting additional spacing that is added between\n\ | |
3068 columns of a matrix).\n\ | |
3372 | 3069 \n\ |
3070 If Octave is unable to format a matrix so that columns line up on the\n\ | |
3071 decimal point and all the numbers fit within the maximum field width,\n\ | |
3072 it switches to an @samp{e} format.\n\ | |
3073 \n\ | |
3074 @item long\n\ | |
3075 Octave will try to print numbers with at least 15 significant figures\n\ | |
4509 | 3076 within a field that is a maximum of 20 characters wide (not counting\n\ |
3077 additional spacing that is added between columns of a matrix).\n\ | |
3372 | 3078 \n\ |
3079 As will the @samp{short} format, Octave will switch to an @samp{e}\n\ | |
3080 format if it is unable to format a matrix so that columns line up on the\n\ | |
3081 decimal point and all the numbers fit within the maximum field width.\n\ | |
3082 \n\ | |
3083 @item long e\n\ | |
3084 @itemx short e\n\ | |
3085 The same as @samp{format long} or @samp{format short} but always display\n\ | |
3086 output with an @samp{e} format. For example, with the @samp{short e}\n\ | |
4509 | 3087 format, @code{pi} is displayed as @code{3.14e+00}.\n\ |
3372 | 3088 \n\ |
3089 @item long E\n\ | |
3090 @itemx short E\n\ | |
3091 The same as @samp{format long e} or @samp{format short e} but always\n\ | |
3092 display output with an uppercase @samp{E} format. For example, with\n\ | |
4509 | 3093 the @samp{long E} format, @code{pi} is displayed as\n\ |
3372 | 3094 @code{3.14159265358979E+00}.\n\ |
4509 | 3095 @item long g\n\ |
3096 @itemx short g\n\ | |
7001 | 3097 Choose between normal @samp{long} (or @samp{short}) and\n\ |
4509 | 3098 @samp{long e} (or @samp{short e}) formats based on the magnitude\n\ |
3099 of the number. For example, with the @samp{short g} format,\n\ | |
3100 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ | |
3101 \n\ | |
3102 @example\n\ | |
3103 @group\n\ | |
3104 ans =\n\ | |
3105 \n\ | |
3106 9.8696\n\ | |
3107 97.409\n\ | |
3108 9488.5\n\ | |
3109 9.0032e+07\n\ | |
3110 8.1058e+15\n\ | |
3111 @end group\n\ | |
3112 @end example\n\ | |
3113 \n\ | |
3114 @item long G\n\ | |
3115 @itemx short G\n\ | |
3116 The same as @samp{format long g} or @samp{format short g} but use an\n\ | |
3117 uppercase @samp{E} format. For example, with the @samp{short G} format,\n\ | |
3118 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as\n\ | |
3119 \n\ | |
3120 @example\n\ | |
3121 @group\n\ | |
3122 ans =\n\ | |
3123 \n\ | |
3124 9.8696\n\ | |
3125 97.409\n\ | |
3126 9488.5\n\ | |
3127 9.0032E+07\n\ | |
3128 8.1058E+15\n\ | |
3129 @end group\n\ | |
3130 @end example\n\ | |
3372 | 3131 \n\ |
3132 @item free\n\ | |
3133 @itemx none\n\ | |
3134 Print output in free format, without trying to line up columns of\n\ | |
3135 matrices on the decimal point. This also causes complex numbers to be\n\ | |
3136 formatted like this @samp{(0.604194, 0.607088)} instead of like this\n\ | |
3137 @samp{0.60419 + 0.60709i}.\n\ | |
529 | 3138 \n\ |
3372 | 3139 @item bank\n\ |
3140 Print in a fixed format with two places to the right of the decimal\n\ | |
3141 point.\n\ | |
3142 \n\ | |
3143 @item +\n\ | |
4632 | 3144 @itemx + @var{chars}\n\ |
3145 @itemx plus\n\ | |
3146 @itemx plus @var{chars}\n\ | |
3372 | 3147 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ |
3148 matrix elements. This format can be very useful for examining the\n\ | |
3149 structure of a large matrix.\n\ | |
3150 \n\ | |
4632 | 3151 The optional argument @var{chars} specifies a list of 3 characters to use\n\ |
3152 for printing values greater than zero, less than zero and equal to zero.\n\ | |
3153 For example, with the @samp{+ \"+-.\"} format, @code{[1, 0, -1; -1, 0, 1]}\n\ | |
3154 is displayed as\n\ | |
3155 \n\ | |
3156 @example\n\ | |
3157 @group\n\ | |
3158 ans =\n\ | |
3159 \n\ | |
3160 +.-\n\ | |
3161 -.+\n\ | |
3162 @end group\n\ | |
3163 @end example\n\ | |
3164 \n\ | |
4833 | 3165 @itemx native-hex\n\ |
3372 | 3166 Print the hexadecimal representation numbers as they are stored in\n\ |
3167 memory. For example, on a workstation which stores 8 byte real values\n\ | |
3168 in IEEE format with the least significant byte first, the value of\n\ | |
3169 @code{pi} when printed in @code{hex} format is @code{400921fb54442d18}.\n\ | |
3170 This format only works for numeric values.\n\ | |
3171 \n\ | |
4833 | 3172 @item hex\n\ |
3173 The same as @code{native-hex}, but always print the most significant\n\ | |
3174 byte first.\n\ | |
3175 @item native-bit\n\ | |
3372 | 3176 Print the bit representation of numbers as stored in memory.\n\ |
3177 For example, the value of @code{pi} is\n\ | |
3178 \n\ | |
3179 @example\n\ | |
3180 @group\n\ | |
3181 01000000000010010010000111111011\n\ | |
3182 01010100010001000010110100011000\n\ | |
3183 @end group\n\ | |
3184 @end example\n\ | |
3185 \n\ | |
3186 (shown here in two 32 bit sections for typesetting purposes) when\n\ | |
3187 printed in bit format on a workstation which stores 8 byte real values\n\ | |
3188 in IEEE format with the least significant byte first. This format only\n\ | |
3189 works for numeric types.\n\ | |
4833 | 3190 @item bit\n\ |
3191 The same as @code{native-bit}, but always print the most significant\n\ | |
3192 bits first.\n\ | |
3193 @item compact\n\ | |
3194 Remove extra blank space around column number labels.\n\ | |
3195 @item loose\n\ | |
3196 Insert blank lines above and below column number labels (this is the\n\ | |
3197 default).\n\ | |
6788 | 3198 @item rat\n\ |
3199 Print a rational approximation. That is the values are approximated\n\ | |
3200 by one small integer divided by another.\n\ | |
3372 | 3201 @end table\n\ |
3202 \n\ | |
3203 By default, Octave will try to print numbers with at least 5 significant\n\ | |
3204 figures within a field that is a maximum of 10 characters wide.\n\ | |
3205 \n\ | |
3206 If Octave is unable to format a matrix so that columns line up on the\n\ | |
3207 decimal point and all the numbers fit within the maximum field width,\n\ | |
3208 it switches to an @samp{e} format.\n\ | |
3209 \n\ | |
3210 If @code{format} is invoked without any options, the default format\n\ | |
3211 state is restored.\n\ | |
3212 @end deffn") | |
529 | 3213 { |
2086 | 3214 octave_value_list retval; |
529 | 3215 |
1755 | 3216 int argc = args.length () + 1; |
3217 | |
1968 | 3218 string_vector argv = args.make_argv ("format"); |
1755 | 3219 |
3220 if (error_state) | |
3221 return retval; | |
529 | 3222 |
3223 set_format_style (argc, argv); | |
3224 | |
3225 return retval; | |
3226 } | |
3227 | |
5794 | 3228 DEFUN (fixed_point_format, args, nargout, |
3229 "-*- texinfo -*-\n\ | |
3230 @deftypefn {Built-in Function} {@var{val} =} fixed_point_format ()\n\ | |
3231 @deftypefnx {Built-in Function} {@var{old_val} =} fixed_point_format (@var{new_val})\n\ | |
3232 Query or set the internal variable that controls whether Octave will\n\ | |
3233 use a scaled format to print matrix values such that the largest\n\ | |
3234 element may be written with a single leading digit with the scaling\n\ | |
3235 factor is printed on the first line of output. For example,\n\ | |
3321 | 3236 \n\ |
3237 @example\n\ | |
3238 @group\n\ | |
3239 octave:1> logspace (1, 7, 5)'\n\ | |
3240 ans =\n\ | |
3241 \n\ | |
3242 1.0e+07 *\n\ | |
3243 \n\ | |
3244 0.00000\n\ | |
3245 0.00003\n\ | |
3246 0.00100\n\ | |
3247 0.03162\n\ | |
3248 1.00000\n\ | |
3249 @end group\n\ | |
3250 @end example\n\ | |
3251 \n\ | |
3252 @noindent\n\ | |
3253 Notice that first value appears to be zero when it is actually 1. For\n\ | |
3254 this reason, you should be careful when setting\n\ | |
3255 @code{fixed_point_format} to a nonzero value.\n\ | |
5794 | 3256 @end deftypefn") |
3257 { | |
3258 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
3259 } | |
3260 | |
3261 DEFUN (print_empty_dimensions, args, nargout, | |
3262 "-*- texinfo -*-\n\ | |
3263 @deftypefn {Built-in Function} {@var{val} =} print_empty_dimensions ()\n\ | |
3264 @deftypefnx {Built-in Function} {@var{old_val} =} print_empty_dimensions (@var{new_val})\n\ | |
7001 | 3265 Query or set the internal variable that controls whether the\n\ |
3321 | 3266 dimensions of empty matrices are printed along with the empty matrix\n\ |
3267 symbol, @samp{[]}. For example, the expression\n\ | |
3268 \n\ | |
3269 @example\n\ | |
3270 zeros (3, 0)\n\ | |
3271 @end example\n\ | |
3272 \n\ | |
3273 @noindent\n\ | |
3274 will print\n\ | |
3275 \n\ | |
3276 @example\n\ | |
3277 ans = [](3x0)\n\ | |
3278 @end example\n\ | |
5794 | 3279 @end deftypefn") |
3280 { | |
3281 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
3282 } | |
3283 | |
3284 DEFUN (split_long_rows, args, nargout, | |
3285 "-*- texinfo -*-\n\ | |
3286 @deftypefn {Built-in Function} {@var{val} =} split_long_rows ()\n\ | |
3287 @deftypefnx {Built-in Function} {@var{old_val} =} split_long_rows (@var{new_val})\n\ | |
3288 Query or set the internal variable that controls whether rows of a matrix\n\ | |
3289 may be split when displayed to a terminal window. If the rows are split,\n\ | |
3290 Octave will display the matrix in a series of smaller pieces, each of\n\ | |
3291 which can fit within the limits of your terminal width and each set of\n\ | |
3292 rows is labeled so that you can easily see which columns are currently\n\ | |
3293 being displayed. For example:\n\ | |
3321 | 3294 \n\ |
6670 | 3295 @example\n\ |
3321 | 3296 @group\n\ |
3297 octave:13> rand (2,10)\n\ | |
3298 ans =\n\ | |
3299 \n\ | |
3300 Columns 1 through 6:\n\ | |
3301 \n\ | |
3302 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ | |
3303 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ | |
3304 \n\ | |
3305 Columns 7 through 10:\n\ | |
3306 \n\ | |
3307 0.90174 0.11854 0.72313 0.73326\n\ | |
3308 0.44672 0.94303 0.56564 0.82150\n\ | |
3309 @end group\n\ | |
6670 | 3310 @end example\n\ |
5794 | 3311 @end deftypefn") |
3312 { | |
3313 return SET_INTERNAL_VARIABLE (split_long_rows); | |
3314 } | |
3315 | |
3316 DEFUN (output_max_field_width, args, nargout, | |
3317 "-*- texinfo -*-\n\ | |
3318 @deftypefn {Built-in Function} {@var{val} =} output_max_field_width ()\n\ | |
3319 @deftypefnx {Built-in Function} {@var{old_val} =} output_max_field_width (@var{new_val})\n\ | |
3320 Query or set the internal variable that specifies the maximum width\n\ | |
3321 of a numeric output field.\n\ | |
3322 @seealso{format, output_precision}\n\ | |
3323 @end deftypefn") | |
3324 { | |
3325 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, 0, INT_MAX); | |
3326 } | |
3327 | |
3328 DEFUN (output_precision, args, nargout, | |
3329 "-*- texinfo -*-\n\ | |
3330 @deftypefn {Built-in Function} {@var{val} =} output_precision ()\n\ | |
3331 @deftypefnx {Built-in Function} {@var{old_val} =} output_precision (@var{new_val})\n\ | |
3332 Query or set the internal variable that specifies the minimum number of\n\ | |
3333 significant figures to display for numeric output.\n\ | |
3334 @seealso{format, output_max_field_width}\n\ | |
3335 @end deftypefn") | |
3336 { | |
3337 return SET_INTERNAL_VARIABLE_WITH_LIMITS (output_precision, -1, INT_MAX); | |
3338 } | |
3339 | |
3340 DEFUN (struct_levels_to_print, args, nargout, | |
3341 "-*- texinfo -*-\n\ | |
3342 @deftypefn {Built-in Function} {@var{val} =} struct_levels_to_print ()\n\ | |
3343 @deftypefnx {Built-in Function} {@var{old_val} =} struct_levels_to_print (@var{new_val})\n\ | |
3344 Query or set the internal variable that specifies the number of\n\ | |
3345 structure levels to display.\n\ | |
3346 @end deftypefn") | |
3347 { | |
3348 return SET_INTERNAL_VARIABLE_WITH_LIMITS (struct_levels_to_print, | |
3349 -1, INT_MAX); | |
2165 | 3350 } |
3351 | |
1 | 3352 /* |
3353 ;;; Local Variables: *** | |
3354 ;;; mode: C++ *** | |
3355 ;;; End: *** | |
3356 */ |