1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
240
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
1
|
25 #endif |
|
26 |
1346
|
27 #include <cfloat> |
3124
|
28 #include <cmath> |
2825
|
29 #include <cstdio> |
1346
|
30 #include <cstring> |
1343
|
31 |
3503
|
32 #include <iomanip> |
|
33 #include <iostream> |
|
34 #include <strstream> |
1728
|
35 #include <string> |
|
36 |
453
|
37 #include "CMatrix.h" |
1
|
38 #include "Range.h" |
2926
|
39 #include "cmd-edit.h" |
1352
|
40 #include "dMatrix.h" |
2891
|
41 #include "lo-mappers.h" |
2317
|
42 #include "mach-info.h" |
1651
|
43 #include "oct-cmplx.h" |
1755
|
44 #include "str-vec.h" |
1
|
45 |
1352
|
46 #include "defun.h" |
|
47 #include "error.h" |
2165
|
48 #include "gripes.h" |
1755
|
49 #include "oct-obj.h" |
1352
|
50 #include "pager.h" |
|
51 #include "pr-output.h" |
1282
|
52 #include "sysdep.h" |
1
|
53 #include "utils.h" |
1352
|
54 #include "variables.h" |
1
|
55 |
3105
|
56 // TRUE means use a scaled fixed point format for `format long' and |
|
57 // `format short'. |
|
58 static bool Vfixed_point_format; |
|
59 |
2165
|
60 // The maximum field width for a number printed by the default output |
|
61 // routines. |
|
62 static int Voutput_max_field_width; |
|
63 |
|
64 // The precision of the numbers printed by the default output |
|
65 // routines. |
|
66 static int Voutput_precision; |
|
67 |
|
68 // TRUE means that the dimensions of empty matrices should be printed |
|
69 // like this: x = [](2x0). |
|
70 static bool Vprint_empty_dimensions; |
|
71 |
|
72 // TRUE means that the rows of big matrices should be split into |
|
73 // smaller slices that fit on the screen. |
|
74 static bool Vsplit_long_rows; |
|
75 |
3523
|
76 // Current format std::string for real numbers and the real part of complex |
1
|
77 // numbers. |
529
|
78 static char *curr_real_fmt = 0; |
1
|
79 |
3523
|
80 // Current format std::string for the imaginary part of complex numbers. |
529
|
81 static char *curr_imag_fmt = 0; |
1
|
82 |
3018
|
83 // TRUE means don't do any fancy formatting. |
2387
|
84 static bool free_format = false; |
1
|
85 |
3018
|
86 // TRUE means print plus sign for nonzero, blank for zero. |
2387
|
87 static bool plus_format = false; |
1
|
88 |
3018
|
89 // TRUE means always print like dollars and cents. |
2387
|
90 static bool bank_format = false; |
1282
|
91 |
3018
|
92 // TRUE means print data in hexadecimal format. |
2387
|
93 static bool hex_format = false; |
1282
|
94 |
3018
|
95 // TRUE means print data in binary-bit-pattern format. |
1309
|
96 static int bit_format = 0; |
|
97 |
3018
|
98 // TRUE means don't put newlines around the column number headers. |
2387
|
99 static bool compact_format = false; |
1186
|
100 |
3018
|
101 // TRUE means use an e format. |
2387
|
102 static bool print_e = false; |
1
|
103 |
3018
|
104 // TRUE means print E instead of e for exponent field. |
2387
|
105 static bool print_big_e = false; |
1
|
106 |
1309
|
107 // XXX FIXME XXX -- these should probably be somewhere else. |
|
108 |
1
|
109 static double |
164
|
110 pr_max_internal (const Matrix& m) |
1
|
111 { |
|
112 int nr = m.rows (); |
|
113 int nc = m.columns (); |
|
114 |
3130
|
115 double result = -DBL_MAX; |
1
|
116 |
|
117 for (int j = 0; j < nc; j++) |
|
118 for (int i = 0; i < nr; i++) |
|
119 { |
2305
|
120 double val = m (i, j); |
1
|
121 if (xisinf (val) || xisnan (val)) |
|
122 continue; |
|
123 |
|
124 if (val > result) |
|
125 result = val; |
|
126 } |
|
127 return result; |
|
128 } |
|
129 |
|
130 static double |
164
|
131 pr_min_internal (const Matrix& m) |
1
|
132 { |
|
133 int nr = m.rows (); |
|
134 int nc = m.columns (); |
|
135 |
|
136 double result = DBL_MAX; |
|
137 |
|
138 for (int j = 0; j < nc; j++) |
|
139 for (int i = 0; i < nr; i++) |
|
140 { |
2305
|
141 double val = m (i, j); |
1
|
142 if (xisinf (val) || xisnan (val)) |
|
143 continue; |
|
144 |
|
145 if (val < result) |
|
146 result = val; |
|
147 } |
|
148 return result; |
|
149 } |
|
150 |
1658
|
151 // XXX FIXME XXX -- it would be nice to share more code among these |
|
152 // functions,.. |
|
153 |
1
|
154 static void |
2387
|
155 set_real_format (bool sign, int digits, bool inf_or_nan, bool nan_or_int, |
1658
|
156 int &fw) |
1
|
157 { |
278
|
158 static char fmt_buf[128]; |
1
|
159 |
2165
|
160 int prec = Voutput_precision; |
1
|
161 |
|
162 int ld, rd; |
|
163 |
|
164 if (bank_format) |
|
165 { |
|
166 fw = digits < 0 ? 4 : digits + 3; |
|
167 if (inf_or_nan && fw < 3) |
|
168 fw = 3; |
|
169 fw += sign; |
|
170 rd = 2; |
|
171 } |
1282
|
172 else if (hex_format) |
|
173 { |
|
174 fw = 2 * sizeof (double); |
|
175 rd = 0; |
|
176 } |
1309
|
177 else if (bit_format) |
|
178 { |
|
179 fw = 8 * sizeof (double); |
|
180 rd = 0; |
|
181 } |
1658
|
182 else if (nan_or_int) |
1
|
183 { |
|
184 fw = digits; |
|
185 if (inf_or_nan && fw < 3) |
|
186 fw = 3; |
|
187 fw += sign; |
|
188 rd = 0; |
|
189 } |
|
190 else |
|
191 { |
|
192 if (digits > 0) |
|
193 { |
|
194 ld = digits; |
1658
|
195 rd = prec > digits ? prec - digits : prec; |
1
|
196 digits++; |
|
197 } |
|
198 else |
|
199 { |
|
200 ld = 1; |
1658
|
201 rd = prec > digits ? prec - digits : prec; |
1
|
202 digits = -digits + 1; |
|
203 } |
|
204 |
|
205 fw = ld + 1 + rd; |
|
206 if (inf_or_nan && fw < 3) |
|
207 fw = 3; |
|
208 fw += sign; |
|
209 } |
|
210 |
1309
|
211 if (! (bank_format || hex_format || bit_format) |
2165
|
212 && (fw > Voutput_max_field_width || print_e)) |
1
|
213 { |
|
214 int exp_field = 4; |
|
215 if (digits > 100) |
|
216 exp_field++; |
|
217 |
|
218 fw = 2 + prec + exp_field; |
|
219 if (inf_or_nan && fw < 3) |
|
220 fw = 3; |
|
221 fw += sign; |
|
222 |
|
223 if (print_big_e) |
|
224 sprintf (fmt_buf, "%%%d.%dE", fw, prec - 1); |
|
225 else |
|
226 sprintf (fmt_buf, "%%%d.%de", fw, prec - 1); |
|
227 } |
|
228 else |
|
229 { |
|
230 sprintf (fmt_buf, "%%%d.%df", fw, rd); |
|
231 } |
|
232 |
|
233 curr_real_fmt = &fmt_buf[0]; |
|
234 } |
|
235 |
1658
|
236 static void |
|
237 set_format (double d, int& fw) |
|
238 { |
|
239 curr_real_fmt = 0; |
|
240 curr_imag_fmt = 0; |
|
241 |
|
242 if (free_format) |
|
243 return; |
|
244 |
2387
|
245 bool sign = (d < 0.0); |
1658
|
246 |
2387
|
247 bool inf_or_nan = (xisinf (d) || xisnan (d)); |
1658
|
248 |
2387
|
249 bool nan_or_int = (xisnan (d) || D_NINT (d) == d); |
1658
|
250 |
|
251 double d_abs = d < 0.0 ? -d : d; |
|
252 |
2800
|
253 int digits = (inf_or_nan || d_abs == 0.0) |
|
254 ? 0 : static_cast<int> (floor (log10 (d_abs) + 1.0)); |
1658
|
255 |
|
256 set_real_format (sign, digits, inf_or_nan, nan_or_int, fw); |
|
257 } |
|
258 |
1
|
259 static inline void |
|
260 set_format (double d) |
|
261 { |
|
262 int fw; |
|
263 set_format (d, fw); |
|
264 } |
|
265 |
|
266 static void |
2387
|
267 set_real_matrix_format (bool sign, int x_max, int x_min, |
|
268 bool inf_or_nan, int int_or_inf_or_nan, int& fw) |
1
|
269 { |
278
|
270 static char fmt_buf[128]; |
1
|
271 |
2165
|
272 int prec = Voutput_precision; |
1
|
273 |
|
274 int ld, rd; |
|
275 |
|
276 if (bank_format) |
|
277 { |
|
278 int digits = x_max > x_min ? x_max : x_min; |
|
279 fw = digits <= 0 ? 4 : digits + 3; |
|
280 if (inf_or_nan && fw < 3) |
|
281 fw = 3; |
|
282 fw += sign; |
|
283 rd = 2; |
|
284 } |
1282
|
285 else if (hex_format) |
|
286 { |
|
287 fw = 2 * sizeof (double); |
|
288 rd = 0; |
|
289 } |
1309
|
290 else if (bit_format) |
|
291 { |
|
292 fw = 8 * sizeof (double); |
|
293 rd = 0; |
|
294 } |
3268
|
295 else if (Vfixed_point_format) |
|
296 { |
|
297 rd = prec; |
|
298 fw = rd + 2; |
|
299 if (inf_or_nan && fw < 3) |
|
300 fw = 3; |
|
301 fw += sign; |
|
302 } |
1715
|
303 else if (int_or_inf_or_nan) |
1
|
304 { |
|
305 int digits = x_max > x_min ? x_max : x_min; |
|
306 fw = digits <= 0 ? 1 : digits; |
|
307 if (inf_or_nan && fw < 3) |
|
308 fw = 3; |
|
309 fw += sign; |
|
310 rd = 0; |
|
311 } |
|
312 else |
|
313 { |
|
314 int ld_max, rd_max; |
|
315 if (x_max > 0) |
|
316 { |
|
317 ld_max = x_max; |
1658
|
318 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
319 x_max++; |
|
320 } |
|
321 else |
|
322 { |
|
323 ld_max = 1; |
1658
|
324 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
325 x_max = -x_max + 1; |
|
326 } |
|
327 |
|
328 int ld_min, rd_min; |
|
329 if (x_min > 0) |
|
330 { |
|
331 ld_min = x_min; |
1658
|
332 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
333 x_min++; |
|
334 } |
|
335 else |
|
336 { |
|
337 ld_min = 1; |
1658
|
338 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
339 x_min = -x_min + 1; |
|
340 } |
|
341 |
|
342 ld = ld_max > ld_min ? ld_max : ld_min; |
|
343 rd = rd_max > rd_min ? rd_max : rd_min; |
|
344 |
|
345 fw = ld + 1 + rd; |
|
346 if (inf_or_nan && fw < 3) |
|
347 fw = 3; |
|
348 fw += sign; |
|
349 } |
|
350 |
1658
|
351 if (! (bank_format || hex_format || bit_format) |
3105
|
352 && (print_e |
|
353 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1
|
354 { |
|
355 int exp_field = 4; |
|
356 if (x_max > 100 || x_min > 100) |
|
357 exp_field++; |
|
358 |
|
359 fw = 2 + prec + exp_field; |
|
360 if (inf_or_nan && fw < 3) |
|
361 fw = 3; |
|
362 fw += sign; |
|
363 |
|
364 if (print_big_e) |
|
365 sprintf (fmt_buf, "%%%d.%dE", fw, prec - 1); |
|
366 else |
|
367 sprintf (fmt_buf, "%%%d.%de", fw, prec - 1); |
|
368 } |
|
369 else |
|
370 { |
|
371 sprintf (fmt_buf, "%%%d.%df", fw, rd); |
|
372 } |
|
373 |
|
374 curr_real_fmt = &fmt_buf[0]; |
|
375 } |
|
376 |
1658
|
377 static void |
3105
|
378 set_format (const Matrix& m, int& fw, double& scale) |
1658
|
379 { |
|
380 curr_real_fmt = 0; |
|
381 curr_imag_fmt = 0; |
|
382 |
|
383 if (free_format) |
|
384 return; |
|
385 |
2387
|
386 bool sign = m.any_element_is_negative (); |
1658
|
387 |
2387
|
388 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658
|
389 |
2387
|
390 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658
|
391 |
2387
|
392 Matrix m_abs = m.abs (); |
1658
|
393 double max_abs = pr_max_internal (m_abs); |
|
394 double min_abs = pr_min_internal (m_abs); |
|
395 |
2800
|
396 int x_max = max_abs == 0.0 |
|
397 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); |
|
398 |
|
399 int x_min = min_abs == 0.0 |
|
400 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); |
1658
|
401 |
3164
|
402 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : pow (10.0, x_max - 1); |
3105
|
403 |
1658
|
404 set_real_matrix_format (sign, x_max, x_min, inf_or_nan, |
1715
|
405 int_or_inf_or_nan, fw); |
1658
|
406 } |
|
407 |
1
|
408 static inline void |
164
|
409 set_format (const Matrix& m) |
1
|
410 { |
|
411 int fw; |
3105
|
412 double scale; |
|
413 set_format (m, fw, scale); |
1
|
414 } |
|
415 |
|
416 static void |
2387
|
417 set_complex_format (bool sign, int x_max, int x_min, int r_x, |
|
418 bool inf_or_nan, int int_only, int& r_fw, int& i_fw) |
1
|
419 { |
278
|
420 static char r_fmt_buf[128]; |
|
421 static char i_fmt_buf[128]; |
1
|
422 |
2165
|
423 int prec = Voutput_precision; |
1
|
424 |
|
425 int ld, rd; |
|
426 |
|
427 if (bank_format) |
|
428 { |
|
429 int digits = r_x; |
|
430 i_fw = 0; |
|
431 r_fw = digits <= 0 ? 4 : digits + 3; |
|
432 if (inf_or_nan && r_fw < 3) |
|
433 r_fw = 3; |
|
434 r_fw += sign; |
|
435 rd = 2; |
|
436 } |
1282
|
437 else if (hex_format) |
|
438 { |
|
439 r_fw = 2 * sizeof (double); |
|
440 i_fw = 2 * sizeof (double); |
|
441 rd = 0; |
|
442 } |
1309
|
443 else if (bit_format) |
|
444 { |
|
445 r_fw = 8 * sizeof (double); |
|
446 i_fw = 8 * sizeof (double); |
|
447 rd = 0; |
|
448 } |
1658
|
449 else if (inf_or_nan || int_only) |
1
|
450 { |
|
451 int digits = x_max > x_min ? x_max : x_min; |
|
452 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
453 if (inf_or_nan && i_fw < 3) |
|
454 i_fw = r_fw = 3; |
|
455 r_fw += sign; |
|
456 rd = 0; |
|
457 } |
|
458 else |
|
459 { |
|
460 int ld_max, rd_max; |
|
461 if (x_max > 0) |
|
462 { |
|
463 ld_max = x_max; |
1658
|
464 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
465 x_max++; |
|
466 } |
|
467 else |
|
468 { |
|
469 ld_max = 1; |
1658
|
470 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
471 x_max = -x_max + 1; |
|
472 } |
|
473 |
|
474 int ld_min, rd_min; |
|
475 if (x_min > 0) |
|
476 { |
|
477 ld_min = x_min; |
1658
|
478 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
479 x_min++; |
|
480 } |
|
481 else |
|
482 { |
|
483 ld_min = 1; |
1658
|
484 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
485 x_min = -x_min + 1; |
|
486 } |
|
487 |
|
488 ld = ld_max > ld_min ? ld_max : ld_min; |
|
489 rd = rd_max > rd_min ? rd_max : rd_min; |
|
490 |
|
491 i_fw = r_fw = ld + 1 + rd; |
|
492 if (inf_or_nan && i_fw < 3) |
|
493 i_fw = r_fw = 3; |
|
494 r_fw += sign; |
|
495 } |
|
496 |
1309
|
497 if (! (bank_format || hex_format || bit_format) |
2165
|
498 && (r_fw > Voutput_max_field_width || print_e)) |
1
|
499 { |
|
500 int exp_field = 4; |
|
501 if (x_max > 100 || x_min > 100) |
|
502 exp_field++; |
|
503 |
|
504 i_fw = r_fw = 1 + prec + exp_field; |
|
505 if (inf_or_nan && i_fw < 3) |
|
506 i_fw = r_fw = 3; |
|
507 r_fw += sign; |
|
508 |
|
509 if (print_big_e) |
|
510 { |
|
511 sprintf (r_fmt_buf, "%%%d.%dE", r_fw, prec - 1); |
|
512 sprintf (i_fmt_buf, "%%%d.%dE", i_fw, prec - 1); |
|
513 } |
|
514 else |
|
515 { |
|
516 sprintf (r_fmt_buf, "%%%d.%de", r_fw, prec - 1); |
|
517 sprintf (i_fmt_buf, "%%%d.%de", i_fw, prec - 1); |
|
518 } |
|
519 } |
|
520 else |
|
521 { |
|
522 sprintf (r_fmt_buf, "%%%d.%df", r_fw, rd); |
|
523 sprintf (i_fmt_buf, "%%%d.%df", i_fw, rd); |
|
524 } |
|
525 |
|
526 curr_real_fmt = &r_fmt_buf[0]; |
|
527 curr_imag_fmt = &i_fmt_buf[0]; |
|
528 } |
|
529 |
1658
|
530 static void |
|
531 set_format (const Complex& c, int& r_fw, int& i_fw) |
|
532 { |
|
533 curr_real_fmt = 0; |
|
534 curr_imag_fmt = 0; |
|
535 |
|
536 if (free_format) |
|
537 return; |
|
538 |
|
539 double rp = c.real (); |
|
540 double ip = c.imag (); |
|
541 |
2387
|
542 bool sign = (rp < 0.0); |
1658
|
543 |
2387
|
544 bool inf_or_nan = (xisinf (c) || xisnan (c)); |
1658
|
545 |
2387
|
546 bool int_only = (D_NINT (rp) == rp && D_NINT (ip) == ip); |
1658
|
547 |
|
548 double r_abs = rp < 0.0 ? -rp : rp; |
|
549 double i_abs = ip < 0.0 ? -ip : ip; |
|
550 |
2800
|
551 int r_x = r_abs == 0.0 |
|
552 ? 0 : static_cast<int> (floor (log10 (r_abs) + 1.0)); |
|
553 |
|
554 int i_x = i_abs == 0.0 |
|
555 ? 0 : static_cast<int> (floor (log10 (i_abs) + 1.0)); |
1658
|
556 |
|
557 int x_max, x_min; |
|
558 |
|
559 if (r_x > i_x) |
|
560 { |
|
561 x_max = r_x; |
|
562 x_min = i_x; |
|
563 } |
|
564 else |
|
565 { |
|
566 x_max = i_x; |
|
567 x_min = r_x; |
|
568 } |
|
569 |
|
570 set_complex_format (sign, x_max, x_min, r_x, inf_or_nan, int_only, |
|
571 r_fw, i_fw); |
|
572 } |
|
573 |
1
|
574 static inline void |
164
|
575 set_format (const Complex& c) |
1
|
576 { |
|
577 int r_fw, i_fw; |
|
578 set_format (c, r_fw, i_fw); |
|
579 } |
|
580 |
|
581 static void |
2387
|
582 set_complex_matrix_format (bool sign, int x_max, int x_min, |
|
583 int r_x_max, int r_x_min, bool inf_or_nan, |
1715
|
584 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1
|
585 { |
278
|
586 static char r_fmt_buf[128]; |
|
587 static char i_fmt_buf[128]; |
1
|
588 |
2165
|
589 int prec = Voutput_precision; |
1
|
590 |
|
591 int ld, rd; |
|
592 |
|
593 if (bank_format) |
|
594 { |
|
595 int digits = r_x_max > r_x_min ? r_x_max : r_x_min; |
|
596 i_fw = 0; |
|
597 r_fw = digits <= 0 ? 4 : digits + 3; |
|
598 if (inf_or_nan && i_fw < 3) |
|
599 i_fw = r_fw = 3; |
|
600 r_fw += sign; |
|
601 rd = 2; |
|
602 } |
1282
|
603 else if (hex_format) |
|
604 { |
|
605 r_fw = 2 * sizeof (double); |
|
606 i_fw = 2 * sizeof (double); |
|
607 rd = 0; |
|
608 } |
1309
|
609 else if (bit_format) |
|
610 { |
|
611 r_fw = 8 * sizeof (double); |
|
612 i_fw = 8 * sizeof (double); |
|
613 rd = 0; |
|
614 } |
3268
|
615 else if (Vfixed_point_format) |
|
616 { |
|
617 rd = prec; |
|
618 i_fw = r_fw = rd + 2; |
|
619 if (inf_or_nan && i_fw < 3) |
|
620 i_fw = r_fw = 3; |
|
621 r_fw += sign; |
|
622 } |
1715
|
623 else if (int_or_inf_or_nan) |
1
|
624 { |
|
625 int digits = x_max > x_min ? x_max : x_min; |
|
626 i_fw = r_fw = digits <= 0 ? 1 : digits; |
|
627 if (inf_or_nan && i_fw < 3) |
|
628 i_fw = r_fw = 3; |
|
629 r_fw += sign; |
|
630 rd = 0; |
|
631 } |
|
632 else |
|
633 { |
|
634 int ld_max, rd_max; |
|
635 if (x_max > 0) |
|
636 { |
|
637 ld_max = x_max; |
1658
|
638 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
639 x_max++; |
|
640 } |
|
641 else |
|
642 { |
|
643 ld_max = 1; |
1658
|
644 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
645 x_max = -x_max + 1; |
|
646 } |
|
647 |
|
648 int ld_min, rd_min; |
|
649 if (x_min > 0) |
|
650 { |
|
651 ld_min = x_min; |
1658
|
652 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
653 x_min++; |
|
654 } |
|
655 else |
|
656 { |
|
657 ld_min = 1; |
1658
|
658 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
659 x_min = -x_min + 1; |
|
660 } |
|
661 |
|
662 ld = ld_max > ld_min ? ld_max : ld_min; |
|
663 rd = rd_max > rd_min ? rd_max : rd_min; |
|
664 |
|
665 i_fw = r_fw = ld + 1 + rd; |
|
666 if (inf_or_nan && i_fw < 3) |
|
667 i_fw = r_fw = 3; |
|
668 r_fw += sign; |
|
669 } |
|
670 |
1309
|
671 if (! (bank_format || hex_format || bit_format) |
3105
|
672 && (print_e |
|
673 || (! Vfixed_point_format && r_fw > Voutput_max_field_width))) |
1
|
674 { |
|
675 int exp_field = 4; |
|
676 if (x_max > 100 || x_min > 100) |
|
677 exp_field++; |
|
678 |
|
679 i_fw = r_fw = 1 + prec + exp_field; |
|
680 if (inf_or_nan && i_fw < 3) |
|
681 i_fw = r_fw = 3; |
|
682 r_fw += sign; |
|
683 |
|
684 if (print_big_e) |
|
685 { |
|
686 sprintf (r_fmt_buf, "%%%d.%dE", r_fw, prec - 1); |
|
687 sprintf (i_fmt_buf, "%%%d.%dE", i_fw, prec - 1); |
|
688 } |
|
689 else |
|
690 { |
|
691 sprintf (r_fmt_buf, "%%%d.%de", r_fw, prec - 1); |
|
692 sprintf (i_fmt_buf, "%%%d.%de", i_fw, prec - 1); |
|
693 } |
|
694 } |
|
695 else |
|
696 { |
|
697 sprintf (r_fmt_buf, "%%%d.%df", r_fw, rd); |
|
698 sprintf (i_fmt_buf, "%%%d.%df", i_fw, rd); |
|
699 } |
|
700 |
|
701 curr_real_fmt = &r_fmt_buf[0]; |
|
702 curr_imag_fmt = &i_fmt_buf[0]; |
|
703 } |
|
704 |
1658
|
705 static void |
3105
|
706 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658
|
707 { |
|
708 curr_real_fmt = 0; |
|
709 curr_imag_fmt = 0; |
|
710 |
|
711 if (free_format) |
|
712 return; |
|
713 |
|
714 Matrix rp = real (cm); |
|
715 Matrix ip = imag (cm); |
|
716 |
2387
|
717 bool sign = rp.any_element_is_negative (); |
1658
|
718 |
2387
|
719 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658
|
720 |
2387
|
721 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan () |
|
722 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658
|
723 |
2387
|
724 Matrix r_m_abs = rp.abs (); |
1658
|
725 double r_max_abs = pr_max_internal (r_m_abs); |
|
726 double r_min_abs = pr_min_internal (r_m_abs); |
|
727 |
2387
|
728 Matrix i_m_abs = ip.abs (); |
1658
|
729 double i_max_abs = pr_max_internal (i_m_abs); |
|
730 double i_min_abs = pr_min_internal (i_m_abs); |
|
731 |
2800
|
732 int r_x_max = r_max_abs == 0.0 |
|
733 ? 0 : static_cast<int> (floor (log10 (r_max_abs) + 1.0)); |
|
734 |
|
735 int r_x_min = r_min_abs == 0.0 |
|
736 ? 0 : static_cast<int> (floor (log10 (r_min_abs) + 1.0)); |
1658
|
737 |
2800
|
738 int i_x_max = i_max_abs == 0.0 |
|
739 ? 0 : static_cast<int> (floor (log10 (i_max_abs) + 1.0)); |
|
740 |
|
741 int i_x_min = i_min_abs == 0.0 |
|
742 ? 0 : static_cast<int> (floor (log10 (i_min_abs) + 1.0)); |
1658
|
743 |
|
744 int x_max = r_x_max > i_x_max ? r_x_max : i_x_max; |
|
745 int x_min = r_x_min > i_x_min ? r_x_min : i_x_min; |
|
746 |
3164
|
747 scale = (x_max == 0 || int_or_inf_or_nan) ? 1.0 : pow (10.0, x_max - 1); |
3105
|
748 |
1658
|
749 set_complex_matrix_format (sign, x_max, x_min, r_x_max, r_x_min, |
1715
|
750 inf_or_nan, int_or_inf_or_nan, r_fw, i_fw); |
1658
|
751 } |
|
752 |
1
|
753 static inline void |
164
|
754 set_format (const ComplexMatrix& cm) |
1
|
755 { |
|
756 int r_fw, i_fw; |
3105
|
757 double scale; |
|
758 set_format (cm, r_fw, i_fw, scale); |
1
|
759 } |
|
760 |
|
761 static void |
3105
|
762 set_range_format (bool sign, int x_max, int x_min, int all_ints, |
|
763 int& fw) |
1
|
764 { |
278
|
765 static char fmt_buf[128]; |
1
|
766 |
2165
|
767 int prec = Voutput_precision; |
1
|
768 |
|
769 int ld, rd; |
|
770 |
|
771 if (bank_format) |
|
772 { |
|
773 int digits = x_max > x_min ? x_max : x_min; |
|
774 fw = sign + digits < 0 ? 4 : digits + 3; |
|
775 rd = 2; |
|
776 } |
1282
|
777 else if (hex_format) |
|
778 { |
|
779 fw = 2 * sizeof (double); |
|
780 rd = 0; |
|
781 } |
1309
|
782 else if (bit_format) |
|
783 { |
|
784 fw = 8 * sizeof (double); |
|
785 rd = 0; |
|
786 } |
1658
|
787 else if (all_ints) |
1
|
788 { |
|
789 int digits = x_max > x_min ? x_max : x_min; |
|
790 fw = sign + digits; |
|
791 rd = 0; |
|
792 } |
3105
|
793 else if (Vfixed_point_format) |
|
794 { |
|
795 rd = prec; |
|
796 fw = rd + 2 + sign; |
|
797 } |
1
|
798 else |
|
799 { |
|
800 int ld_max, rd_max; |
|
801 if (x_max > 0) |
|
802 { |
|
803 ld_max = x_max; |
1658
|
804 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
805 x_max++; |
|
806 } |
|
807 else |
|
808 { |
|
809 ld_max = 1; |
1658
|
810 rd_max = prec > x_max ? prec - x_max : prec; |
1
|
811 x_max = -x_max + 1; |
|
812 } |
|
813 |
|
814 int ld_min, rd_min; |
|
815 if (x_min > 0) |
|
816 { |
|
817 ld_min = x_min; |
1658
|
818 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
819 x_min++; |
|
820 } |
|
821 else |
|
822 { |
|
823 ld_min = 1; |
1658
|
824 rd_min = prec > x_min ? prec - x_min : prec; |
1
|
825 x_min = -x_min + 1; |
|
826 } |
|
827 |
|
828 ld = ld_max > ld_min ? ld_max : ld_min; |
|
829 rd = rd_max > rd_min ? rd_max : rd_min; |
|
830 |
|
831 fw = sign + ld + 1 + rd; |
|
832 } |
|
833 |
1309
|
834 if (! (bank_format || hex_format || bit_format) |
3105
|
835 && (print_e |
|
836 || (! Vfixed_point_format && fw > Voutput_max_field_width))) |
1
|
837 { |
|
838 int exp_field = 4; |
|
839 if (x_max > 100 || x_min > 100) |
|
840 exp_field++; |
|
841 |
|
842 fw = sign + 2 + prec + exp_field; |
|
843 |
|
844 if (print_big_e) |
|
845 sprintf (fmt_buf, "%%%d.%dE", fw, prec - 1); |
|
846 else |
|
847 sprintf (fmt_buf, "%%%d.%de", fw, prec - 1); |
|
848 } |
|
849 else |
|
850 { |
|
851 sprintf (fmt_buf, "%%%d.%df", fw, rd); |
|
852 } |
|
853 |
|
854 curr_real_fmt = &fmt_buf[0]; |
|
855 } |
|
856 |
1658
|
857 static void |
3105
|
858 set_format (const Range& r, int& fw, double& scale) |
1658
|
859 { |
|
860 curr_real_fmt = 0; |
|
861 curr_imag_fmt = 0; |
|
862 |
|
863 if (free_format) |
|
864 return; |
|
865 |
|
866 double r_min = r.base (); |
|
867 double r_max = r.limit (); |
|
868 |
|
869 if (r_max < r_min) |
|
870 { |
|
871 double tmp = r_max; |
|
872 r_max = r_min; |
|
873 r_min = tmp; |
|
874 } |
|
875 |
2387
|
876 bool sign = (r_min < 0.0); |
1658
|
877 |
2387
|
878 bool all_ints = r.all_elements_are_ints (); |
1658
|
879 |
|
880 double max_abs = r_max < 0.0 ? -r_max : r_max; |
|
881 double min_abs = r_min < 0.0 ? -r_min : r_min; |
|
882 |
2800
|
883 int x_max = max_abs == 0.0 |
|
884 ? 0 : static_cast<int> (floor (log10 (max_abs) + 1.0)); |
|
885 |
|
886 int x_min = min_abs == 0.0 |
|
887 ? 0 : static_cast<int> (floor (log10 (min_abs) + 1.0)); |
1658
|
888 |
3164
|
889 scale = (x_max == 0 || all_ints) ? 1.0 : pow (10.0, x_max - 1); |
3105
|
890 |
1658
|
891 set_range_format (sign, x_max, x_min, all_ints, fw); |
|
892 } |
|
893 |
1
|
894 static inline void |
164
|
895 set_format (const Range& r) |
1
|
896 { |
|
897 int fw; |
3105
|
898 double scale; |
|
899 set_format (r, fw, scale); |
1
|
900 } |
|
901 |
1282
|
902 union equiv |
|
903 { |
|
904 double d; |
|
905 unsigned char i[sizeof (double)]; |
|
906 }; |
|
907 |
1309
|
908 #define PRINT_CHAR_BITS(os, c) \ |
|
909 do \ |
|
910 { \ |
|
911 unsigned char ctmp = c; \ |
|
912 char stmp[9]; \ |
1488
|
913 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
|
914 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ |
|
915 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ |
|
916 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ |
|
917 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ |
|
918 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ |
|
919 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ |
|
920 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ |
1309
|
921 stmp[8] = '\0'; \ |
3013
|
922 os << stmp; \ |
1309
|
923 } \ |
|
924 while (0) |
|
925 |
|
926 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ |
|
927 do \ |
|
928 { \ |
|
929 unsigned char ctmp = c; \ |
|
930 char stmp[9]; \ |
1488
|
931 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
|
932 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ |
|
933 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ |
|
934 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ |
|
935 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ |
|
936 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ |
|
937 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ |
|
938 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ |
1309
|
939 stmp[8] = '\0'; \ |
3013
|
940 os << stmp; \ |
1309
|
941 } \ |
|
942 while (0) |
|
943 |
2522
|
944 static void |
3523
|
945 pr_any_float (const char *fmt, std::ostream& os, double d, int fw = 0) |
1
|
946 { |
2522
|
947 #if defined (SCO) |
|
948 // Apparently on some SCO systems NaN == -0.0 is true. Compiler bug? |
|
949 if (d == -0.0 && ! xisnan (d)) |
|
950 d = 0.0; |
|
951 #else |
1
|
952 if (d == -0.0) |
|
953 d = 0.0; |
2522
|
954 #endif |
1
|
955 |
529
|
956 if (fmt) |
1
|
957 { |
1282
|
958 if (hex_format) |
|
959 { |
|
960 equiv tmp; |
|
961 tmp.d = d; |
|
962 |
|
963 // Unless explicitly asked for, always print in big-endian |
|
964 // format. |
|
965 |
|
966 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
967 // formats and not for Cray? |
|
968 |
3013
|
969 // XXX FIXME XXX -- will bad things happen if we are |
|
970 // interrupted before resetting the format flags and fill |
|
971 // character? |
|
972 |
2317
|
973 oct_mach_info::float_format flt_fmt = |
|
974 oct_mach_info::native_float_format (); |
|
975 |
3013
|
976 char ofill = os.fill ('0'); |
|
977 |
3538
|
978 std::ios::fmtflags oflags = os.setf (std::ios::right); |
|
979 os.setf (std::ios::hex, std::ios::basefield); |
3013
|
980 |
1282
|
981 if (hex_format > 1 |
2317
|
982 || flt_fmt == oct_mach_info::ieee_big_endian |
|
983 || flt_fmt == oct_mach_info::cray |
|
984 || flt_fmt == oct_mach_info::unknown) |
1282
|
985 { |
1322
|
986 for (size_t i = 0; i < sizeof (double); i++) |
3548
|
987 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282
|
988 } |
|
989 else |
|
990 { |
1328
|
991 for (int i = sizeof (double) - 1; i >= 0; i--) |
3548
|
992 os << std::setw (2) << static_cast<int> (tmp.i[i]); |
1282
|
993 } |
3013
|
994 |
|
995 os.fill (ofill); |
|
996 os.setf (oflags); |
1282
|
997 } |
1309
|
998 else if (bit_format) |
|
999 { |
|
1000 equiv tmp; |
|
1001 tmp.d = d; |
|
1002 |
|
1003 // Unless explicitly asked for, always print in big-endian |
|
1004 // format. |
|
1005 |
|
1006 // XXX FIXME XXX -- is it correct to swap bytes for VAX |
|
1007 // formats and not for Cray? |
|
1008 |
2317
|
1009 oct_mach_info::float_format flt_fmt = |
|
1010 oct_mach_info::native_float_format (); |
|
1011 |
|
1012 if (flt_fmt == oct_mach_info::ieee_big_endian |
|
1013 || flt_fmt == oct_mach_info::cray |
|
1014 || flt_fmt == oct_mach_info::unknown) |
1309
|
1015 { |
1322
|
1016 for (size_t i = 0; i < sizeof (double); i++) |
1309
|
1017 PRINT_CHAR_BITS (os, tmp.i[i]); |
|
1018 } |
|
1019 else |
|
1020 { |
|
1021 if (bit_format > 1) |
|
1022 { |
1328
|
1023 for (size_t i = 0; i < sizeof (double); i++) |
1309
|
1024 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]); |
|
1025 } |
|
1026 else |
|
1027 { |
|
1028 for (int i = sizeof (double) - 1; i >= 0; i--) |
|
1029 PRINT_CHAR_BITS (os, tmp.i[i]); |
|
1030 } |
|
1031 } |
|
1032 } |
1282
|
1033 else if (xisinf (d)) |
1
|
1034 { |
2804
|
1035 const char *s; |
1
|
1036 if (d < 0.0) |
|
1037 s = "-Inf"; |
|
1038 else |
|
1039 s = "Inf"; |
|
1040 |
|
1041 if (fw > 0) |
3548
|
1042 os << std::setw (fw) << s; |
1
|
1043 else |
|
1044 os << s; |
|
1045 } |
|
1046 else if (xisnan (d)) |
|
1047 { |
|
1048 if (fw > 0) |
3548
|
1049 os << std::setw (fw) << "NaN"; |
1
|
1050 else |
|
1051 os << "NaN"; |
|
1052 } |
|
1053 else |
|
1054 os.form (fmt, d); |
|
1055 } |
529
|
1056 else |
|
1057 os << d; |
1
|
1058 } |
|
1059 |
|
1060 static inline void |
3523
|
1061 pr_float (std::ostream& os, double d, int fw = 0) |
1
|
1062 { |
|
1063 pr_any_float (curr_real_fmt, os, d, fw); |
|
1064 } |
|
1065 |
|
1066 static inline void |
3523
|
1067 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1
|
1068 { |
|
1069 pr_any_float (curr_imag_fmt, os, d, fw); |
|
1070 } |
|
1071 |
2522
|
1072 static void |
3523
|
1073 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, int i_fw = 0) |
1
|
1074 { |
|
1075 double r = c.real (); |
|
1076 pr_float (os, r, r_fw); |
|
1077 if (! bank_format) |
|
1078 { |
|
1079 double i = c.imag (); |
1309
|
1080 if (! (hex_format || bit_format) && i < 0) |
1
|
1081 { |
|
1082 os << " - "; |
|
1083 i = -i; |
|
1084 pr_imag_float (os, i, i_fw); |
|
1085 } |
|
1086 else |
|
1087 { |
1309
|
1088 if (hex_format || bit_format) |
1282
|
1089 os << " "; |
|
1090 else |
|
1091 os << " + "; |
|
1092 |
1
|
1093 pr_imag_float (os, i, i_fw); |
|
1094 } |
|
1095 os << "i"; |
|
1096 } |
|
1097 } |
|
1098 |
626
|
1099 static void |
3523
|
1100 print_empty_matrix (std::ostream& os, int nr, int nc, bool pr_as_read_syntax) |
626
|
1101 { |
|
1102 assert (nr == 0 || nc == 0); |
|
1103 |
|
1104 if (pr_as_read_syntax) |
|
1105 { |
|
1106 if (nr == 0 && nc == 0) |
|
1107 os << "[]"; |
|
1108 else |
|
1109 os << "zeros (" << nr << ", " << nc << ")"; |
|
1110 } |
|
1111 else |
|
1112 { |
|
1113 os << "[]"; |
2165
|
1114 if (Vprint_empty_dimensions) |
626
|
1115 os << "(" << nr << "x" << nc << ")"; |
|
1116 } |
|
1117 } |
|
1118 |
1186
|
1119 static void |
3523
|
1120 pr_scale_header (std::ostream& os, double scale) |
3105
|
1121 { |
|
1122 if (Vfixed_point_format && scale != 1.0) |
|
1123 { |
|
1124 os.form (" %-8.1e *\n", scale); |
|
1125 |
|
1126 if (! compact_format) |
|
1127 os << "\n"; |
|
1128 } |
|
1129 } |
|
1130 |
|
1131 static void |
3523
|
1132 pr_col_num_header (std::ostream& os, int total_width, int max_width, |
1972
|
1133 int lim, int col, int extra_indent) |
1186
|
1134 { |
2165
|
1135 if (total_width > max_width && Vsplit_long_rows) |
1186
|
1136 { |
|
1137 if (col != 0 && ! compact_format) |
2915
|
1138 os << "\n\n"; |
1186
|
1139 |
|
1140 int num_cols = lim - col; |
|
1141 |
3548
|
1142 os << std::setw (extra_indent) << ""; |
1972
|
1143 |
1186
|
1144 if (num_cols == 1) |
|
1145 os << " Column " << col + 1 << ":\n"; |
|
1146 else if (num_cols == 2) |
|
1147 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
|
1148 else |
|
1149 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915
|
1150 |
|
1151 if (! compact_format) |
|
1152 os << "\n"; |
1186
|
1153 } |
|
1154 } |
|
1155 |
3248
|
1156 static inline void |
3523
|
1157 do_plus_format (std::ostream& os, double d) |
3248
|
1158 { |
|
1159 if (d == 0.0) |
|
1160 os << " "; |
|
1161 else if (d < 0.0) |
|
1162 os << "-"; |
|
1163 else |
|
1164 os << "+"; |
|
1165 } |
|
1166 |
1
|
1167 void |
3523
|
1168 octave_print_internal (std::ostream& os, double d, bool pr_as_read_syntax) |
1
|
1169 { |
|
1170 if (plus_format) |
|
1171 { |
3248
|
1172 do_plus_format (os, d); |
1
|
1173 } |
|
1174 else |
|
1175 { |
|
1176 set_format (d); |
|
1177 if (free_format) |
|
1178 os << d; |
|
1179 else |
|
1180 pr_float (os, d); |
|
1181 } |
|
1182 } |
|
1183 |
|
1184 void |
3523
|
1185 octave_print_internal (std::ostream& os, const Matrix& m, bool pr_as_read_syntax, |
1972
|
1186 int extra_indent) |
1
|
1187 { |
|
1188 int nr = m.rows (); |
|
1189 int nc = m.columns (); |
|
1190 |
2408
|
1191 if (nr == 0 || nc == 0) |
626
|
1192 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1193 else if (plus_format && ! pr_as_read_syntax) |
1
|
1194 { |
|
1195 for (int i = 0; i < nr; i++) |
|
1196 { |
|
1197 for (int j = 0; j < nc; j++) |
|
1198 { |
|
1199 if (j == 0) |
|
1200 os << " "; |
|
1201 |
3248
|
1202 do_plus_format (os, m (i, j)); |
1
|
1203 } |
2907
|
1204 |
|
1205 if (i < nr - 1) |
|
1206 os << "\n"; |
1
|
1207 } |
|
1208 } |
|
1209 else |
|
1210 { |
|
1211 int fw; |
3105
|
1212 double scale = 1.0; |
|
1213 set_format (m, fw, scale); |
1
|
1214 int column_width = fw + 2; |
|
1215 int total_width = nc * column_width; |
2926
|
1216 int max_width = command_editor::terminal_cols (); |
1
|
1217 |
626
|
1218 if (pr_as_read_syntax) |
|
1219 max_width -= 4; |
1972
|
1220 else |
|
1221 max_width -= extra_indent; |
|
1222 |
|
1223 if (max_width < 0) |
|
1224 max_width = 0; |
626
|
1225 |
1
|
1226 if (free_format) |
|
1227 { |
626
|
1228 if (pr_as_read_syntax) |
|
1229 os << "[\n"; |
|
1230 |
1
|
1231 os << m; |
626
|
1232 |
|
1233 if (pr_as_read_syntax) |
|
1234 os << "]"; |
|
1235 |
1
|
1236 return; |
|
1237 } |
|
1238 |
|
1239 int inc = nc; |
2165
|
1240 if (total_width > max_width && Vsplit_long_rows) |
1
|
1241 { |
|
1242 inc = max_width / column_width; |
|
1243 if (inc == 0) |
|
1244 inc++; |
|
1245 } |
|
1246 |
626
|
1247 if (pr_as_read_syntax) |
1
|
1248 { |
|
1249 for (int i = 0; i < nr; i++) |
|
1250 { |
626
|
1251 int col = 0; |
|
1252 while (col < nc) |
1
|
1253 { |
626
|
1254 int lim = col + inc < nc ? col + inc : nc; |
|
1255 |
|
1256 for (int j = col; j < lim; j++) |
|
1257 { |
|
1258 if (i == 0 && j == 0) |
|
1259 os << "[ "; |
|
1260 else |
|
1261 { |
|
1262 if (j > col && j < lim) |
|
1263 os << ", "; |
|
1264 else |
|
1265 os << " "; |
|
1266 } |
|
1267 |
2305
|
1268 pr_float (os, m (i, j)); |
626
|
1269 } |
|
1270 |
|
1271 col += inc; |
|
1272 |
|
1273 if (col >= nc) |
|
1274 { |
|
1275 if (i == nr - 1) |
|
1276 os << " ]"; |
|
1277 else |
|
1278 os << ";\n"; |
|
1279 } |
|
1280 else |
|
1281 os << " ...\n"; |
1
|
1282 } |
|
1283 } |
626
|
1284 } |
|
1285 else |
|
1286 { |
3105
|
1287 pr_scale_header (os, scale); |
|
1288 |
626
|
1289 for (int col = 0; col < nc; col += inc) |
|
1290 { |
|
1291 int lim = col + inc < nc ? col + inc : nc; |
|
1292 |
1972
|
1293 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1294 extra_indent); |
626
|
1295 |
|
1296 for (int i = 0; i < nr; i++) |
|
1297 { |
3548
|
1298 os << std::setw (extra_indent) << ""; |
1972
|
1299 |
626
|
1300 for (int j = col; j < lim; j++) |
|
1301 { |
|
1302 os << " "; |
|
1303 |
3105
|
1304 double tmp = (Vfixed_point_format && scale != 1.0) |
|
1305 ? m(i,j) / scale : m(i,j); |
|
1306 |
|
1307 pr_float (os, tmp, fw); |
626
|
1308 } |
|
1309 |
2907
|
1310 if (i < nr - 1) |
|
1311 os << "\n"; |
626
|
1312 } |
|
1313 } |
1
|
1314 } |
|
1315 } |
|
1316 } |
|
1317 |
3248
|
1318 static inline void |
3523
|
1319 do_plus_format (std::ostream& os, const Complex& c) |
3248
|
1320 { |
|
1321 double rp = c.real (); |
|
1322 double ip = c.imag (); |
|
1323 |
|
1324 if (rp == 0.0) |
|
1325 { |
|
1326 if (ip == 0.0) |
|
1327 os << " "; |
|
1328 else |
|
1329 os << "i"; |
|
1330 } |
|
1331 else if (ip == 0.0) |
|
1332 do_plus_format (os, rp); |
|
1333 else |
|
1334 os << "c"; |
|
1335 } |
|
1336 |
1
|
1337 void |
3523
|
1338 octave_print_internal (std::ostream& os, const Complex& c, |
1972
|
1339 bool pr_as_read_syntax) |
1
|
1340 { |
|
1341 if (plus_format) |
|
1342 { |
3248
|
1343 do_plus_format (os, c); |
1
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 set_format (c); |
|
1348 if (free_format) |
|
1349 os << c; |
|
1350 else |
|
1351 pr_complex (os, c); |
|
1352 } |
|
1353 } |
|
1354 |
|
1355 void |
3523
|
1356 octave_print_internal (std::ostream& os, const ComplexMatrix& cm, |
1972
|
1357 bool pr_as_read_syntax, int extra_indent) |
1
|
1358 { |
|
1359 int nr = cm.rows (); |
|
1360 int nc = cm.columns (); |
|
1361 |
2408
|
1362 if (nr == 0 || nc == 0) |
626
|
1363 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
|
1364 else if (plus_format && ! pr_as_read_syntax) |
1
|
1365 { |
|
1366 for (int i = 0; i < nr; i++) |
|
1367 { |
|
1368 for (int j = 0; j < nc; j++) |
|
1369 { |
|
1370 if (j == 0) |
|
1371 os << " "; |
|
1372 |
3248
|
1373 do_plus_format (os, cm (i, j)); |
1
|
1374 } |
2907
|
1375 |
|
1376 if (i < nr - 1) |
|
1377 os << "\n"; |
1
|
1378 } |
|
1379 } |
|
1380 else |
|
1381 { |
|
1382 int r_fw, i_fw; |
3105
|
1383 double scale = 1.0; |
|
1384 set_format (cm, r_fw, i_fw, scale); |
1
|
1385 int column_width = i_fw + r_fw; |
1309
|
1386 column_width += (bank_format || hex_format|| bit_format) ? 2 : 7; |
1
|
1387 int total_width = nc * column_width; |
2926
|
1388 int max_width = command_editor::terminal_cols (); |
1
|
1389 |
626
|
1390 if (pr_as_read_syntax) |
|
1391 max_width -= 4; |
1972
|
1392 else |
|
1393 max_width -= extra_indent; |
|
1394 |
|
1395 if (max_width < 0) |
|
1396 max_width = 0; |
626
|
1397 |
1
|
1398 if (free_format) |
|
1399 { |
626
|
1400 if (pr_as_read_syntax) |
|
1401 os << "[\n"; |
|
1402 |
1
|
1403 os << cm; |
626
|
1404 |
|
1405 if (pr_as_read_syntax) |
|
1406 os << "]"; |
|
1407 |
1
|
1408 return; |
|
1409 } |
|
1410 |
|
1411 int inc = nc; |
2165
|
1412 if (total_width > max_width && Vsplit_long_rows) |
1
|
1413 { |
|
1414 inc = max_width / column_width; |
|
1415 if (inc == 0) |
|
1416 inc++; |
|
1417 } |
|
1418 |
626
|
1419 if (pr_as_read_syntax) |
1
|
1420 { |
|
1421 for (int i = 0; i < nr; i++) |
|
1422 { |
626
|
1423 int col = 0; |
|
1424 while (col < nc) |
1
|
1425 { |
626
|
1426 int lim = col + inc < nc ? col + inc : nc; |
|
1427 |
|
1428 for (int j = col; j < lim; j++) |
|
1429 { |
|
1430 if (i == 0 && j == 0) |
|
1431 os << "[ "; |
|
1432 else |
|
1433 { |
|
1434 if (j > col && j < lim) |
|
1435 os << ", "; |
|
1436 else |
|
1437 os << " "; |
|
1438 } |
|
1439 |
2305
|
1440 pr_complex (os, cm (i, j)); |
626
|
1441 } |
|
1442 |
|
1443 col += inc; |
|
1444 |
|
1445 if (col >= nc) |
|
1446 { |
|
1447 if (i == nr - 1) |
|
1448 os << " ]"; |
|
1449 else |
|
1450 os << ";\n"; |
|
1451 } |
1
|
1452 else |
626
|
1453 os << " ...\n"; |
1
|
1454 } |
|
1455 } |
626
|
1456 } |
|
1457 else |
|
1458 { |
3105
|
1459 pr_scale_header (os, scale); |
|
1460 |
626
|
1461 for (int col = 0; col < nc; col += inc) |
|
1462 { |
|
1463 int lim = col + inc < nc ? col + inc : nc; |
|
1464 |
1972
|
1465 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1466 extra_indent); |
626
|
1467 |
|
1468 for (int i = 0; i < nr; i++) |
|
1469 { |
3548
|
1470 os << std::setw (extra_indent) << ""; |
1972
|
1471 |
626
|
1472 for (int j = col; j < lim; j++) |
|
1473 { |
|
1474 os << " "; |
|
1475 |
3105
|
1476 Complex tmp = (Vfixed_point_format && scale != 1.0) |
|
1477 ? cm(i,j) / scale : cm(i,j); |
|
1478 |
|
1479 pr_complex (os, tmp, r_fw, i_fw); |
626
|
1480 } |
2907
|
1481 |
|
1482 if (i < nr - 1) |
|
1483 os << "\n"; |
626
|
1484 } |
|
1485 } |
1
|
1486 } |
|
1487 } |
|
1488 } |
|
1489 |
|
1490 void |
3523
|
1491 octave_print_internal (std::ostream& os, const Range& r, |
1972
|
1492 bool pr_as_read_syntax, int extra_indent) |
1
|
1493 { |
626
|
1494 double base = r.base (); |
1
|
1495 double increment = r.inc (); |
626
|
1496 double limit = r.limit (); |
1
|
1497 int num_elem = r.nelem (); |
|
1498 |
626
|
1499 if (plus_format && ! pr_as_read_syntax) |
1
|
1500 { |
|
1501 os << " "; |
|
1502 for (int i = 0; i < num_elem; i++) |
|
1503 { |
626
|
1504 double val = base + i * increment; |
1
|
1505 if (val == 0.0) |
|
1506 os << " "; |
|
1507 else |
|
1508 os << "+"; |
|
1509 } |
|
1510 } |
|
1511 else |
|
1512 { |
|
1513 int fw; |
3105
|
1514 double scale = 1.0; |
|
1515 set_format (r, fw, scale); |
1
|
1516 |
626
|
1517 if (pr_as_read_syntax) |
1
|
1518 { |
626
|
1519 if (free_format) |
|
1520 { |
|
1521 os << base << " : "; |
|
1522 if (increment != 1.0) |
|
1523 os << increment << " : "; |
|
1524 os << limit; |
|
1525 } |
|
1526 else |
|
1527 { |
|
1528 pr_float (os, base, fw); |
|
1529 os << " : "; |
|
1530 if (increment != 1.0) |
|
1531 { |
|
1532 pr_float (os, increment, fw); |
|
1533 os << " : "; |
|
1534 } |
|
1535 pr_float (os, limit, fw); |
|
1536 } |
1
|
1537 } |
626
|
1538 else |
|
1539 { |
|
1540 int column_width = fw + 2; |
|
1541 int total_width = num_elem * column_width; |
2926
|
1542 int max_width = command_editor::terminal_cols (); |
1
|
1543 |
626
|
1544 if (free_format) |
|
1545 { |
|
1546 os << r; |
|
1547 return; |
|
1548 } |
1
|
1549 |
626
|
1550 int inc = num_elem; |
2165
|
1551 if (total_width > max_width && Vsplit_long_rows) |
1
|
1552 { |
626
|
1553 inc = max_width / column_width; |
|
1554 if (inc == 0) |
|
1555 inc++; |
1
|
1556 } |
|
1557 |
1972
|
1558 max_width -= extra_indent; |
|
1559 |
|
1560 if (max_width < 0) |
|
1561 max_width = 0; |
|
1562 |
3105
|
1563 pr_scale_header (os, scale); |
|
1564 |
626
|
1565 int col = 0; |
|
1566 while (col < num_elem) |
1
|
1567 { |
626
|
1568 int lim = col + inc < num_elem ? col + inc : num_elem; |
|
1569 |
1972
|
1570 pr_col_num_header (os, total_width, max_width, lim, col, |
|
1571 extra_indent); |
|
1572 |
3548
|
1573 os << std::setw (extra_indent) << ""; |
626
|
1574 |
|
1575 for (int i = col; i < lim; i++) |
|
1576 { |
|
1577 double val = base + i * increment; |
3105
|
1578 |
626
|
1579 os << " "; |
3105
|
1580 |
|
1581 if (Vfixed_point_format && scale != 1.0) |
|
1582 val /= scale; |
|
1583 |
626
|
1584 pr_float (os, val, fw); |
|
1585 } |
|
1586 |
2907
|
1587 col += inc; |
626
|
1588 |
2907
|
1589 if (col < num_elem) |
|
1590 os << "\n"; |
1
|
1591 } |
|
1592 } |
|
1593 } |
|
1594 } |
|
1595 |
1343
|
1596 void |
3523
|
1597 octave_print_internal (std::ostream& os, const boolMatrix& bm, |
3215
|
1598 bool pr_as_read_syntax, |
|
1599 int extra_indent) |
|
1600 { |
|
1601 Matrix tmp (bm); |
|
1602 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
|
1603 } |
|
1604 |
|
1605 void |
3523
|
1606 octave_print_internal (std::ostream& os, const charMatrix& chm, |
3215
|
1607 bool pr_as_read_syntax, |
|
1608 int /* extra_indent XXX FIXME XXX */, |
|
1609 bool pr_as_string) |
1343
|
1610 { |
1572
|
1611 if (pr_as_string) |
|
1612 { |
|
1613 int nstr = chm.rows (); |
1343
|
1614 |
1572
|
1615 if (pr_as_read_syntax && nstr > 1) |
|
1616 os << "[ "; |
1343
|
1617 |
2907
|
1618 if (nstr != 0) |
1343
|
1619 { |
2664
|
1620 for (int i = 0; i < nstr; i++) |
1572
|
1621 { |
3523
|
1622 std::string row = chm.row_as_string (i); |
2664
|
1623 |
|
1624 if (pr_as_read_syntax) |
|
1625 { |
|
1626 os << "\"" << undo_string_escapes (row) << "\""; |
1343
|
1627 |
2664
|
1628 if (i < nstr - 1) |
|
1629 os << "; "; |
|
1630 } |
|
1631 else |
2907
|
1632 { |
|
1633 os << row; |
|
1634 |
|
1635 if (i < nstr - 1) |
|
1636 os << "\n"; |
|
1637 } |
1572
|
1638 } |
1343
|
1639 } |
1572
|
1640 |
|
1641 if (pr_as_read_syntax && nstr > 1) |
|
1642 os << " ]"; |
1343
|
1643 } |
1572
|
1644 else |
|
1645 { |
|
1646 os << "sorry, printing char matrices not implemented yet\n"; |
|
1647 } |
1343
|
1648 } |
|
1649 |
1957
|
1650 DEFUN (disp, args, , |
3372
|
1651 "-*- texinfo -*-\n\ |
|
1652 @deftypefn {Built-in Function} {} disp (@var{x})\n\ |
|
1653 Display the value of @var{x}. For example,\n\ |
|
1654 \n\ |
|
1655 @example\n\ |
|
1656 disp (\"The value of pi is:\"), disp (pi)\n\ |
|
1657 \n\ |
|
1658 @print{} the value of pi is:\n\ |
|
1659 @print{} 3.1416\n\ |
|
1660 @end example\n\ |
|
1661 \n\ |
|
1662 @noindent\n\ |
|
1663 Note that the output from @code{disp} always ends with a newline.\n\ |
|
1664 @end deftypefn") |
529
|
1665 { |
2086
|
1666 octave_value_list retval; |
529
|
1667 |
|
1668 int nargin = args.length (); |
|
1669 |
712
|
1670 if (nargin == 1) |
2903
|
1671 args(0).print (octave_stdout); |
529
|
1672 else |
|
1673 print_usage ("disp"); |
|
1674 |
|
1675 return retval; |
|
1676 } |
|
1677 |
1
|
1678 static void |
|
1679 init_format_state (void) |
|
1680 { |
2387
|
1681 free_format = false; |
|
1682 plus_format = false; |
|
1683 bank_format = false; |
|
1684 hex_format = false; |
1309
|
1685 bit_format = 0; |
2387
|
1686 print_e = false; |
|
1687 print_big_e = false; |
1
|
1688 } |
|
1689 |
|
1690 static void |
|
1691 set_output_prec_and_fw (int prec, int fw) |
|
1692 { |
2800
|
1693 bind_builtin_variable ("output_precision", static_cast<double> (prec)); |
|
1694 bind_builtin_variable ("output_max_field_width", static_cast<double> (fw)); |
1
|
1695 } |
|
1696 |
1755
|
1697 static void |
|
1698 set_format_style (int argc, const string_vector& argv) |
1
|
1699 { |
1755
|
1700 int idx = 1; |
|
1701 |
1899
|
1702 if (--argc > 0) |
1
|
1703 { |
3523
|
1704 std::string arg = argv[idx++]; |
2584
|
1705 |
1755
|
1706 if (arg == "short") |
1
|
1707 { |
1755
|
1708 if (--argc > 0) |
1
|
1709 { |
1755
|
1710 arg = argv[idx++]; |
|
1711 |
|
1712 if (arg == "e") |
1
|
1713 { |
1755
|
1714 init_format_state (); |
2387
|
1715 print_e = true; |
1755
|
1716 } |
|
1717 else if (arg == "E") |
|
1718 { |
|
1719 init_format_state (); |
2387
|
1720 print_e = true; |
|
1721 print_big_e = true; |
1
|
1722 } |
|
1723 else |
|
1724 { |
1755
|
1725 error ("format: unrecognized option `short %s'", |
|
1726 arg.c_str ()); |
|
1727 return; |
|
1728 } |
|
1729 } |
|
1730 else |
|
1731 init_format_state (); |
|
1732 |
|
1733 set_output_prec_and_fw (3, 8); |
|
1734 } |
|
1735 else if (arg == "long") |
|
1736 { |
|
1737 if (--argc > 0) |
|
1738 { |
|
1739 arg = argv[idx++]; |
|
1740 |
|
1741 if (arg == "e") |
|
1742 { |
|
1743 init_format_state (); |
2387
|
1744 print_e = true; |
1755
|
1745 } |
|
1746 else if (arg == "E") |
|
1747 { |
|
1748 init_format_state (); |
2387
|
1749 print_e = true; |
|
1750 print_big_e = true; |
1
|
1751 } |
|
1752 else |
1755
|
1753 { |
|
1754 error ("format: unrecognized option `long %s'", |
|
1755 arg.c_str ()); |
|
1756 return; |
|
1757 } |
1186
|
1758 } |
1
|
1759 else |
1755
|
1760 init_format_state (); |
|
1761 |
|
1762 set_output_prec_and_fw (15, 24); |
|
1763 } |
|
1764 else if (arg == "hex") |
|
1765 { |
|
1766 init_format_state (); |
2387
|
1767 hex_format = true; |
1755
|
1768 } |
|
1769 else if (arg == "native-hex") |
|
1770 { |
|
1771 init_format_state (); |
|
1772 hex_format = 2; |
|
1773 } |
|
1774 else if (arg == "bit") |
|
1775 { |
|
1776 init_format_state (); |
|
1777 bit_format = 1; |
|
1778 } |
|
1779 else if (arg == "native-bit") |
|
1780 { |
|
1781 init_format_state (); |
|
1782 bit_format = 2; |
|
1783 } |
|
1784 else if (arg == "+" || arg == "plus") |
|
1785 { |
|
1786 init_format_state (); |
2387
|
1787 plus_format = true; |
1755
|
1788 } |
|
1789 else if (arg == "bank") |
|
1790 { |
|
1791 init_format_state (); |
2387
|
1792 bank_format = true; |
1755
|
1793 } |
|
1794 else if (arg == "free") |
|
1795 { |
|
1796 init_format_state (); |
2387
|
1797 free_format = true; |
1755
|
1798 } |
|
1799 else if (arg == "none") |
|
1800 { |
|
1801 init_format_state (); |
2387
|
1802 free_format = true; |
1755
|
1803 } |
|
1804 else if (arg == "compact") |
|
1805 { |
2387
|
1806 compact_format = true; |
1755
|
1807 } |
|
1808 else if (arg == "loose") |
|
1809 { |
2387
|
1810 compact_format = false; |
1
|
1811 } |
|
1812 else |
1755
|
1813 error ("format: unrecognized format state `%s'", arg.c_str ()); |
1
|
1814 } |
|
1815 else |
|
1816 { |
|
1817 init_format_state (); |
|
1818 set_output_prec_and_fw (5, 10); |
|
1819 } |
|
1820 } |
|
1821 |
1957
|
1822 DEFUN_TEXT (format, args, , |
3372
|
1823 "-*- texinfo -*-\n\ |
|
1824 @deffn {Command} format options\n\ |
|
1825 Control the format of the output produced by @code{disp} and Octave's\n\ |
|
1826 normal echoing mechanism. Valid options are listed in the following\n\ |
|
1827 table.\n\ |
|
1828 \n\ |
|
1829 @table @code\n\ |
|
1830 @item short\n\ |
|
1831 Octave will try to print numbers with at\n\ |
|
1832 least 3 significant figures within a field that is a maximum of 8\n\ |
|
1833 characters wide.\n\ |
|
1834 \n\ |
|
1835 If Octave is unable to format a matrix so that columns line up on the\n\ |
|
1836 decimal point and all the numbers fit within the maximum field width,\n\ |
|
1837 it switches to an @samp{e} format.\n\ |
|
1838 \n\ |
|
1839 @item long\n\ |
|
1840 Octave will try to print numbers with at least 15 significant figures\n\ |
|
1841 within a field that is a maximum of 24 characters wide.\n\ |
|
1842 \n\ |
|
1843 As will the @samp{short} format, Octave will switch to an @samp{e}\n\ |
|
1844 format if it is unable to format a matrix so that columns line up on the\n\ |
|
1845 decimal point and all the numbers fit within the maximum field width.\n\ |
|
1846 \n\ |
|
1847 @item long e\n\ |
|
1848 @itemx short e\n\ |
|
1849 The same as @samp{format long} or @samp{format short} but always display\n\ |
|
1850 output with an @samp{e} format. For example, with the @samp{short e}\n\ |
|
1851 format, pi is displayed as @code{3.14e+00}.\n\ |
|
1852 \n\ |
|
1853 @item long E\n\ |
|
1854 @itemx short E\n\ |
|
1855 The same as @samp{format long e} or @samp{format short e} but always\n\ |
|
1856 display output with an uppercase @samp{E} format. For example, with\n\ |
|
1857 the @samp{long E} format, pi is displayed as\n\ |
|
1858 @code{3.14159265358979E+00}.\n\ |
|
1859 \n\ |
|
1860 @item free\n\ |
|
1861 @itemx none\n\ |
|
1862 Print output in free format, without trying to line up columns of\n\ |
|
1863 matrices on the decimal point. This also causes complex numbers to be\n\ |
|
1864 formatted like this @samp{(0.604194, 0.607088)} instead of like this\n\ |
|
1865 @samp{0.60419 + 0.60709i}.\n\ |
529
|
1866 \n\ |
3372
|
1867 @item bank\n\ |
|
1868 Print in a fixed format with two places to the right of the decimal\n\ |
|
1869 point.\n\ |
|
1870 \n\ |
|
1871 @item +\n\ |
|
1872 Print a @samp{+} symbol for nonzero matrix elements and a space for zero\n\ |
|
1873 matrix elements. This format can be very useful for examining the\n\ |
|
1874 structure of a large matrix.\n\ |
|
1875 \n\ |
|
1876 @item hex\n\ |
|
1877 Print the hexadecimal representation numbers as they are stored in\n\ |
|
1878 memory. For example, on a workstation which stores 8 byte real values\n\ |
|
1879 in IEEE format with the least significant byte first, the value of\n\ |
|
1880 @code{pi} when printed in @code{hex} format is @code{400921fb54442d18}.\n\ |
|
1881 This format only works for numeric values.\n\ |
|
1882 \n\ |
|
1883 @item bit\n\ |
|
1884 Print the bit representation of numbers as stored in memory.\n\ |
|
1885 For example, the value of @code{pi} is\n\ |
|
1886 \n\ |
|
1887 @example\n\ |
|
1888 @group\n\ |
|
1889 01000000000010010010000111111011\n\ |
|
1890 01010100010001000010110100011000\n\ |
|
1891 @end group\n\ |
|
1892 @end example\n\ |
|
1893 \n\ |
|
1894 (shown here in two 32 bit sections for typesetting purposes) when\n\ |
|
1895 printed in bit format on a workstation which stores 8 byte real values\n\ |
|
1896 in IEEE format with the least significant byte first. This format only\n\ |
|
1897 works for numeric types.\n\ |
|
1898 @end table\n\ |
|
1899 \n\ |
|
1900 By default, Octave will try to print numbers with at least 5 significant\n\ |
|
1901 figures within a field that is a maximum of 10 characters wide.\n\ |
|
1902 \n\ |
|
1903 If Octave is unable to format a matrix so that columns line up on the\n\ |
|
1904 decimal point and all the numbers fit within the maximum field width,\n\ |
|
1905 it switches to an @samp{e} format.\n\ |
|
1906 \n\ |
|
1907 If @code{format} is invoked without any options, the default format\n\ |
|
1908 state is restored.\n\ |
|
1909 @end deffn") |
529
|
1910 { |
2086
|
1911 octave_value_list retval; |
529
|
1912 |
1755
|
1913 int argc = args.length () + 1; |
|
1914 |
1968
|
1915 string_vector argv = args.make_argv ("format"); |
1755
|
1916 |
|
1917 if (error_state) |
|
1918 return retval; |
529
|
1919 |
|
1920 set_format_style (argc, argv); |
|
1921 |
|
1922 return retval; |
|
1923 } |
|
1924 |
2165
|
1925 static int |
3105
|
1926 fixed_point_format (void) |
|
1927 { |
|
1928 Vfixed_point_format = check_preference ("fixed_point_format"); |
|
1929 |
|
1930 return 0; |
|
1931 } |
|
1932 |
|
1933 static int |
2165
|
1934 output_max_field_width (void) |
|
1935 { |
|
1936 double val; |
|
1937 if (builtin_real_scalar_variable ("output_max_field_width", val) |
|
1938 && ! xisnan (val)) |
|
1939 { |
|
1940 int ival = NINT (val); |
2800
|
1941 if (ival > 0 && ival == val) |
2165
|
1942 { |
|
1943 Voutput_max_field_width = ival; |
|
1944 return 0; |
|
1945 } |
|
1946 } |
|
1947 gripe_invalid_value_specified ("output_max_field_width"); |
|
1948 return -1; |
|
1949 } |
|
1950 |
|
1951 static int |
|
1952 output_precision (void) |
|
1953 { |
|
1954 double val; |
|
1955 if (builtin_real_scalar_variable ("output_precision", val) |
|
1956 && ! xisnan (val)) |
|
1957 { |
|
1958 int ival = NINT (val); |
2800
|
1959 if (ival >= 0 && ival == val) |
2165
|
1960 { |
|
1961 Voutput_precision = ival; |
|
1962 return 0; |
|
1963 } |
|
1964 } |
|
1965 gripe_invalid_value_specified ("output_precision"); |
|
1966 return -1; |
|
1967 } |
|
1968 |
|
1969 static int |
|
1970 print_empty_dimensions (void) |
|
1971 { |
|
1972 Vprint_empty_dimensions = check_preference ("print_empty_dimensions"); |
|
1973 |
|
1974 return 0; |
|
1975 } |
|
1976 |
|
1977 static int |
|
1978 split_long_rows (void) |
|
1979 { |
|
1980 Vsplit_long_rows = check_preference ("split_long_rows"); |
|
1981 |
|
1982 return 0; |
|
1983 } |
|
1984 |
|
1985 void |
|
1986 symbols_of_pr_output (void) |
|
1987 { |
3258
|
1988 DEFVAR (fixed_point_format, 0.0, fixed_point_format, |
3321
|
1989 "-*- texinfo -*-\n\ |
|
1990 @defvr {Built-in Variable} fixed_point_format\n\ |
|
1991 If the value of this variable is nonzero, Octave will scale all values\n\ |
|
1992 in a matrix so that the largest may be written with one leading digit.\n\ |
|
1993 The scaling factor is printed on the first line of output. For example,\n\ |
|
1994 \n\ |
|
1995 @example\n\ |
|
1996 @group\n\ |
|
1997 octave:1> logspace (1, 7, 5)'\n\ |
|
1998 ans =\n\ |
|
1999 \n\ |
|
2000 1.0e+07 *\n\ |
|
2001 \n\ |
|
2002 0.00000\n\ |
|
2003 0.00003\n\ |
|
2004 0.00100\n\ |
|
2005 0.03162\n\ |
|
2006 1.00000\n\ |
|
2007 @end group\n\ |
|
2008 @end example\n\ |
|
2009 \n\ |
|
2010 @noindent\n\ |
|
2011 Notice that first value appears to be zero when it is actually 1. For\n\ |
|
2012 this reason, you should be careful when setting\n\ |
|
2013 @code{fixed_point_format} to a nonzero value.\n\ |
|
2014 \n\ |
|
2015 The default value of @code{fixed_point_format} is 0.\n\ |
3333
|
2016 @end defvr"); |
3105
|
2017 |
3258
|
2018 DEFVAR (output_max_field_width, 10.0, output_max_field_width, |
3321
|
2019 "-*- texinfo -*-\n\ |
|
2020 @defvr {Built-in Variable} output_max_field_width\n\ |
|
2021 This variable specifies the maximum width of a numeric output field.\n\ |
|
2022 The default value is 10.\n\ |
3333
|
2023 @end defvr"); |
2165
|
2024 |
3258
|
2025 DEFVAR (output_precision, 5.0, output_precision, |
3321
|
2026 "-*- texinfo -*-\n\ |
|
2027 @defvr {Built-in Variable} output_precision\n\ |
|
2028 This variable specifies the minimum number of significant figures to\n\ |
|
2029 display for numeric output. The default value is 5.\n\ |
3333
|
2030 @end defvr"); |
2165
|
2031 |
3258
|
2032 DEFVAR (print_empty_dimensions, 1.0, print_empty_dimensions, |
3321
|
2033 "-*- texinfo -*-\n\ |
|
2034 @defvr {Built-in Variable} print_empty_dimensions\n\ |
|
2035 If the value of @code{print_empty_dimensions} is nonzero, the\n\ |
|
2036 dimensions of empty matrices are printed along with the empty matrix\n\ |
|
2037 symbol, @samp{[]}. For example, the expression\n\ |
|
2038 \n\ |
|
2039 @example\n\ |
|
2040 zeros (3, 0)\n\ |
|
2041 @end example\n\ |
|
2042 \n\ |
|
2043 @noindent\n\ |
|
2044 will print\n\ |
|
2045 \n\ |
|
2046 @example\n\ |
|
2047 ans = [](3x0)\n\ |
|
2048 @end example\n\ |
3333
|
2049 @end defvr"); |
2165
|
2050 |
3258
|
2051 DEFVAR (split_long_rows, 1.0, split_long_rows, |
3321
|
2052 "-*- texinfo -*-\n\ |
|
2053 @defvr {Built-in Variable} split_long_rows\n\ |
|
2054 For large matrices, Octave may not be able to display all the columns of\n\ |
|
2055 a given row on one line of your screen. This can result in missing\n\ |
|
2056 information or output that is nearly impossible to decipher, depending\n\ |
|
2057 on whether your terminal truncates or wraps long lines.\n\ |
|
2058 \n\ |
|
2059 If the value of @code{split_long_rows} is nonzero, Octave will display\n\ |
|
2060 the matrix in a series of smaller pieces, each of which can fit within\n\ |
|
2061 the limits of your terminal width. Each set of rows is labeled so that\n\ |
|
2062 you can easily see which columns are currently being displayed.\n\ |
|
2063 For example:\n\ |
|
2064 \n\ |
|
2065 @smallexample\n\ |
|
2066 @group\n\ |
|
2067 octave:13> rand (2,10)\n\ |
|
2068 ans =\n\ |
|
2069 \n\ |
|
2070 Columns 1 through 6:\n\ |
|
2071 \n\ |
|
2072 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467\n\ |
|
2073 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201\n\ |
|
2074 \n\ |
|
2075 Columns 7 through 10:\n\ |
|
2076 \n\ |
|
2077 0.90174 0.11854 0.72313 0.73326\n\ |
|
2078 0.44672 0.94303 0.56564 0.82150\n\ |
|
2079 @end group\n\ |
|
2080 @end smallexample\n\ |
|
2081 \n\ |
|
2082 @noindent\n\ |
|
2083 The default value of @code{split_long_rows} is nonzero.\n\ |
3333
|
2084 @end defvr"); |
2165
|
2085 } |
|
2086 |
1
|
2087 /* |
|
2088 ;;; Local Variables: *** |
|
2089 ;;; mode: C++ *** |
|
2090 ;;; End: *** |
|
2091 */ |