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