annotate libinterp/corefcn/pr-output.cc @ 27439:251056aeba5d

Align negative numbers correctly with g format (bug #56940). * pr-output.cc (make_real_matrix_format, make_complex_format, make_complex_matrix_format, make_range_format): Increase width of format by 1 to allow for '-' sign.
author Rik <rik@octave.org>
date Mon, 23 Sep 2019 13:51:17 -0700
parents 57f5c5768eb3
children ce0399fa017a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26205
diff changeset
3 Copyright (C) 1993-2019 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
11
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
19 <https://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21662
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
23662
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23619
diff changeset
27 #include <cmath>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
28
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3373
diff changeset
29 #include <iomanip>
23455
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
30 #include <limits>
73ff72d3d603 maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents: 23450
diff changeset
31 #include <list>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5759
diff changeset
32 #include <sstream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
33 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1716
diff changeset
34
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
35 #include "Array-util.h"
453
393e95f46b51 [project @ 1994-06-06 00:05:20 by jwe]
jwe
parents: 296
diff changeset
36 #include "CMatrix.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37 #include "Range.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2915
diff changeset
38 #include "cmd-edit.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
39 #include "dMatrix.h"
2891
1a30f46e1870 [project @ 1997-04-28 01:49:00 by jwe]
jwe
parents: 2847
diff changeset
40 #include "lo-mappers.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2305
diff changeset
41 #include "mach-info.h"
1651
e846e361a265 [project @ 1995-12-20 06:59:12 by jwe]
jwe
parents: 1588
diff changeset
42 #include "oct-cmplx.h"
26111
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
43 #include "oct-string.h"
4153
6b96ce9f5743 [project @ 2002-11-06 20:38:49 by jwe]
jwe
parents: 4051
diff changeset
44 #include "quit.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
45
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
46 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
47 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
48 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21066
diff changeset
49 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
50 #include "ovl.h"
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
51 #include "oct-stream.h"
20925
667861ffffab Extracted header class octave-preserve-stream-state from utils.{cc/h}.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 20915
diff changeset
52 #include "octave-preserve-stream-state.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
53 #include "pager.h"
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
54 #include "parse.h"
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
55 #include "pr-flt-fmt.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
56 #include "pr-output.h"
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
57 #include "sysdep.h"
6803
fe19c6cb5bc6 [project @ 2007-07-26 18:04:05 by jwe]
jwe
parents: 6788
diff changeset
58 #include "unwind-prot.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
59 #include "utils.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1346
diff changeset
60 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
61
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
62 // TRUE means use a scaled fixed point format for 'format long' and
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
63 // 'format short'.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
64 static bool Vfixed_point_format = false;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
65
5360
33adb987c033 [project @ 2005-05-23 16:19:56 by jwe]
jwe
parents: 5331
diff changeset
66 // TRUE means that the dimensions of empty objects should be printed
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
67 // like this: x = [](2x0).
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
68 bool Vprint_empty_dimensions = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
69
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
70 // TRUE means that the rows of big matrices should be split into
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
71 // smaller slices that fit on the screen.
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
72 static bool Vsplit_long_rows = true;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
73
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
74 // TRUE means don't do any fancy formatting.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
75 static bool free_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
76
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
77 // TRUE means print plus sign for nonzero, blank for zero.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
78 static bool plus_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
79
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
80 // First char for > 0, second for < 0, third for == 0.
19232
97eea1e2d9ff pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
81 static std::string plus_format_chars = "+- ";
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
82
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
83 // TRUE means always print in a rational approximation
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
84 static bool rat_format = false;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
85
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
86 // Used to force the length of the rational approximation string for Frats
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
87 static int rat_string_len = -1;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
88
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
89 // TRUE means always print like dollars and cents.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
90 static bool bank_format = false;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
91
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
92 // TRUE means print data in hexadecimal format.
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
93 static int hex_format = 0;
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
94
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
95 // TRUE means print data in binary-bit-pattern format.
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
96 static int bit_format = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
97
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
98 // TRUE means don't put newlines around the column number headers.
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
99 bool Vcompact_format = false;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
100
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
101 // TRUE means use an e format.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
102 static bool print_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
103
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
104 // TRUE means use a g format.
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
105 static bool print_g = false;
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
106
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3014
diff changeset
107 // TRUE means print E instead of e for exponent field.
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
108 static bool print_big_e = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
109
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
110 // TRUE means use an engineering format.
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
111 static bool print_eng = false;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
112
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
113 static int
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
114 calc_scale_exp (const int& x)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
115 {
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
116 if (! print_eng)
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
117 return x;
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
118 else
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
119 return x - 3*static_cast<int> (x/3);
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
120
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
121 // The expression above is equivalent to x - (x % 3).
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
122
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
123 // According to the ISO specification for C++ the modulo operator is
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
124 // compiler dependent if any of the arguments are negative. Since
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
125 // this function will need to work on negative arguments, and we want
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
126 // to avoid portability issues, we re-implement the modulo function to
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
127 // the desired behavior (truncation). There may be a gnulib
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
128 // replacement.
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
129
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
130 // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO,
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
131 // IEC. 2003 . "the binary % operator yields the remainder from the
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
132 // division of the first expression by the second. .... If both
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
133 // operands are nonnegative then the remainder is nonnegative; if not,
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
134 // the sign of the remainder is implementation-defined".
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
135 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
136
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
137 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
138 static inline int
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
139 engineering_exponent (T x)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
140 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
141 int ex = 0;
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
142
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
143 if (x != 0)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
144 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
145 T absval = (x < 0 ? -x : x);
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
146 int logabsval = static_cast<int> (std::floor (log10 (absval)));
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
147
20946
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
148 // Avoid using modulo function with negative arguments for
6eff66fb8a02 style fixes for comments
John W. Eaton <jwe@octave.org>
parents: 20941
diff changeset
149 // portability. See extended comment at calc_scale_exp
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
150
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
151 if (logabsval < 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
152 ex = logabsval - 2 + ((-logabsval + 2) % 3);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
153 else
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
154 ex = logabsval - (logabsval % 3);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
155 }
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
156
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
157 return ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
158 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
159
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
160 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
161 static inline int
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
162 num_digits (T x)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
163 {
11450
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
164 return 1 + (print_eng
5eb10763069f substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents: 10987
diff changeset
165 ? engineering_exponent (x)
21942
aab79a1885cc limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents: 21782
diff changeset
166 : static_cast<int> (std::floor (log10 (x))));
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
167 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
168
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
169 template <typename T>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
170 int
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
171 pr_engineering_float<T>::exponent (void) const
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
172 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
173 return engineering_exponent (m_val);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
174 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
175
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
176 template <typename T>
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
177 T
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
178 pr_engineering_float<T>::mantissa (void) const
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
179 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
180 return m_val / std::pow (static_cast<T> (10), exponent ());
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
181 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
182
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
183 template <typename T>
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
184 std::ostream&
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
185 operator << (std::ostream& os, const pr_engineering_float<T>& pef)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
186 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
187 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
188
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
189 float_format real_fmt = pef.m_ff;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
190
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
191 if (real_fmt.width () >= 0)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
192 os << std::setw (real_fmt.width () - real_fmt.exponent_width ());
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
193
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
194 if (real_fmt.precision () >= 0)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
195 os << std::setprecision (real_fmt.precision ());
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
196
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
197 os.flags (real_fmt.format_flags ());
10771
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
198
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
199 os << pef.mantissa ();
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
200
82d9efde7e96 pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents: 10741
diff changeset
201 int ex = pef.exponent ();
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
202 if (ex < 0)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
203 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
204 os << std::setw (0) << "e-";
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
205 ex = -ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
206 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
207 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
208 os << std::setw (0) << "e+";
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
209
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
210 os << std::setw (real_fmt.exponent_width () - 2)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
211 << std::setfill ('0') << ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
212
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
213 return os;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
214 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
215
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
216 template <typename T>
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
217 std::ostream&
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
218 operator << (std::ostream& os, const pr_formatted_float<T>& pff)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
219 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
220 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
221
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
222 float_format real_fmt = pff.m_ff;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
223
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
224 if (real_fmt.width () >= 0)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
225 os << std::setw (real_fmt.width ());
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
226
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
227 if (real_fmt.precision () >= 0)
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
228 os << std::setprecision (real_fmt.precision ());
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
229
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
230 os.flags (real_fmt.format_flags ());
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
231
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
232 os << pff.m_val;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
233
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
234 return os;
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
235 }
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
236
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
237 template <typename T>
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
238 std::ostream&
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
239 operator << (std::ostream& os, const pr_rational_float<T>& prf)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
240 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
241 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
242
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
243 float_format real_fmt = prf.m_ff;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
244
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
245 int fw = (rat_string_len > 0 ? rat_string_len : real_fmt.width ());
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
246 std::string s = rational_approx (prf.m_val, fw);
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
247
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
248 if (fw >= 0)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
249 os << std::setw (fw);
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
250
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
251 os.flags (real_fmt.format_flags ());
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
252
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
253 if (fw > 0 && s.length () > static_cast<unsigned int> (fw))
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
254 os << '*';
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
255 else
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
256 os << s;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
257
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
258 return os;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
259 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
260
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
261 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
262 static inline T
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
263 pr_max_internal (const MArray<T>& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
264 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
265 // We expect a 2-d array.
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
266 assert (m.ndims () == 2);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
267
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
268 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
269 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
270
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
271 T result = std::numeric_limits<T>::lowest ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
272
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
273 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
274
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
275 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
276 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
277 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
278 T val = m(i,j);
23564
7049da1648c0 Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents: 23534
diff changeset
279 if (! octave::math::isfinite (val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
280 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
281
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
282 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
283
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
284 if (val > result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
285 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
286 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
287
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
288 if (all_inf_or_nan)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
289 result = 0;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
290
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
291 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
292 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
293
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
294 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
295 static inline T
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
296 pr_min_internal (const MArray<T>& m)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
297 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
298 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
299 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
300
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
301 T result = std::numeric_limits<T>::max ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
302
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
303 bool all_inf_or_nan = true;
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
304
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
305 for (octave_idx_type j = 0; j < nc; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
306 for (octave_idx_type i = 0; i < nr; i++)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
307 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
308 T val = m(i,j);
23564
7049da1648c0 Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents: 23534
diff changeset
309 if (! octave::math::isfinite (val))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
310 continue;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
311
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
312 all_inf_or_nan = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
314 if (val < result)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
315 result = val;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
316 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
317
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
318 if (all_inf_or_nan)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
319 result = 0;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
320
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
321 return result;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
322 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
323
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
324 template <typename>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
325 struct pr_output_traits
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
326 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
327 static const int digits10;
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
328 static const int max_field_width;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
329 };
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
330
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
331 template <>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
332 struct pr_output_traits<double>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
333 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
334 static const int digits10;
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
335 static const int max_field_width;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
336 };
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
337
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
338 const int pr_output_traits<double>::digits10 = 16;
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
339 const int pr_output_traits<double>::max_field_width = 21;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
340
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
341 template <>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
342 struct pr_output_traits<float>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
343 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
344 static const int digits10;
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
345 static const int max_field_width;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
346 };
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
347
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
348 const int pr_output_traits<float>::digits10 = 8;
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
349 const int pr_output_traits<float>::max_field_width = 13;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
350
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
351 // FIXME: it would be nice to share more code among these functions,..
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
352
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
353 // Works for double and float.
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
354
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
355 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
356 static inline float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
357 make_real_format (int digits, bool inf_or_nan, bool int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
358 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
359 float_format fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
360
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
361 int prec = std::min (output_precision (), pr_output_traits<T>::digits10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
362
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
363 int fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
364
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
365 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
366 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
367 fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
368 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
369 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
370 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
371 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
372 fw = (digits < 0 ? 5 : digits + 4);
17847
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
373 if (inf_or_nan && fw < 5)
3a0075793fcd allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents: 17818
diff changeset
374 fw = 5;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
375 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
376 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
377 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
378 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
379 fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
380 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
381 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
382 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
383 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
384 fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
385 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
386 }
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
387 else if (inf_or_nan || int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
388 {
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
389 fw = 1 + digits;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
390 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
391 fw = 4;
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
392
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
393 if (int_only)
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
394 {
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
395 ld = digits;
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
396 rd = 0;
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
397 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
398 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
399 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
400 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
401 if (digits > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
402 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
403 ld = digits;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
404 rd = (prec > digits ? prec - digits : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
405 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
406 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
407 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
408 ld = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
409 rd = (prec > digits ? prec - digits : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
410 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
411
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
412 fw = 1 + ld + 1 + rd;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
413 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
414
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
415 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
416 && (print_e || print_g || print_eng
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
417 || ld + rd > pr_output_traits<T>::digits10
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
418 || fw > pr_output_traits<T>::max_field_width))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
419 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
420 if (print_g)
27430
ba3fc70ba996 Correctly print "format g" when variable is of single type (bug #56926).
Rik <rik@octave.org>
parents: 27429
diff changeset
421 fmt = float_format (prec+5, prec);
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
422 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
423 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
424 // e+ddd
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
425 int ex = 5;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
426
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
427 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
428 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
429 // -ddd.
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
430 fw = 5 + prec + ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
431 if (inf_or_nan && fw < 6)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
432 fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
433 fmt = float_format (fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
434 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
435 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
436 {
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
437 // -d.
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
438 fw = 3 + prec + ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
439 if (inf_or_nan && fw < 4)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
440 fw = 4;
16339
0c340bf413d7 allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents: 16169
diff changeset
441 fmt = float_format (fw, ex, prec - 1, std::ios::scientific);
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
442 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
443 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
444
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
445 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
446 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
447 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
448 else if (! bank_format && (inf_or_nan || int_only))
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
449 fmt = float_format (fw, ld);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
450 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
451 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
452
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
453 return float_display_format (fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
454 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
455
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
456 // Works for double and float.
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
457
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
458 template <typename T>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
459 float_display_format
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
460 make_scalar_format (const T& val)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
461 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
462 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
463 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
464
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
465 bool inf_or_nan = (octave::math::isinf (val) || octave::math::isnan (val));
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
466
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
467 bool int_only = (! inf_or_nan && octave::math::x_nint (val) == val);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
468
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
469 T val_abs = (val < 0 ? -val : val);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
470
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
471 int digits = (inf_or_nan || val_abs == 0) ? 0 : num_digits (val_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
472
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
473 return make_real_format<T> (digits, inf_or_nan, int_only);
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
474 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
475
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
476 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
477 float_display_format
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
478 make_format (const double& d)
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
479 {
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
480 return make_scalar_format (d);
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
481 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
482
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
483 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
484 float_display_format
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
485 make_format (const float& f)
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
486 {
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
487 return make_scalar_format (f);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
488 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
489
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
490 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
491 static inline float_display_format
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
492 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
493 int int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
494 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
495 T scale = ((x_max == 0 || int_or_inf_or_nan)
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
496 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1)));
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
497
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
498 float_format fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
499
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
500 int prec = std::min (output_precision (), pr_output_traits<T>::digits10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
501
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
502 int fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
503
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
504 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
505 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
506 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
507 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
508 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
509 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
510 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
511 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
512 fw = (digits <= 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
513 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
514 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
515 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
516 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
517 fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
518 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
519 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
520 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
521 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
522 fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
523 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
524 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
525 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
526 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
527 rd = prec;
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
528 fw = rd + 3;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
529 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
530 fw = 4;
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
531 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
532 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
533 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
534 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
535 fw = (digits <= 0 ? 2 : digits + 1);
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
536 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
537 fw = 4;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
538 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
539 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
540 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
541 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
542 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
543 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
544 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
545 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
546 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
547 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
548 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
549 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
550 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
551 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
552 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
553 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
554 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
555
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
556 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
557 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
558 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
559 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
560 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
561 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
562 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
563 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
564 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
565 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
566 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
567 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
568 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
569
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
570 ld = (ld_max > ld_min ? ld_max : ld_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
571 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
572
5832
5e41e06f6a78 [project @ 2006-05-26 21:41:32 by jwe]
jwe
parents: 5823
diff changeset
573 fw = 1 + ld + 1 + rd;
5748
8510034588a7 [project @ 2006-04-07 07:51:59 by jwe]
jwe
parents: 5642
diff changeset
574 if (inf_or_nan && fw < 4)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
575 fw = 4;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
576 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
577
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
578 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
579 && (print_e || print_eng || print_g
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
580 || (! Vfixed_point_format
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
581 && (ld + rd > pr_output_traits<T>::digits10
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
582 || fw > pr_output_traits<T>::max_field_width))))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
583 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
584 if (print_g)
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
585 fmt = float_format (prec+6, prec);
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
586 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
587 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
588 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
589 if (x_max > 100 || x_min > 100)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
590 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
591
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
592 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
593 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
594 fw = 4 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
595 if (inf_or_nan && fw < 6)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
596 fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
597 fmt = float_format (fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
598 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
599 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
600 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
601 fw = 2 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
602 if (inf_or_nan && fw < 4)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
603 fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
604 fmt = float_format (fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
605 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
606 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
607
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
608 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
609 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
610 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
611 else if (! bank_format && int_or_inf_or_nan)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
612 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
613 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
614 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
615
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
616 return float_display_format (scale, fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
617 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
618
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
619 template <typename MT>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
620 static inline float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
621 make_matrix_format (const MT& m)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
622 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
623 assert (m.ndims () == 2);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
624
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
625 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
626 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
627
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
628 bool inf_or_nan = m.any_element_is_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
629
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
630 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
631
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
632 MT m_abs = m.abs ();
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
633
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
634 typedef typename MT::element_type ELT_T;
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
635
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
636 ELT_T max_abs = pr_max_internal (m_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
637 ELT_T min_abs = pr_min_internal (m_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
638
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
639 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
640
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
641 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
642
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
643 return make_real_matrix_format<ELT_T> (x_max, x_min, inf_or_nan,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
644 int_or_inf_or_nan);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
645 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
646
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
647 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
648 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
649 make_format (const Matrix& m)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
650 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
651 return make_matrix_format (m);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
652 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
653
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
654 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
655 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
656 make_format (const FloatMatrix& m)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
657 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
658 return make_matrix_format (m);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
659 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
660
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
661 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
662 static inline float_display_format
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
663 make_complex_format (int x_max, int x_min, int r_x,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
664 bool inf_or_nan, int int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
665 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
666 float_format r_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
667 float_format i_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
668
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
669 int prec = std::min (output_precision (), pr_output_traits<T>::digits10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
670
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
671 int i_fw = 0, r_fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
672
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
673 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
674 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
675 i_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
676 r_fw = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
677 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
678 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
679 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
680 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
681 int digits = r_x;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
682 i_fw = 0;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
683 r_fw = (digits <= 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
684 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
685 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
686 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
687 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
688 r_fw = 2 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
689 i_fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
690 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
691 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
692 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
693 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
694 r_fw = 8 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
695 i_fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
696 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
697 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
698 else if (inf_or_nan || int_only)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
699 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
700 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
701 i_fw = (digits <= 0 ? 1 : digits);
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
702 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
703 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
704 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
705 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
706 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
707 }
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
708
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
709 if (int_only)
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
710 {
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
711 ld = digits;
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
712 rd = 0;
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
713 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
714 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
715 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
716 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
717 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
718 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
719 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
720 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
721 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
722 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
723 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
724 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
725 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
726 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
727 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
728 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
729 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
730
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
731 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
732 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
733 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
734 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
735 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
736 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
737 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
738 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
739 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
740 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
741 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
742 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
743 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
744
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
745 ld = (ld_max > ld_min ? ld_max : ld_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
746 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
747
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
748 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
749 r_fw = i_fw + 1;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
750 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
751
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
752 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
753 && (print_e || print_eng || print_g
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
754 || ld + rd > pr_output_traits<T>::digits10
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
755 || r_fw > pr_output_traits<T>::max_field_width
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
756 || i_fw > pr_output_traits<T>::max_field_width))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
757 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
758 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
759 {
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
760 int width = prec + 6;
27429
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
761 r_fmt = float_format (width, prec);
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
762 i_fmt = float_format (width, prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
763 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
764 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
765 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
766 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
767 if (x_max > 100 || x_min > 100)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
768 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
769
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
770 if (print_eng)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
771 {
21568
3d60ed163b70 maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents: 21547
diff changeset
772 i_fw = 3 + prec + ex;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
773 r_fw = i_fw + 1;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
774 if (inf_or_nan && i_fw < 5)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
775 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
776 i_fw = 5;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
777 r_fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
778 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
779 r_fmt = float_format (r_fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
780 i_fmt = float_format (i_fw, ex, prec - 1, std::ios::fixed);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
781 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
782 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
783 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
784 i_fw = 1 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
785 r_fw = i_fw + 1;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
786 if (inf_or_nan && i_fw < 3)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
787 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
788 i_fw = 3;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
789 r_fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
790 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
791 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
792 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
793 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
794 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
795
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
796 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
797 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
798 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
799 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
800 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
801 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
802 else if (! bank_format && (inf_or_nan || int_only))
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
803 {
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
804 r_fmt = float_format (r_fw, ld);
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
805 i_fmt = float_format (i_fw, ld);
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
806 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
807 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
808 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
809 r_fmt = float_format (r_fw, rd, std::ios::fixed);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
810 i_fmt = float_format (i_fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
811 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
812
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
813 return float_display_format (r_fmt, i_fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
814 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
815
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
816 template <typename T>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
817 float_display_format
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
818 make_complex_scalar_format (const std::complex<T>& c)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
819 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
820 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
821 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
822
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
823 T rp = c.real ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
824 T ip = c.imag ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
825
21782
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
826 bool inf_or_nan = (octave::math::isinf (c) || octave::math::isnan (c));
2aef506f3fec use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
827
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
828 bool int_only = (octave::math::x_nint (rp) == rp
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
829 && octave::math::x_nint (ip) == ip);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
830
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
831 T r_abs = (rp < 0 ? -rp : rp);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
832 T i_abs = (ip < 0 ? -ip : ip);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
833
23564
7049da1648c0 Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents: 23534
diff changeset
834 int r_x = (! octave::math::isfinite (rp)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
835 || r_abs == 0) ? 0 : num_digits (r_abs);
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22323
diff changeset
836
23564
7049da1648c0 Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents: 23534
diff changeset
837 int i_x = (! octave::math::isfinite (ip)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
838 || i_abs == 0) ? 0 : num_digits (i_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
839
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
840 int x_max, x_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
841
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
842 if (r_x > i_x)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
843 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
844 x_max = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
845 x_min = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
846 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
847 else
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
848 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
849 x_max = i_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
850 x_min = r_x;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
851 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
852
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
853 return make_complex_format<T> (x_max, x_min, r_x, inf_or_nan, int_only);
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
854 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
855
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
856 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
857 float_display_format
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
858 make_format (const std::complex<double>& c)
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
859 {
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
860 return make_complex_scalar_format (c);
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
861 }
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
862
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
863 template <>
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
864 float_display_format
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
865 make_format (const std::complex<float>& fc)
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
866 {
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
867 return make_complex_scalar_format (fc);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
868 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
869
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
870 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
871 static inline float_display_format
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
872 make_complex_matrix_format (int x_max, int x_min, int r_x_max,
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
873 int r_x_min, bool inf_or_nan,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
874 int int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
875 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
876 T scale = ((x_max == 0 || int_or_inf_or_nan)
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
877 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1)));
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
878
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
879 float_format r_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
880 float_format i_fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
881
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
882 int prec = std::min (output_precision (), pr_output_traits<T>::digits10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
883
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
884 int i_fw = 0, r_fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
885
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
886 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
887 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
888 i_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
889 r_fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
890 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
891 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
892 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
893 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
894 int digits = (r_x_max > r_x_min ? r_x_max : r_x_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
895 i_fw = 0;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
896 r_fw = (digits <= 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
897 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
898 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
899 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
900 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
901 r_fw = 2 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
902 i_fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
903 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
904 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
905 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
906 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
907 r_fw = 8 * sizeof (T);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
908 i_fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
909 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
910 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
911 else if (Vfixed_point_format && ! print_g)
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
912 {
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
913 rd = prec;
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
914 i_fw = rd + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
915 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
916 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
917 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
918 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
919 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
920 }
3268
fdc7dd08cd85 [project @ 1999-09-10 05:16:49 by jwe]
jwe
parents: 3258
diff changeset
921 }
1715
6f4631c7118c [project @ 1996-01-08 07:57:04 by jwe]
jwe
parents: 1658
diff changeset
922 else if (int_or_inf_or_nan)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
923 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
924 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
925 i_fw = (digits <= 0 ? 1 : digits);
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
926 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
927 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
928 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
929 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
930 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
931 }
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
932 rd = r_fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
933 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
934 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
935 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
936 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
937 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
938 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
939 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
940 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
941 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
942 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
943 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
944 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
945 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
946 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
947 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
948 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
949
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
950 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
951 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
952 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
953 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
954 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
955 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
956 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
957 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
958 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
959 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
960 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
961 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
962 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
963
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
964 ld = (ld_max > ld_min ? ld_max : ld_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
965 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
966
5945
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
967 i_fw = ld + 1 + rd;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
968 r_fw = i_fw + 1;
76cfea89e4e7 [project @ 2006-08-18 22:19:24 by jwe]
jwe
parents: 5832
diff changeset
969 if (inf_or_nan && i_fw < 3)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
970 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
971 i_fw = 3;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
972 r_fw = 4;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
973 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
974 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
975
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
976 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
977 && (print_e || print_eng || print_g
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
978 || (! Vfixed_point_format
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
979 && (ld + rd > pr_output_traits<T>::digits10
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
980 || r_fw > pr_output_traits<T>::max_field_width
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
981 || i_fw > pr_output_traits<T>::max_field_width))))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
982 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
983 if (print_g)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
984 {
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
985 int width = prec + 6;
27429
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
986 r_fmt = float_format (width, prec);
e0134184c1fd Fix regression with display of "format g" (bug #55919).
Rik <rik@octave.org>
parents: 27277
diff changeset
987 i_fmt = float_format (width, prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
988 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
989 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
990 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
991 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
992 if (x_max > 100 || x_min > 100)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
993 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
994
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
995 if (print_eng)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
996 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
997 i_fw = 3 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
998 r_fw = i_fw + 1;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
999 if (inf_or_nan && i_fw < 5)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1000 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1001 i_fw = 5;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1002 r_fw = 6;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1003 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1004 r_fmt = float_format (r_fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1005 i_fmt = float_format (i_fw, ex, prec - 1, std::ios::fixed);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1006 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1007 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1008 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1009 i_fw = 1 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1010 r_fw = i_fw + 1;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1011 if (inf_or_nan && i_fw < 3)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1012 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1013 i_fw = 3;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1014 r_fw = 4;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1015 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1016 r_fmt = float_format (r_fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1017 i_fmt = float_format (i_fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1018 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1019 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1020
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1021 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1022 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1023 r_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1024 i_fmt.uppercase ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1025 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1026 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1027 else if (! bank_format && int_or_inf_or_nan)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1028 {
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1029 r_fmt = float_format (r_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1030 i_fmt = float_format (i_fw, rd);
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1031 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1032 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1033 {
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1034 r_fmt = float_format (r_fw, rd, std::ios::fixed);
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1035 i_fmt = float_format (i_fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1036 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1037
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1038 return float_display_format (scale, r_fmt, i_fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1039 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1040
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1041 template <typename CMT>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1042 static inline float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1043 make_complex_matrix_format (const CMT& cm)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1044 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1045 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1046 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1047
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1048 typedef typename CMT::real_matrix_type RMT;
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1049 typedef typename CMT::real_elt_type ELT_T;
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1050
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1051 RMT rp = real (cm);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1052 RMT ip = imag (cm);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1053
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1054 bool inf_or_nan = cm.any_element_is_inf_or_nan ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1055
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1056 bool int_or_inf_or_nan = (rp.all_elements_are_int_or_inf_or_nan ()
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1057 && ip.all_elements_are_int_or_inf_or_nan ());
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1058
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1059 RMT r_m_abs = rp.abs ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1060 ELT_T r_max_abs = pr_max_internal (r_m_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1061 ELT_T r_min_abs = pr_min_internal (r_m_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1062
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1063 RMT i_m_abs = ip.abs ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1064 ELT_T i_max_abs = pr_max_internal (i_m_abs);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1065 ELT_T i_min_abs = pr_min_internal (i_m_abs);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1066
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1067 int r_x_max = (r_max_abs == 0 ? 0 : num_digits (r_max_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1068
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1069 int r_x_min = (r_min_abs == 0 ? 0 : num_digits (r_min_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1070
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1071 int i_x_max = (i_max_abs == 0 ? 0 : num_digits (i_max_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1072
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1073 int i_x_min = (i_min_abs == 0 ? 0 : num_digits (i_min_abs));
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1074
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1075 int x_max = (r_x_max > i_x_max ? r_x_max : i_x_max);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1076 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1077
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1078 return make_complex_matrix_format<ELT_T> (x_max, x_min, r_x_max, r_x_min,
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1079 inf_or_nan, int_or_inf_or_nan);
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1080 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1081
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1082 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1083 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1084 make_format (const ComplexMatrix& cm)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1085 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1086 return make_complex_matrix_format (cm);
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1087 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1088
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1089 template <>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1090 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1091 make_format (const FloatComplexMatrix& cm)
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1092 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1093 return make_complex_matrix_format (cm);
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1094 }
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1095
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1096 template <>
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1097 float_display_format
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1098 make_format (const boolNDArray&)
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1099 {
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1100 return float_display_format (float_format (1, 1));
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1101 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1102
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1103 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1104 static inline float_display_format
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1105 make_range_format (int x_max, int x_min, int all_ints)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1106 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1107 double scale = ((x_max == 0 || all_ints)
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1108 ? 1 : std::pow (10.0, calc_scale_exp (x_max - 1)));
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1109
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1110 float_format fmt;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1111
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1112 int prec = std::min (output_precision (), pr_output_traits<T>::digits10);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1113
24789
a4d4ec566fd7 improve formatting of large values in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24788
diff changeset
1114 int fw = 0, ld = 0, rd = 0;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1115
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1116 if (rat_format)
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1117 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1118 fw = 9;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1119 rd = 0;
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1120 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1121 else if (bank_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1122 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1123 int digits = (x_max > x_min ? x_max : x_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1124 fw = (digits < 0 ? 5 : digits + 4);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1125 rd = 2;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1126 }
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1127 else if (hex_format)
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1128 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1129 fw = 2 * sizeof (T);
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1130 rd = 0;
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1131 }
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1132 else if (bit_format)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1133 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1134 fw = 8 * sizeof (T);
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1135 rd = 0;
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1136 }
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1137 else if (all_ints)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1138 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1139 int digits = (x_max > x_min ? x_max : x_min);
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1140 fw = digits + 1;
3682
19e1ac7359fb [project @ 2000-06-27 03:23:10 by jwe]
jwe
parents: 3611
diff changeset
1141 rd = fw;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1142 }
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1143 else if (Vfixed_point_format && ! print_g)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1144 {
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1145 rd = prec;
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1146 fw = rd + 3;
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1147 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1148 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1149 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1150 int ld_max, rd_max;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1151 if (x_max > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1152 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1153 ld_max = x_max;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1154 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1155 x_max++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1156 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1157 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1158 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1159 ld_max = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1160 rd_max = (prec > x_max ? prec - x_max : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1161 x_max = -x_max + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1162 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1163
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1164 int ld_min, rd_min;
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1165 if (x_min > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1166 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1167 ld_min = x_min;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1168 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1169 x_min++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1170 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1171 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1172 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1173 ld_min = 1;
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1174 rd_min = (prec > x_min ? prec - x_min : prec);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1175 x_min = -x_min + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1176 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1177
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1178 ld = (ld_max > ld_min ? ld_max : ld_min);
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1179 rd = (rd_max > rd_min ? rd_max : rd_min);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1180
7465
8d6ab12f8fda format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents: 7231
diff changeset
1181 fw = ld + rd + 3;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1182 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1183
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
1184 if (! (rat_format || bank_format || hex_format || bit_format)
24785
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
1185 && (print_e || print_eng || print_g
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
1186 || (! Vfixed_point_format
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
1187 && (ld + rd > pr_output_traits<T>::digits10
504869574c89 restore auto switch to E formats octave_print_internal functions
John W. Eaton <jwe@octave.org>
parents: 24784
diff changeset
1188 || fw > pr_output_traits<T>::max_field_width))))
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1189 {
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1190 if (print_g)
27439
251056aeba5d Align negative numbers correctly with g format (bug #56940).
Rik <rik@octave.org>
parents: 27434
diff changeset
1191 fmt = float_format (prec+6, prec);
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
1192 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1193 {
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1194 int ex = 4;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1195 if (x_max > 100 || x_min > 100)
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1196 ex++;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1197
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1198 if (print_eng)
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1199 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1200 fw = 5 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1201 fmt = float_format (fw, ex, prec - 1, std::ios::fixed);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1202 }
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1203 else
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1204 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1205 fw = 3 + prec + ex;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1206 fmt = float_format (fw, prec - 1, std::ios::scientific);
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
1207 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1208 }
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1209
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1210 if (print_big_e)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1211 fmt.uppercase ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1212 }
5086
55f5b61d74b7 [project @ 2004-11-19 21:50:50 by jwe]
jwe
parents: 5030
diff changeset
1213 else if (! bank_format && all_ints)
3611
b1ff6597576f [project @ 2000-03-17 09:44:29 by jwe]
jwe
parents: 3608
diff changeset
1214 fmt = float_format (fw, rd);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1215 else
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1216 fmt = float_format (fw, rd, std::ios::fixed);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1217
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1218 return float_display_format (scale, fmt);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1219 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1220
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1221 template <>
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1222 float_display_format
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1223 make_format (const Range& r)
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1224 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1225 if (free_format)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1226 return float_display_format ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1227
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1228 double r_min = r.base ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1229 double r_max = r.limit ();
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1230
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1231 if (r_max < r_min)
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1232 {
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1233 double tmp = r_max;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1234 r_max = r_min;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1235 r_min = tmp;
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1236 }
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1237
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
1238 bool all_ints = r.all_elements_are_ints ();
1658
0e9cd25503d9 [project @ 1995-12-20 16:49:05 by jwe]
jwe
parents: 1651
diff changeset
1239
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1240 double max_abs = (r_max < 0 ? -r_max : r_max);
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1241 double min_abs = (r_min < 0 ? -r_min : r_min);
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1242
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1243 int x_max = (max_abs == 0 ? 0 : num_digits (max_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1244
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1245 int x_min = (min_abs == 0 ? 0 : num_digits (min_abs));
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1246
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1247 return make_range_format<double> (x_max, x_min, all_ints);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1248 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1249
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1250 template <typename T>
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1251 union equiv
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1252 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1253 T val;
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1254 unsigned char i[sizeof (T)];
1282
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1255 };
dac3c9c58b1a [project @ 1995-04-27 19:27:40 by jwe]
jwe
parents: 1192
diff changeset
1256
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1257 #define PRINT_CHAR_BITS(os, c) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1258 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1259 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1260 unsigned char ctmp = c; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1261 char stmp[9]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1262 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1263 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1264 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1265 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1266 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1267 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1268 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1269 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1270 stmp[8] = '\0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1271 os << stmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1272 } \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1273 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1274
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1275 #define PRINT_CHAR_BITS_SWAPPED(os, c) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1276 do \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1277 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1278 unsigned char ctmp = c; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1279 char stmp[9]; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1280 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1281 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1282 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1283 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1284 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1285 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1286 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1287 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1288 stmp[8] = '\0'; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1289 os << stmp; \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
1290 } \
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1291 while (0)
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
1292
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1293 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1294 static inline void
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1295 pr_any_float (std::ostream& os, const float_format& fmt, T val)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1296 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1297 // Unless explicitly asked for, always print in big-endian format
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1298 // for hex and bit formats.
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1299 //
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1300 // {bit,hex}_format == 1: print big-endian
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1301 // {bit,hex}_format == 2: print native
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1302
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
1303 int fw = fmt.width ();
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1304
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1305 if (hex_format)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1306 {
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1307 octave::preserve_stream_state stream_state (os);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1308
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1309 equiv<T> tmp;
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1310 tmp.val = val;
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1311
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1312 // Unless explicitly asked for, always print in big-endian format.
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1313
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1314 // FIXME: will bad things happen if we are
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1315 // interrupted before resetting the format flags and fill
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1316 // character?
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1317
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27183
diff changeset
1318 octave::mach_info::float_format flt_fmt
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27183
diff changeset
1319 = octave::mach_info::native_float_format ();
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1320
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1321 os.fill ('0');
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1322 os.flags (std::ios::right | std::ios::hex);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1323
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1324 if (hex_format > 1
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1325 || flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1326 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1327 for (size_t i = 0; i < sizeof (T); i++)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1328 os << std::setw (2) << static_cast<int> (tmp.i[i]);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1329 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1330 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1331 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1332 for (int i = sizeof (T) - 1; i >= 0; i--)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1333 os << std::setw (2) << static_cast<int> (tmp.i[i]);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1334 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1335 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1336 else if (bit_format)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1337 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1338 equiv<T> tmp;
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1339 tmp.val = val;
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1340
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27183
diff changeset
1341 octave::mach_info::float_format flt_fmt
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27183
diff changeset
1342 = octave::mach_info::native_float_format ();
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1343
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1344 if (flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1345 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1346 for (size_t i = 0; i < sizeof (T); i++)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1347 PRINT_CHAR_BITS (os, tmp.i[i]);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1348 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1349 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1350 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1351 if (bit_format > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1352 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1353 for (size_t i = 0; i < sizeof (T); i++)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1354 PRINT_CHAR_BITS_SWAPPED (os, tmp.i[i]);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1355 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1356 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1357 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1358 for (int i = sizeof (T) - 1; i >= 0; i--)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1359 PRINT_CHAR_BITS (os, tmp.i[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1360 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1361 }
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1362 }
27433
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1363 else if (val == 0)
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1364 {
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1365 octave::preserve_stream_state stream_state (os);
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1366
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1367 if (fw > 0)
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1368 os << std::setw (fw) << "0";
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1369 else
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1370 os << "0";
fc7504df6a12 Display "0" for true zeros rather than "0.0000" (bug #53083).
Rik <rik@octave.org>
parents: 27430
diff changeset
1371 }
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1372 else if (octave::math::isna (val))
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1373 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1374 octave::preserve_stream_state stream_state (os);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1375
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1376 if (fw > 0)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1377 os << std::setw (fw) << "NA";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1378 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1379 os << "NA";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1380 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1381 else if (rat_format)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1382 os << pr_rational_float<T> (fmt, val);
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1383 else if (octave::math::isinf (val))
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1384 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1385 octave::preserve_stream_state stream_state (os);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1386
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1387 const char *s;
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1388 if (val < 0)
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1389 s = "-Inf";
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1390 else
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1391 s = "Inf";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1392
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1393 if (fw > 0)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1394 os << std::setw (fw) << s;
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1395 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1396 os << s;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1397 }
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1398 else if (octave::math::isnan (val))
24667
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1399 {
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1400 octave::preserve_stream_state stream_state (os);
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1401
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1402 if (fw > 0)
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1403 os << std::setw (fw) << "NaN";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1404 else
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1405 os << "NaN";
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1406 }
56f889d66b7c move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
1407 else if (print_eng)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1408 os << pr_engineering_float<T> (fmt, val);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
1409 else
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1410 os << pr_formatted_float<T> (fmt, val);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1411 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1412
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1413 template <typename T>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1414 static inline void
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1415 pr_float (std::ostream& os, const float_display_format& fmt, T val)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1416 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1417 double scale = fmt.scale_factor ();
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1418
27434
57f5c5768eb3 Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents: 27433
diff changeset
1419 if (Vfixed_point_format && ! (print_g || print_e) && scale != 1)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1420 val /= scale;
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1421
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1422 pr_any_float (os, fmt.real_format (), val);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1423 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1424
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1425 template <typename T>
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1426 static inline void
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1427 pr_imag_float (std::ostream& os, const float_display_format& fmt, T val)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1428 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1429 pr_any_float (os, fmt.imag_format (), val);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1430 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1431
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1432 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1433 static inline void
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1434 pr_float (std::ostream& os, const float_display_format& fmt,
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1435 const std::complex<T>& cval)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1436 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1437 // FIXME: should we range check this value? It is stored as a double
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1438 // to simplify the implementation, but should always correspond to the
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1439 // type of value we are displaying.
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1440
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1441 double dscale = fmt.scale_factor ();
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1442 T scale = static_cast<T> (dscale);
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1443
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1444 std::complex<T> tmp
27434
57f5c5768eb3 Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents: 27433
diff changeset
1445 = ((Vfixed_point_format && ! (print_g || print_e) && scale != 1)
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1446 ? cval / scale : cval);
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1447
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1448 T r = tmp.real ();
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1449
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1450 pr_float (os, fmt, r);
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
1451
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1452 if (! bank_format)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1453 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1454 T i = tmp.imag ();
4349
a6c22c2c9b09 [project @ 2003-02-21 18:59:07 by jwe]
jwe
parents: 4270
diff changeset
1455 if (! (hex_format || bit_format) && lo_ieee_signbit (i))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1456 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1457 os << " - ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1458 i = -i;
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1459 pr_imag_float (os, fmt, i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1460 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1461 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1462 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1463 if (hex_format || bit_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1464 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1465 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1466 os << " + ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1467
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1468 pr_imag_float (os, fmt, i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1469 }
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1470 os << 'i';
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1471 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1472 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1473
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1474 static inline void
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1475 print_empty_matrix (std::ostream& os, octave_idx_type nr, octave_idx_type nc,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1476 bool pr_as_read_syntax)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1477 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1478 assert (nr == 0 || nc == 0);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1479
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1480 if (pr_as_read_syntax)
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1481 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1482 if (nr == 0 && nc == 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1483 os << "[]";
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1484 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1485 os << "zeros (" << nr << ", " << nc << ')';
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1486 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1487 else
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1488 {
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1489 os << "[]";
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1490
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1491 if (Vprint_empty_dimensions)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1492 os << '(' << nr << 'x' << nc << ')';
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1493 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1494 }
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1495
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1496 static inline void
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1497 print_empty_nd_array (std::ostream& os, const dim_vector& dims,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1498 bool pr_as_read_syntax)
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1499 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1500 assert (dims.any_zero ());
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1501
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1502 if (pr_as_read_syntax)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1503 os << "zeros (" << dims.str (',') << ')';
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1504 else
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1505 {
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1506 os << "[]";
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1507
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1508 if (Vprint_empty_dimensions)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1509 os << '(' << dims.str () << ')';
4559
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1510 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1511 }
802818bfac91 [project @ 2003-10-28 19:13:43 by jwe]
jwe
parents: 4532
diff changeset
1512
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1513 static inline void
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1514 pr_scale_header (std::ostream& os, double scale)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1515 {
27434
57f5c5768eb3 Disallow exponential format in combination with fixed_point_format.
Rik <rik@octave.org>
parents: 27433
diff changeset
1516 if (Vfixed_point_format && ! (print_g || print_e) && scale != 1)
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1517 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1518 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1519
3568
58549b931ad5 [project @ 2000-02-03 10:21:54 by jwe]
jwe
parents: 3548
diff changeset
1520 os << " "
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1521 << std::setw (8) << std::setprecision (1)
21662
5b9868c2e212 maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents: 21583
diff changeset
1522 << std::setiosflags (std::ios::scientific | std::ios::left)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1523 << scale
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
1524 << "*\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1525
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1526 if (! Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1527 os << "\n";
3105
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1528 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1529 }
f936c7f5074f [project @ 1997-11-19 04:36:17 by jwe]
jwe
parents: 3018
diff changeset
1530
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1531 static inline void
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1532 pr_col_num_header (std::ostream& os, octave_idx_type total_width, int max_width,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1533 octave_idx_type lim, octave_idx_type col, int extra_indent)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1534 {
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1535 if (total_width > max_width && Vsplit_long_rows)
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1536 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1537 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1538
4833
399e8681b774 [project @ 2004-03-10 20:49:48 by jwe]
jwe
parents: 4791
diff changeset
1539 if (col != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1540 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1541 if (Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1542 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1543 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1544 os << "\n\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1545 }
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1546
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1547 octave_idx_type num_cols = lim - col;
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1548
3548
ab7fa5a8f23f [project @ 2000-02-03 01:17:15 by jwe]
jwe
parents: 3538
diff changeset
1549 os << std::setw (extra_indent) << "";
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1550
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1551 if (num_cols == 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1552 os << " Column " << col + 1 << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1553 else if (num_cols == 2)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1554 os << " Columns " << col + 1 << " and " << lim << ":\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1555 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1556 os << " Columns " << col + 1 << " through " << lim << ":\n";
2915
649549662cf6 [project @ 1997-04-30 20:51:40 by jwe]
jwe
parents: 2907
diff changeset
1557
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1558 if (! Vcompact_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1559 os << "\n";
1186
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1560 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1561 }
d94bcafabac2 [project @ 1995-03-30 04:57:32 by jwe]
jwe
parents: 1086
diff changeset
1562
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
1563 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1564 static inline void
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1565 pr_plus_format (std::ostream& os, const T& val)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1566 {
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1567 if (val > T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1568 os << plus_format_chars[0];
5030
160365410ad4 [project @ 2004-09-24 03:22:23 by jwe]
jwe
parents: 4949
diff changeset
1569 else if (val < T (0))
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1570 os << plus_format_chars[1];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1571 else
4632
0e28461651f2 [project @ 2003-11-18 19:07:13 by jwe]
jwe
parents: 4574
diff changeset
1572 os << plus_format_chars[2];
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1573 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
1574
24747
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1575 // FIXME: all this mess with abs is an attempt to avoid seeing
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1576 //
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1577 // warning: comparison of unsigned expression < 0 is always false
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1578 //
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1579 // from GCC. Isn't there a better way?
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1580
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1581 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1582 static inline T
24747
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1583 abs (T x)
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1584 {
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1585 return x < 0 ? -x : x;
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1586 }
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1587
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1588 #define INSTANTIATE_ABS(T) \
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1589 template T abs (T)
24747
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1590
25569
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1591 INSTANTIATE_ABS(int8_t);
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1592 INSTANTIATE_ABS(int16_t);
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1593 INSTANTIATE_ABS(int32_t);
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1594 INSTANTIATE_ABS(int64_t);
24747
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1595
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1596 #define SPECIALIZE_UABS(T) \
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1597 template <> \
25569
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1598 inline T \
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1599 abs (T x) \
24747
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1600 { \
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1601 return x; \
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1602 }
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1603
25569
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1604 SPECIALIZE_UABS(uint8_t)
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1605 SPECIALIZE_UABS(uint16_t)
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1606 SPECIALIZE_UABS(uint32_t)
e8961d677661 build: avoid compiler warning about unused function 'abs' (bug #54237)
Mike Miller <mtmiller@octave.org>
parents: 25108
diff changeset
1607 SPECIALIZE_UABS(uint64_t)
24747
6114be517240 * pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents: 24745
diff changeset
1608
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1609 #define MAKE_INT_MATRIX_FORMAT(TYPE) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1610 template <> \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1611 float_display_format \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1612 make_format (const intNDArray<TYPE>& nda) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1613 { \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1614 bool isneg = false; \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1615 int digits = 0; \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1616 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1617 for (octave_idx_type i = 0; i < nda.numel (); i++) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1618 { \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1619 int new_digits \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1620 = static_cast<int> \
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1621 (std::floor (log10 (double (abs (nda(i).value ()))) + 1)); \
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1622 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1623 if (new_digits > digits) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1624 digits = new_digits; \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1625 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1626 if (! isneg) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1627 isneg = (abs (nda(i).value ()) != nda(i).value ()); \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1628 } \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1629 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1630 return float_display_format (float_format (digits + isneg, 0, 0)); \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1631 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1632
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1633 MAKE_INT_MATRIX_FORMAT (octave_int8)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1634 MAKE_INT_MATRIX_FORMAT (octave_uint8)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1635 MAKE_INT_MATRIX_FORMAT (octave_int16)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1636 MAKE_INT_MATRIX_FORMAT (octave_uint16)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1637 MAKE_INT_MATRIX_FORMAT (octave_int32)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1638 MAKE_INT_MATRIX_FORMAT (octave_uint32)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1639 MAKE_INT_MATRIX_FORMAT (octave_int64)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1640 MAKE_INT_MATRIX_FORMAT (octave_uint64)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1641
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1642 #define MAKE_INT_SCALAR_FORMAT(TYPE) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1643 template <> \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1644 float_display_format \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1645 make_format (const octave_int<TYPE>& val) \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1646 { \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1647 bool isneg = false; \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1648 int digits \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1649 = static_cast<int> \
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
1650 (std::floor (log10 (double (abs (val.value ()))) + 1)); \
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1651 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1652 isneg = (abs (val.value ()) != val.value ()); \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1653 \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1654 return float_display_format (float_format (digits + isneg, 0, 0)); \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1655 }
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1656
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1657 MAKE_INT_SCALAR_FORMAT (int8_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1658 MAKE_INT_SCALAR_FORMAT (uint8_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1659 MAKE_INT_SCALAR_FORMAT (int16_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1660 MAKE_INT_SCALAR_FORMAT (uint16_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1661 MAKE_INT_SCALAR_FORMAT (int32_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1662 MAKE_INT_SCALAR_FORMAT (uint32_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1663 MAKE_INT_SCALAR_FORMAT (int64_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1664 MAKE_INT_SCALAR_FORMAT (uint64_t)
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
1665
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1666 void
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1667 octave_print_internal (std::ostream& os, const float_display_format& fmt,
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1668 bool d, bool pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1669 {
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1670 octave_print_internal (os, fmt, octave_uint8 (d), pr_as_read_syntax);
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1671 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1672
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1673 void
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1674 octave_print_internal (std::ostream& os, bool d, bool pr_as_read_syntax)
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1675 {
24760
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1676 octave_print_internal (os, octave_uint8 (d), pr_as_read_syntax);
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1677 }
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1678
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1679 void
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1680 octave_print_internal (std::ostream&, const float_display_format&,
b784d68f7c44 fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents: 24747
diff changeset
1681 char, bool)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1682 {
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1683 panic_impossible ();
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1684 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1685
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1686 void
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
1687 octave_print_internal (std::ostream& os, const float_display_format& fmt,
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
1688 double d, bool pr_as_read_syntax)
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1689 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1690 if (pr_as_read_syntax)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1691 os << d;
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1692 else if (plus_format)
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
1693 pr_plus_format (os, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1694 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1695 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1696 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1697 os << d;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1698 else
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
1699 pr_float (os, fmt, d);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1700 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1701 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1702
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1703 void
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1704 octave_print_internal (std::ostream& os, const float_display_format& fmt,
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1705 float d, bool pr_as_read_syntax)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1706 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1707 if (pr_as_read_syntax)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1708 os << d;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1709 else if (plus_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1710 pr_plus_format (os, d);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1711 else
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1712 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1713 if (free_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1714 os << d;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1715 else
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1716 pr_float (os, fmt, d);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1717 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1718 }
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1719
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1720 template <typename MT>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
1721 static inline void
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1722 octave_print_free (std::ostream& os, const MT& m, bool pr_as_read_syntax)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1723 {
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1724 octave_idx_type nr = m.rows ();
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1725 octave_idx_type nc = m.columns ();
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1726
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1727 if (pr_as_read_syntax)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1728 os << "[\n";
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1729
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1730 for (octave_idx_type i = 0; i < nr; i++)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1731 {
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1732 for (octave_idx_type j = 0; j < nc; j++)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1733 os << ' ' << m.elem(i,j);
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1734
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1735 if (i < nr - 1)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1736 os << "\n";
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1737 }
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1738
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1739 if (pr_as_read_syntax)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1740 os << ']';
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1741 }
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1742
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1743 template <typename MT>
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1744 static inline void
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1745 pr_plus_format_matrix (std::ostream& os, const MT& m)
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1746 {
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1747 octave_idx_type nr = m.rows ();
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1748 octave_idx_type nc = m.columns ();
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1749
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1750 for (octave_idx_type i = 0; i < nr; i++)
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1751 {
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1752 for (octave_idx_type j = 0; j < nc; j++)
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1753 {
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1754 octave_quit ();
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1755
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1756 pr_plus_format (os, m(i,j));
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1757 }
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1758
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1759 if (i < nr - 1)
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1760 os << "\n";
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1761 }
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1762 }
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1763
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1764 static inline int
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1765 get_column_width (const float_display_format& fmt)
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1766 {
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
1767 int r_fw = fmt.real_format().width ();
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
1768 int i_fw = fmt.imag_format().width ();
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1769
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1770 int retval = r_fw + i_fw + 2;
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1771
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1772 if (i_fw && ! (rat_format || bank_format || hex_format || bit_format))
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1773 retval += 5;
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1774
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1775 return retval;
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1776 }
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1777
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1778 template <typename MT>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1779 static void
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1780 octave_print_matrix_internal (std::ostream& os, const MT& m,
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1781 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1782 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1783 octave_idx_type nr = m.rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1784 octave_idx_type nc = m.columns ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1785
2408
e22aae3ccfad [project @ 1996-10-15 16:37:52 by jwe]
jwe
parents: 2387
diff changeset
1786 if (nr == 0 || nc == 0)
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1787 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1788 else if (plus_format && ! pr_as_read_syntax)
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1789 pr_plus_format_matrix (os, m);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1790 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1791 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1792 float_display_format fmt = make_format (m);
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1793 int column_width = get_column_width (fmt);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1794 octave_idx_type total_width = nc * column_width;
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21747
diff changeset
1795 octave_idx_type max_width = octave::command_editor::terminal_cols ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1796
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1797 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1798 max_width -= 4;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1799 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1800 max_width -= extra_indent;
1972
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1801
58ac5f889c64 [project @ 1996-02-24 07:12:58 by jwe]
jwe
parents: 1968
diff changeset
1802 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1803 max_width = 0;
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1804
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1805 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1806 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1807 octave_print_free (os, m, pr_as_read_syntax);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1808 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1809 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1810
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
1811 octave_idx_type inc = nc;
2165
83d91aa3759b [project @ 1996-05-13 13:28:10 by jwe]
jwe
parents: 2086
diff changeset
1812 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1813 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1814 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1815 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1816 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1817 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1818
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1819 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1820 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1821 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1822 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1823 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1824 while (col < nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1825 {
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
1826 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1827
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1828 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1829 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1830 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1831
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1832 if (i == 0 && j == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1833 os << "[ ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1834 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1835 {
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
1836 if (j > col)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1837 os << ", ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1838 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1839 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1840 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1841
24761
d7c3918955e6 eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents: 24760
diff changeset
1842 pr_float (os, fmt, m(i,j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1843 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1844
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1845 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1846
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1847 if (col >= nc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1848 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1849 if (i == nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1850 os << " ]";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1851 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1852 os << ";\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1853 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1854 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1855 os << " ...\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1856 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1857 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1858 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
1859 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1860 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1861 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1862
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1863 pr_scale_header (os, fmt.scale_factor ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1864
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1865 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1866 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
1867 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1868
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1869 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1870 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1871
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1872 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1873 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1874 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1875
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1876 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1877 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1878 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1879
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1880 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1881
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1882 pr_float (os, fmt, m(i,j));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1883 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1884
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1885 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1886 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1887 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1888 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1889 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1890 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1891 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1892
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1893 template <typename DMT>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1894 static void
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1895 octave_print_diag_matrix_internal (std::ostream& os, const DMT& m,
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1896 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1897 {
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1898 octave_idx_type nr = m.rows ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1899 octave_idx_type nc = m.columns ();
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1900
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1901 if (nr == 0 || nc == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1902 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1903 else if (plus_format && ! pr_as_read_syntax)
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
1904 pr_plus_format_matrix (os, m);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1905 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1906 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
1907 float_display_format fmt
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1908 = make_format (typename DMT::full_matrix_type (m.diag ()));
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
1909 int column_width = get_column_width (fmt);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1910 octave_idx_type total_width = nc * column_width;
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21747
diff changeset
1911 octave_idx_type max_width = octave::command_editor::terminal_cols ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1912
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1913 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1914 max_width -= 4;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1915 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1916 max_width -= extra_indent;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1917
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1918 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1919 max_width = 0;
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1920
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1921 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1922 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
1923 octave_print_free (os, m, pr_as_read_syntax);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1924 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1925 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1926
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1927 octave_idx_type inc = nc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1928 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1929 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1930 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1931 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1932 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1933 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1934
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1935 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1936 {
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1937 os << "diag (";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1938
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1939 octave_idx_type col = 0;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1940 while (col < nc)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1941 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
1942 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1943
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1944 for (octave_idx_type j = col; j < lim; j++)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1945 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
1946 octave_quit ();
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1947
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1948 if (j == 0)
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1949 os << "[ ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1950 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1951 {
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
1952 if (j > col)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1953 os << ", ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1954 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1955 os << " ";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1956 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1957
24761
d7c3918955e6 eliminate file-scope static variable in pr-output.cc
John W. Eaton <jwe@octave.org>
parents: 24760
diff changeset
1958 pr_float (os, fmt, m(j,j));
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1959 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1960
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1961 col += inc;
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1962
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1963 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1964 os << " ]";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1965 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1966 os << " ...\n";
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1967 }
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
1968 os << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1969 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1970 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1971 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
1972 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1973
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1974 os << "Diagonal Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1975 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1976 os << "\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
1977
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1978 pr_scale_header (os, fmt.scale_factor ());
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1979
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21748
diff changeset
1980 // kluge. Get the true width of a number.
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1981 int zero_fw;
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1982 {
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1983 std::ostringstream tmp_oss;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
1984 typename DMT::element_type zero = 0;
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
1985 pr_float (tmp_oss, fmt, zero);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1986 zero_fw = tmp_oss.str ().length ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1987 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
1988
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1989 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1990 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
1991 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1992
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1993 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1994 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1995
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1996 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1997 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1998 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
1999
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2000 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2001 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2002 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2003
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2004 os << " ";
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2005
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2006 if (i == j)
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2007 pr_float (os, fmt, m(i,j));
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2008 else
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2009 os << std::setw (zero_fw) << '0';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2010 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2011
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2012 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2013 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2014 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2015 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2016 }
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2017 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2018 }
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2019
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2020 template <typename NDA_T, typename ELT_T, typename MAT_T>
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
2021 void print_nd_array (std::ostream& os, const NDA_T& nda,
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
2022 bool pr_as_read_syntax)
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2023 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2024
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
2025 if (nda.isempty ())
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2026 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2027 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2028 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2029
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2030 int ndims = nda.ndims ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2031
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2032 dim_vector dims = nda.dims ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2033
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2034 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2035
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2036 octave_idx_type m = 1;
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2037
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2038 for (int i = 2; i < ndims; i++)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2039 m *= dims(i);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2040
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2041 octave_idx_type nr = dims(0);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2042 octave_idx_type nc = dims(1);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2043
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2044 for (octave_idx_type i = 0; i < m; i++)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2045 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2046 octave_quit ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2047
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2048 std::string nm = "ans";
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2049
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2050 if (m > 1)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2051 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2052 nm += "(:,:,";
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2053
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2054 std::ostringstream buf;
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2055
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2056 for (int k = 2; k < ndims; k++)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2057 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2058 buf << ra_idx(k) + 1;
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2059
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2060 if (k < ndims - 1)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2061 buf << ',';
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2062 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2063 buf << ')';
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2064 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2065
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2066 nm += buf.str ();
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2067 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2068
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2069 Array<idx_vector> idx (dim_vector (ndims, 1));
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2070
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2071 idx(0) = idx_vector (':');
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2072 idx(1) = idx_vector (':');
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2073
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2074 for (int k = 2; k < ndims; k++)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2075 idx(k) = idx_vector (ra_idx(k));
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2076
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2077 octave_value page
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2078 = MAT_T (Array<ELT_T> (nda.index (idx), dim_vector (nr, nc)));
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2079
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2080 if (i != m - 1)
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2081 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2082 page.print_with_name (os, nm);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2083 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2084 else
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2085 {
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2086 page.print_name_tag (os, nm);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2087 page.print_raw (os);
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2088 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2089
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2090 NDA_T::increment_index (ra_idx, dims, 2);
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2091 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2092 }
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2093 }
4532
01ee68d18069 [project @ 2003-10-10 00:49:54 by jwe]
jwe
parents: 4513
diff changeset
2094
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2095 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2096 octave_print_internal (std::ostream& os, const NDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2097 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2098 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2099 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2100 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2101 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2102 case 2:
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19318
diff changeset
2103 octave_print_internal (os, Matrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2104 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2105 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2106
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2107 default:
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2108 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2109 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2110 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2111 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2112
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2113 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2114 octave_print_internal (std::ostream& os, const FloatNDArray& nda,
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2115 bool pr_as_read_syntax, int extra_indent)
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2116 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2117 switch (nda.ndims ())
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2118 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2119 case 1:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2120 case 2:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2121 octave_print_internal (os, FloatMatrix (nda),
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2122 pr_as_read_syntax, extra_indent);
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2123 break;
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2124
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2125 default:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2126 print_nd_array <FloatNDArray, float, FloatMatrix> (os, nda, pr_as_read_syntax);
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2127 break;
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2128 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2129 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2130
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2131 template <typename T>
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2132 static inline void
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2133 pr_plus_format (std::ostream& os, const std::complex<T>& c)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2134 {
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2135 T rp = c.real ();
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2136 T ip = c.imag ();
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2137
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
2138 if (rp == 0)
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2139 {
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
2140 if (ip == 0)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2141 os << ' ';
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2142 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2143 os << 'i';
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2144 }
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
2145 else if (ip == 0)
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
2146 pr_plus_format (os, rp);
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2147 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2148 os << 'c';
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2149 }
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3215
diff changeset
2150
24668
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
2151 extern void
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
2152 octave_print_internal (std::ostream& os, const float_display_format& fmt,
d4dd741b2794 new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents: 24667
diff changeset
2153 const Complex& c, bool pr_as_read_syntax)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2154 {
17867
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2155 if (pr_as_read_syntax)
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2156 os << c;
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2157 else if (plus_format)
49d573a1deda avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents: 17866
diff changeset
2158 pr_plus_format (os, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2159 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2160 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2161 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2162 os << c;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2163 else
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2164 pr_float (os, fmt, c);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2165 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2166 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2167
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2168 void
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2169 octave_print_internal (std::ostream& os, const float_display_format& fmt,
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2170 const FloatComplex& c, bool pr_as_read_syntax)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2171 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2172 if (pr_as_read_syntax)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2173 os << c;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2174 else if (plus_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2175 pr_plus_format (os, c);
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2176 else
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2177 {
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2178 if (free_format)
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2179 os << c;
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2180 else
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2181 pr_float (os, fmt, c);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2182 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2183 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2184
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2185 void
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2186 octave_print_internal (std::ostream& os, const PermMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2187 bool pr_as_read_syntax, int extra_indent)
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2188 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2189 octave_idx_type nr = m.rows ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2190 octave_idx_type nc = m.columns ();
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2191
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2192 if (nr == 0 || nc == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2193 print_empty_matrix (os, nr, nc, pr_as_read_syntax);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2194 else if (plus_format && ! pr_as_read_syntax)
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
2195 pr_plus_format_matrix (os, m);
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2196 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2197 {
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2198 int fw = 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2199 int column_width = fw + 2;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2200 octave_idx_type total_width = nc * column_width;
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21747
diff changeset
2201 octave_idx_type max_width = octave::command_editor::terminal_cols ();
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2202
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2203 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2204 max_width -= 4;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2205 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2206 max_width -= extra_indent;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2207
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2208 if (max_width < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2209 max_width = 0;
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2210
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2211 if (free_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2212 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2213 octave_print_free (os, m, pr_as_read_syntax);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2214 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2215 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2216
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2217 octave_idx_type inc = nc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2218 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2219 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2220 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2221 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2222 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2223 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2224
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2225 if (pr_as_read_syntax)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2226 {
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18816
diff changeset
2227 Array<octave_idx_type> pvec = m.col_perm_vec ();
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2228
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2229 os << "eye (";
18849
aa9ca67f09fb make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents: 18816
diff changeset
2230 os << ":, ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2231
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2232 octave_idx_type col = 0;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2233 while (col < nc)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2234 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2235 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2236
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2237 for (octave_idx_type j = col; j < lim; j++)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2238 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 10066
diff changeset
2239 octave_quit ();
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2240
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2241 if (j == 0)
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2242 os << "[ ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2243 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2244 {
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2245 if (j > col)
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2246 os << ", ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2247 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2248 os << " ";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2249 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2250
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2251 os << pvec (j);
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2252 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2253
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2254 col += inc;
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2255
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2256 if (col >= nc)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2257 os << " ]";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2258 else
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2259 os << " ...\n";
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2260 }
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2261 os << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2262 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2263 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2264 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2265 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2266
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2267 os << "Permutation Matrix\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2268 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2269 os << "\n";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2270
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2271 for (octave_idx_type col = 0; col < nc; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2272 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2273 octave_idx_type lim = (col + inc < nc ? col + inc : nc);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2274
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2275 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2276 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2277
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2278 for (octave_idx_type i = 0; i < nr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2279 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2280 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2281
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2282 for (octave_idx_type j = col; j < lim; j++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2283 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2284 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2285
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2286 os << " ";
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2287
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2288 os << std::setw (fw) << m(i,j);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2289 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2290
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2291 if (i < nr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2292 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2293 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2294 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2295 }
8891
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2296 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2297 }
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2298
d077c590eb88 indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents: 8746
diff changeset
2299 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2300 octave_print_internal (std::ostream& os, const ComplexNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2301 bool pr_as_read_syntax, int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2302 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2303 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2304 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2305 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2306 case 2:
19320
d0c73e23a505 Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents: 19318
diff changeset
2307 octave_print_internal (os, ComplexMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2308 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2309 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2310
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2311 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2312 print_nd_array <ComplexNDArray, Complex, ComplexMatrix>
19861
19755f4fc851 maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
2313 (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2314 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2315 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2316 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2317
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2318 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2319 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda,
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2320 bool pr_as_read_syntax, int extra_indent)
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2321 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2322 switch (nda.ndims ())
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2323 {
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2324 case 1:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2325 case 2:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2326 octave_print_internal (os, FloatComplexMatrix (nda),
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2327 pr_as_read_syntax, extra_indent);
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2328 break;
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2329
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2330 default:
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2331 print_nd_array <FloatComplexNDArray, FloatComplex, FloatComplexMatrix>
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2332 (os, nda, pr_as_read_syntax);
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2333 break;
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2334 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2335 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2336
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2337 // FIXME: write single precision versions of the printing functions.
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2338
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2339 void
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2340 octave_print_internal (std::ostream& os, const Matrix& m,
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2341 bool pr_as_read_syntax, int extra_indent)
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2342 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2343 octave_print_matrix_internal (os, m, pr_as_read_syntax, extra_indent);
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2344 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2345
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2346 void
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2347 octave_print_internal (std::ostream& os, const FloatMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2348 bool pr_as_read_syntax, int extra_indent)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2349 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2350 octave_print_matrix_internal (os, m, pr_as_read_syntax, extra_indent);
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2351 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2352
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2353 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2354 octave_print_internal (std::ostream& os, const DiagMatrix& m,
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2355 bool pr_as_read_syntax, int extra_indent)
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2356 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2357 octave_print_diag_matrix_internal (os, m, pr_as_read_syntax, extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2358 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2359
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2360 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2361 octave_print_internal (std::ostream& os, const FloatDiagMatrix& m,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2362 bool pr_as_read_syntax, int extra_indent)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
2363 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2364 octave_print_diag_matrix_internal (os, m, pr_as_read_syntax, extra_indent);
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2365 }
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2366
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2367 void
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2368 octave_print_internal (std::ostream& os, const ComplexMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2369 bool pr_as_read_syntax, int extra_indent)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2370 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2371 octave_print_matrix_internal (os, cm, pr_as_read_syntax, extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2372 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2373
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2374 void
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2375 octave_print_internal (std::ostream& os, const FloatComplexMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2376 bool pr_as_read_syntax, int extra_indent)
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2377 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2378 octave_print_matrix_internal (os, cm, pr_as_read_syntax, extra_indent);
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2379 }
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2380
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2381 void
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2382 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm,
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2383 bool pr_as_read_syntax, int extra_indent)
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
2384 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2385 octave_print_diag_matrix_internal (os, cm, pr_as_read_syntax, extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2386 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2387
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2388 void
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2389 octave_print_internal (std::ostream& os, const FloatComplexDiagMatrix& cm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2390 bool pr_as_read_syntax, int extra_indent)
8625
4d90d21a9cd9 special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 8333
diff changeset
2391 {
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2392 octave_print_diag_matrix_internal (os, cm, pr_as_read_syntax, extra_indent);
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2393 }
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2394
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7721
diff changeset
2395 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2396 octave_print_internal (std::ostream& os, const Range& r,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2397 bool pr_as_read_syntax, int extra_indent)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2398 {
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2399 double base = r.base ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2400 double increment = r.inc ();
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2401 double limit = r.limit ();
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20172
diff changeset
2402 octave_idx_type num_elem = r.numel ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2403
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2404 if (plus_format && ! pr_as_read_syntax)
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
2405 pr_plus_format_matrix (os, r);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2406 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2407 {
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2408 float_display_format fmt = make_format (r);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2409
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2410 if (pr_as_read_syntax)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2411 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2412 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2413 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2414 os << base << " : ";
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
2415 if (increment != 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2416 os << increment << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2417 os << limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2418 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2419 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2420 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
2421 pr_float (os, fmt, base);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2422 os << " : ";
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
2423 if (increment != 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2424 {
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
2425 pr_float (os, fmt, increment);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2426 os << " : ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2427 }
24786
0aeef407b04e don't pass field width as separate argument in pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24785
diff changeset
2428 pr_float (os, fmt, limit);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2429 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2430 }
626
96be9eae023f [project @ 1994-08-19 02:10:54 by jwe]
jwe
parents: 575
diff changeset
2431 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2432 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2433 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2434
24788
6f04028d5d86 use templates to eliminate more nearly duplicate pr-output code
John W. Eaton <jwe@octave.org>
parents: 24787
diff changeset
2435 int column_width = get_column_width (fmt);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2436 octave_idx_type total_width = num_elem * column_width;
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21747
diff changeset
2437 octave_idx_type max_width = octave::command_editor::terminal_cols ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2438
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2439 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2440 {
24769
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2441 os << ' ';
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2442 for (octave_idx_type i = 0; i < num_elem; i++)
e574b957b01b don't print extra newline after matrices with format free (bug #53168)
John W. Eaton <jwe@octave.org>
parents: 24767
diff changeset
2443 os << ' ' << r.elem(i);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2444 return;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2445 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2446
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2447 octave_idx_type inc = num_elem;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2448 if (total_width > max_width && Vsplit_long_rows)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2449 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2450 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2451 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2452 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2453 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2454
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2455 max_width -= extra_indent;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2456
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2457 if (max_width < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2458 max_width = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2459
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2460 pr_scale_header (os, fmt.scale_factor ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2461
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2462 octave_idx_type col = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2463 while (col < num_elem)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2464 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
2465 octave_idx_type lim = (col + inc < num_elem ? col + inc : num_elem);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2466
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2467 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2468 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2469
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2470 os << std::setw (extra_indent) << "";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2471
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2472 for (octave_idx_type i = col; i < lim; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2473 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2474 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2475
16169
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2476 double val;
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2477 if (i == 0)
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2478 val = base;
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2479 else
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2480 val = base + i * increment;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2481
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2482 if (i == num_elem - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2483 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2484 // See the comments in Range::matrix_value.
16169
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2485 if ((increment > 0 && val >= limit)
0303fda3e929 Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents: 15467
diff changeset
2486 || (increment < 0 && val <= limit))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2487 val = limit;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2488 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2489
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2490 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2491
24787
168d5b43c840 store scale factor in float_display_format object
John W. Eaton <jwe@octave.org>
parents: 24786
diff changeset
2492 pr_float (os, fmt, val);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2493 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2494
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2495 col += inc;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2496 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2497 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2498 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2499 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2500
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2501 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2502 octave_print_internal (std::ostream& os, const boolMatrix& bm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2503 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2504 int extra_indent)
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2505 {
21583
d5963a6e29c2 Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents: 21568
diff changeset
2506 uint8NDArray tmp (bm);
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2507 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent);
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2508 }
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2509
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3164
diff changeset
2510 void
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2511 octave_print_internal (std::ostream& os, const boolNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2512 bool pr_as_read_syntax,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2513 int extra_indent)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2514 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2515 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2516 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2517 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2518 case 2:
19317
25f535b90e52 Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents: 19255
diff changeset
2519 octave_print_internal (os, boolMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2520 pr_as_read_syntax, extra_indent);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2521 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2522
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2523 default:
13102
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2524 print_nd_array<boolNDArray, bool,
801c5a6ad487 Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 12483
diff changeset
2525 boolMatrix> (os, nda, pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2526 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2527 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2528 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2529
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2530 void
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
2531 octave_print_internal (std::ostream& os, const charMatrix& chm,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2532 bool pr_as_read_syntax,
21066
258c787cd9ce maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents: 20946
diff changeset
2533 int /* FIXME: extra_indent */,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2534 bool pr_as_string)
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2535 {
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2536 if (pr_as_string)
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2537 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2538 octave_idx_type nstr = chm.rows ();
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2539
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2540 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2541 os << "[ ";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2542
2907
8bb31a2b480b [project @ 1997-04-30 05:01:46 by jwe]
jwe
parents: 2903
diff changeset
2543 if (nstr != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2544 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2545 for (octave_idx_type i = 0; i < nstr; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2546 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2547 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2548
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2549 std::string row = chm.row_as_string (i);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2550
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2551 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2552 {
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25569
diff changeset
2553 os << '"' << octave::undo_string_escapes (row) << '"';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2554
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2555 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2556 os << "; ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2557 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2558 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2559 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2560 os << row;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2561
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2562 if (i < nstr - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2563 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2564 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2565 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2566 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2567
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2568 if (pr_as_read_syntax && nstr > 1)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2569 os << " ]";
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2570 }
1572
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2571 else
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2572 {
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2573 os << "sorry, printing char matrices not implemented yet\n";
0d9e10d10bd7 [project @ 1995-10-19 04:31:30 by jwe]
jwe
parents: 1488
diff changeset
2574 }
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2575 }
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1328
diff changeset
2576
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2577 void
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2578 octave_print_internal (std::ostream& os, const charNDArray& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2579 bool pr_as_read_syntax, int extra_indent,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2580 bool pr_as_string)
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2581 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2582 switch (nda.ndims ())
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2583 {
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2584 case 1:
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2585 case 2:
19318
6c9ea5be96bf Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents: 19317
diff changeset
2586 octave_print_internal (os, charMatrix (nda),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2587 pr_as_read_syntax, extra_indent, pr_as_string);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2588 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2589
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2590 default:
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2591 print_nd_array <charNDArray, char, charMatrix> (os, nda,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2592 pr_as_read_syntax);
4513
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2593 break;
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2594 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2595 }
508238e65af7 [project @ 2003-09-19 21:40:57 by jwe]
jwe
parents: 4509
diff changeset
2596
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2597 void
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2598 octave_print_internal (std::ostream& os, const std::string& s,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2599 bool pr_as_read_syntax, int extra_indent)
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2600 {
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2601 Array<std::string> nda (dim_vector (1, 1), s);
4925
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2602
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2603 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent);
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2604 }
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2605
90f51232d751 [project @ 2004-08-02 22:09:47 by jwe]
jwe
parents: 4901
diff changeset
2606 void
9732
b4fdfee405b5 remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents: 9643
diff changeset
2607 octave_print_internal (std::ostream& os, const Array<std::string>& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2608 bool pr_as_read_syntax, int /* extra_indent */)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2609 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2610 // FIXME: this mostly duplicates the code in the print_nd_array<>
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21748
diff changeset
2611 // function. Can fix this with std::is_same from C++11.
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2612
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
2613 if (nda.isempty ())
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2614 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
2615 else if (nda.numel () == 1)
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2616 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2617 os << nda(0);
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2618 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2619 else
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2620 {
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2621 int ndims = nda.ndims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2622
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2623 dim_vector dims = nda.dims ();
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2624
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2625 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2626
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2627 octave_idx_type m = 1;
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2628
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2629 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2630 m *= dims(i);
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2631
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2632 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2633 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2634
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2635 for (octave_idx_type i = 0; i < m; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2636 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2637 std::string nm = "ans";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2638
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2639 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2640 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2641 nm += "(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2642
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2643 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2644
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2645 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2646 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2647 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2648
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2649 if (k < ndims - 1)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2650 buf << ',';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2651 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2652 buf << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2653 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2654
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2655 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2656 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2657
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2658 Array<idx_vector> idx (dim_vector (ndims, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2659
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2660 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2661 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2662
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2663 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2664 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2665
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2666 Array<std::string> page (nda.index (idx), dim_vector (nr, nc));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2667
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2668 // FIXME: need to do some more work to put these
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2669 // in neatly aligned columns...
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2670
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2671 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2672 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2673
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2674 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2675 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2676 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2677
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2678 for (octave_idx_type ii = 0; ii < n_rows; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2679 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2680 for (octave_idx_type jj = 0; jj < n_cols; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2681 os << " " << page(ii,jj);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2682
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2683 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2684 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2685
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2686 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2687 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2688
26501
cfe28edab48b pr-output.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
2689 increment_index (ra_idx, dims, 2);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2690 }
4655
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2691 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2692 }
c8829691db47 [project @ 2003-11-24 21:24:37 by jwe]
jwe
parents: 4632
diff changeset
2693
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2694 template <typename T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2695 class
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2696 octave_print_conv
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2697 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2698 public:
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2699 typedef T print_conv_type;
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2700 };
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2701
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2702 #define PRINT_CONV(T1, T2) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2703 template <> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2704 class \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2705 octave_print_conv<T1> \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2706 { \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2707 public: \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2708 typedef T2 print_conv_type; \
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2709 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2710
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2711 PRINT_CONV (octave_int8, octave_int16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2712 PRINT_CONV (octave_uint8, octave_uint16);
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2713
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2714 #undef PRINT_CONV
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2715
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2716 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2717 static inline void
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2718 pr_int (std::ostream& os, const T& d, int fw = 0)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2719 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14429
diff changeset
2720 size_t sz = d.byte_size ();
23432
e35a5c1233d0 maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents: 23410
diff changeset
2721 const unsigned char *tmpi = d.iptr ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2722
5544
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2723 // Unless explicitly asked for, always print in big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2724 // format for hex and bit formats.
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2725 //
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2726 // {bit,hex}_format == 1: print big-endian
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2727 // {bit,hex}_format == 2: print native
2286fa5f2e5d [project @ 2005-11-21 18:44:31 by jwe]
jwe
parents: 5404
diff changeset
2728
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2729 if (hex_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2730 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2731 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2732
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2733 os.flags (std::ios::right | std::ios::hex);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2734
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
2735 if (hex_format > 1 || octave::mach_info::words_big_endian ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2736 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2737 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2738 os << std::setw (2) << static_cast<int> (tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2739 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2740 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2741 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2742 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2743 os << std::setw (2) << static_cast<int> (tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2744 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2745 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2746 else if (bit_format)
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2747 {
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
2748 if (octave::mach_info::words_big_endian ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2749 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2750 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2751 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2752 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2753 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2754 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2755 if (bit_format > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2756 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2757 for (size_t i = 0; i < sz; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2758 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2759 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2760 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2761 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2762 for (int i = sz - 1; i >= 0; i--)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2763 PRINT_CHAR_BITS (os, tmpi[i]);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2764 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2765 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2766 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2767 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2768 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
2769 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
2770
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2771 os << std::setw (fw)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2772 << typename octave_print_conv<T>::print_conv_type (d);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2773
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2774 if (bank_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2775 os << ".00";
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2776 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2777 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2778
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2779 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2780 pr_int (std::ostream&, const octave_int8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2781
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2782 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2783 pr_int (std::ostream&, const octave_int16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2784
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2785 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2786 pr_int (std::ostream&, const octave_int32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2787
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2788 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2789 pr_int (std::ostream&, const octave_int64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2790
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2791 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2792 pr_int (std::ostream&, const octave_uint8&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2793
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2794 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2795 pr_int (std::ostream&, const octave_uint16&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2796
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2797 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2798 pr_int (std::ostream&, const octave_uint32&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2799
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2800 template void
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2801 pr_int (std::ostream&, const octave_uint64&, int);
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2802
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2803 template <typename T>
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2804 void
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2805 octave_print_internal_template (std::ostream& os,
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2806 const float_display_format& fmt,
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2807 const octave_int<T>& val, bool)
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2808 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2809 if (plus_format)
24781
e6f380f9b2a4 use template for printing matrices in plus format
John W. Eaton <jwe@octave.org>
parents: 24771
diff changeset
2810 pr_plus_format (os, val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2811 else
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2812 {
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2813 if (free_format)
23534
b6498c088fca maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents: 23457
diff changeset
2814 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val);
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2815 else
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2816 {
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2817 float_format r_fmt = fmt.real_format ();
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2818
27183
2d9decd77e58 revamp float_format object
John W. Eaton <jwe@octave.org>
parents: 27156
diff changeset
2819 pr_int (os, val, r_fmt.width ());
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2820 }
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2821 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2822 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2823
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2824 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2825 OCTINTERP_API void \
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2826 octave_print_internal (std::ostream& os, \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2827 const float_display_format& fmt, \
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2828 const octave_int<TYPE>& val, bool dummy) \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
2829 { \
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2830 octave_print_internal_template (os, fmt, val, dummy); \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2831 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2832
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2833 PRINT_INT_SCALAR_INTERNAL (int8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2834 PRINT_INT_SCALAR_INTERNAL (uint8_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2835 PRINT_INT_SCALAR_INTERNAL (int16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2836 PRINT_INT_SCALAR_INTERNAL (uint16_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2837 PRINT_INT_SCALAR_INTERNAL (int32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2838 PRINT_INT_SCALAR_INTERNAL (uint32_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2839 PRINT_INT_SCALAR_INTERNAL (int64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2840 PRINT_INT_SCALAR_INTERNAL (uint64_t)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2841
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21100
diff changeset
2842 template <typename T>
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
2843 static inline void
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
2844 octave_print_internal_template (std::ostream& os, const intNDArray<T>& nda,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2845 bool pr_as_read_syntax, int extra_indent)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2846 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2847 // FIXME: this mostly duplicates the code in the print_nd_array<>
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21748
diff changeset
2848 // function. Can fix this with std::is_same from C++11.
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2849
23577
80c42f4cca13 maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents: 23565
diff changeset
2850 if (nda.isempty ())
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2851 print_empty_nd_array (os, nda.dims (), pr_as_read_syntax);
20232
a9574e3c6e9e Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20230
diff changeset
2852 else if (nda.numel () == 1)
24745
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2853 octave_print_internal_template (os, float_display_format (), nda(0),
d2467914ce33 enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents: 24737
diff changeset
2854 pr_as_read_syntax);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2855 else if (plus_format && ! pr_as_read_syntax)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2856 {
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2857 int ndims = nda.ndims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2858
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2859 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2860
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2861 dim_vector dims = nda.dims ();
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2862
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2863 octave_idx_type m = 1;
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2864
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2865 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2866 m *= dims(i);
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
2867
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2868 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2869 octave_idx_type nc = dims(1);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2870
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2871 for (octave_idx_type i = 0; i < m; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2872 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2873 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2874 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2875 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2876
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2877 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2878
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2879 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2880 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2881 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2882
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2883 if (k < ndims - 1)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2884 buf << ',';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2885 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2886 buf << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2887 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2888
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2889 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2890
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2891 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2892 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2893 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2894 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2895
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2896 Array<idx_vector> idx (dim_vector (ndims, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2897
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2898 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2899 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2900
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2901 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2902 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2903
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2904 Array<T> page (nda.index (idx), dim_vector (nr, nc));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2905
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2906 for (octave_idx_type ii = 0; ii < nr; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2907 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2908 for (octave_idx_type jj = 0; jj < nc; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2909 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2910 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2911
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2912 pr_plus_format (os, page(ii,jj));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2913 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2914
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2915 if ((ii < nr - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2916 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2917 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2918
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2919 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2920 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2921 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2922 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2923 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2924 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2925 }
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2926 else
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2927 {
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2928 int ndims = nda.ndims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2929
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2930 dim_vector dims = nda.dims ();
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2931
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
2932 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0);
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2933
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2934 octave_idx_type m = 1;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2935
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2936 for (int i = 2; i < ndims; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2937 m *= dims(i);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2938
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2939 octave_idx_type nr = dims(0);
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2940 octave_idx_type nc = dims(1);
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2941
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2942 int fw = 0;
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2943 if (hex_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2944 fw = 2 * nda(0).byte_size ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2945 else if (bit_format)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2946 fw = nda(0).nbits ();
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2947 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2948 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2949 bool isneg = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2950 int digits = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2951
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2952 for (octave_idx_type i = 0; i < dims.numel (); i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2953 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2954 int new_digits
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2955 = static_cast<int>
24770
39186eac5a05 preparing for a brave new future, use templates in some pr-output functions
John W. Eaton <jwe@octave.org>
parents: 24769
diff changeset
2956 (std::floor (log10 (double (abs (nda(i).value ()))) + 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2957
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2958 if (new_digits > digits)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2959 digits = new_digits;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2960
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2961 if (! isneg)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2962 isneg = (abs (nda(i).value ()) != nda(i).value ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2963 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2964
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2965 fw = digits + isneg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2966 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2967
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
2968 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2));
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2969 octave_idx_type total_width = nc * column_width;
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21747
diff changeset
2970 int max_width = octave::command_editor::terminal_cols () - extra_indent;
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2971 octave_idx_type inc = nc;
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2972 if (total_width > max_width && Vsplit_long_rows)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2973 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2974 inc = max_width / column_width;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2975 if (inc == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2976 inc++;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2977 }
4949
f6b63ff1119b [project @ 2004-08-31 19:17:44 by jwe]
jwe
parents: 4933
diff changeset
2978
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5086
diff changeset
2979 for (octave_idx_type i = 0; i < m; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2980 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2981 if (m > 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2982 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2983 std::string nm = "ans(:,:,";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2984
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2985 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2986
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2987 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2988 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2989 buf << ra_idx(k) + 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2990
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2991 if (k < ndims - 1)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2992 buf << ',';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2993 else
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
2994 buf << ')';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2995 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2996
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2997 nm += buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
2998
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
2999 os << nm << " =\n";
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3000 if (! Vcompact_format)
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3001 os << "\n";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3002 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3003
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3004 Array<idx_vector> idx (dim_vector (ndims, 1));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3005
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3006 idx(0) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3007 idx(1) = idx_vector (':');
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3008
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3009 for (int k = 2; k < ndims; k++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3010 idx(k) = idx_vector (ra_idx(k));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3011
11570
57632dea2446 attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents: 11547
diff changeset
3012 Array<T> page (nda.index (idx), dim_vector (nr, nc));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3013
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3014 if (free_format)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3015 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3016 if (pr_as_read_syntax)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3017 os << "[\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3018
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3019 for (octave_idx_type ii = 0; ii < nr; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3020 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3021 for (octave_idx_type jj = 0; jj < nc; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3022 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3023 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3024 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3025 os << typename octave_print_conv<T>::print_conv_type (page(ii,jj));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3026 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3027 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3028 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3029
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3030 if (pr_as_read_syntax)
23807
336f89b6208b Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents: 23803
diff changeset
3031 os << ']';
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3032 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3033 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3034 {
23675
f71c0195b19d move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents: 23662
diff changeset
3035 octave::preserve_stream_state stream_state (os);
17818
f1b59ef34eda attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
3036
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3037 octave_idx_type n_rows = page.rows ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3038 octave_idx_type n_cols = page.cols ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3039
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3040 for (octave_idx_type col = 0; col < n_cols; col += inc)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3041 {
24737
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
3042 octave_idx_type lim = (col + inc < n_cols ? col + inc
5be92b26ef8f Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents: 24673
diff changeset
3043 : n_cols);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3044
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3045 pr_col_num_header (os, total_width, max_width, lim, col,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3046 extra_indent);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3047
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3048 for (octave_idx_type ii = 0; ii < n_rows; ii++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3049 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3050 os << std::setw (extra_indent) << "";
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3051
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3052 for (octave_idx_type jj = col; jj < lim; jj++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3053 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3054 octave_quit ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3055 os << " ";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3056 pr_int (os, page(ii,jj), fw);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3057 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3058 if ((ii < n_rows - 1) || (i < m -1))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3059 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3060 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3061 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3062 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3063
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3064 if (i < m - 1)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3065 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3066 os << "\n";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3067 increment_index (ra_idx, dims, 2);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3068 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3069 }
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3070 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3071 }
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3072
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3073 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3074 OCTINTERP_API void \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3075 octave_print_internal (std::ostream& os, const intNDArray<TYPE>& nda, \
22197
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3076 bool pr_as_read_syntax, int extra_indent) \
e43d83253e28 refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents: 22022
diff changeset
3077 { \
7215
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3078 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3079 }
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3080
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3081 PRINT_INT_ARRAY_INTERNAL (octave_int8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3082 PRINT_INT_ARRAY_INTERNAL (octave_uint8)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3083 PRINT_INT_ARRAY_INTERNAL (octave_int16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3084 PRINT_INT_ARRAY_INTERNAL (octave_uint16)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3085 PRINT_INT_ARRAY_INTERNAL (octave_int32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3086 PRINT_INT_ARRAY_INTERNAL (octave_uint32)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3087 PRINT_INT_ARRAY_INTERNAL (octave_int64)
dd88d61d443f [project @ 2007-11-29 16:44:45 by jwe]
jwe
parents: 7097
diff changeset
3088 PRINT_INT_ARRAY_INTERNAL (octave_uint64)
4901
35bfb4e0b96b [project @ 2004-06-14 18:33:02 by jwe]
jwe
parents: 4869
diff changeset
3089
8012
63dbb85452cc fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents: 7896
diff changeset
3090 void
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3091 octave_print_internal (std::ostream&, const Cell&, bool, int, bool)
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3092 {
3933
f9ea3dcf58ee [project @ 2002-05-15 03:21:00 by jwe]
jwe
parents: 3928
diff changeset
3093 panic_impossible ();
3928
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3094 }
e8627dc4bdf2 [project @ 2002-05-03 19:56:01 by jwe]
jwe
parents: 3776
diff changeset
3095
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3096 void
19620
a1d172bfcb2f eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents: 19367
diff changeset
3097 octave_print_internal (std::ostream&, const octave_value&, bool)
17866
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3098 {
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3099 panic_impossible ();
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3100 }
ea0ecbe2eaf5 display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents: 17847
diff changeset
3101
20915
a3359fe50966 remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents: 20909
diff changeset
3102 DEFUN (rats, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3103 doc: /* -*- texinfo -*-
27154
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3104 @deftypefn {} {@var{s} =} rats (@var{x})
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3105 @deftypefnx {} {@var{s} =} rats (@var{x}, @var{len})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3106 Convert @var{x} into a rational approximation represented as a string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3107
27154
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3108 A rational approximation to a floating point number is a simple fraction
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3109 with numerator @var{N} and denominator @var{D} such that
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3110 @code{@var{x} = @var{N}/@var{D}}.
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3111
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3112 The optional second argument defines the maximum length of the string
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3113 representing the elements of @var{x}. By default, @var{len} is 9.
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3114
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3115 If the length of the smallest possible rational approximation exceeds
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3116 @var{len}, an asterisk (*) padded with spaces will be returned instead.
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3117
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3118 Example conversion from matrix to string, and back again.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3119
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3120 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3121 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3122 r = rats (hilb (4));
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3123 x = str2num (r)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3124 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3125 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3126
27154
ecc16b72bfb3 doc: Redo documentation for rats() function.
Rik <rik@octave.org>
parents: 26585
diff changeset
3127 @seealso{rat, format}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3128 @end deftypefn */)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3129 {
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3130 int nargin = args.length ();
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3131
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20897
diff changeset
3132 if (nargin < 1 || nargin > 2)
7896
92c26470fe56 Frats fix for nargin==0
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
3133 print_usage ();
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3134
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3135 octave_value arg = args(0);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3136
23586
f6c5db0a02e7 maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents: 23577
diff changeset
3137 if (! arg.isnumeric ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3138 error ("rats: X must be numeric");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3139
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
3140 octave::unwind_protect frame;
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3141
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3142 frame.protect_var (rat_string_len);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3143
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3144 rat_string_len = 9;
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3145 if (nargin == 2)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3146 rat_string_len = args(1).nint_value ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3147
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3148 frame.protect_var (rat_format);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3149
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3150 rat_format = true;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3151
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3152 std::ostringstream buf;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3153 arg.print (buf);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3154 std::string s = buf.str ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3155
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3156 std::list<std::string> lst;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3157
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3158 size_t n = 0;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3159 size_t s_len = s.length ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3160
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3161 while (n < s_len)
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3162 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3163 size_t m = s.find ('\n', n);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3164
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3165 if (m == std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3166 {
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3167 lst.push_back (s.substr (n));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3168 break;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3169 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3170 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3171 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3172 lst.push_back (s.substr (n, m - n));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3173 n = m + 1;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3174 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3175 }
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3176
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3177 return ovl (string_vector (lst));
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3178 }
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3179
26111
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3180 /*
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3181 %!test
26716
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3182 %! [old_fmt, old_spacing] = format ();
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3183 %! unwind_protect
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3184 %! format short;
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3185 %! assert (rats (2.0005, 9), "4001/2000");
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3186 %! assert (rats (-2.0005, 10), "-4001/2000");
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3187 %! assert (strtrim (rats (2.0005, 30)), "4001/2000");
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3188 %! assert (pi - str2num (rats (pi, 30)), 0, 4 * eps);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3189 %! assert (e - str2num (rats (e, 30)), 0, 4 * eps);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3190 %! assert (rats (123, 2), " *");
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3191 %! v = 1 / double (intmax);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3192 %! err = v - str2num (rats (v, 12));
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3193 %! assert (err, 0, 4 * eps);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3194 %! unwind_protect_cleanup
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3195 %! format (old_fmt);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3196 %! format (old_spacing);
daa281e03d9a Harden BIST tests against changes in format().
Rik <rik@octave.org>
parents: 26585
diff changeset
3197 %! end_unwind_protect
26111
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3198 */
3e44ed9d50b6 Move rational_approx to liboctave (patch #9084).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26009
diff changeset
3199
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3200 DEFUN (disp, args, nargout,
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3201 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3202 doc: /* -*- texinfo -*-
24764
36ca11f78553 Document second calling form of disp().
Rik <rik@octave.org>
parents: 23219
diff changeset
3203 @deftypefn {} {} disp (@var{x})
36ca11f78553 Document second calling form of disp().
Rik <rik@octave.org>
parents: 23219
diff changeset
3204 @deftypefnx {} {@var{str} =} disp (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3205 Display the value of @var{x}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3206
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3207 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3208
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3209 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3210 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3211 disp ("The value of pi is:"), disp (pi)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3212
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3213 @print{} the value of pi is:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3214 @print{} 3.1416
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3215 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3216 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3217
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3218 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3219 Note that the output from @code{disp} always ends with a newline.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3220
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3221 If an output value is requested, @code{disp} prints nothing and returns the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3222 formatted output in a string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3223 @seealso{fdisp}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3224 @end deftypefn */)
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3225 {
20909
03e4ddd49396 omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents: 20897
diff changeset
3226 if (args.length () != 1)
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3227 print_usage ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3228
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3229 octave_value_list retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20925
diff changeset
3230
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3231 octave_value arg = args(0);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3232
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3233 if (nargout == 0)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3234 arg.print (octave_stdout);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3235 else
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3236 {
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3237 std::ostringstream buf;
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3238 arg.print (buf);
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
3239 retval = (octave_value (buf.str (), arg.is_dq_string () ? '"' : '\''));
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3240 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3241
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3242 return retval;
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3243 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3244
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3245 DEFMETHOD (fdisp, interp, args, ,
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3246 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3247 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3248 @deftypefn {} {} fdisp (@var{fid}, @var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3249 Display the value of @var{x} on the stream @var{fid}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3250
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3251 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3252
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3253 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3254 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3255 fdisp (stdout, "The value of pi is:"), fdisp (stdout, pi)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3256
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3257 @print{} the value of pi is:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3258 @print{} 3.1416
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3259 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3260 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3261
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3262 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3263 Note that the output from @code{fdisp} always ends with a newline.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3264 @seealso{disp}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3265 @end deftypefn */)
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3266 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20801
diff changeset
3267 if (args.length () != 2)
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3268 print_usage ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3269
23738
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3270 octave::stream_list& streams = interp.get_stream_list ();
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3271
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3272 int fid = streams.get_file_number (args(0));
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3273
8acd390d16c9 don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents: 23675
diff changeset
3274 octave::stream os = streams.lookup (fid, "fdisp");
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3275
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3276 std::ostream *osp = os.output_stream ();
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3277
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3278 octave_value arg = args(1);
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3279
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3280 if (osp)
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3281 arg.print (*osp);
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3282 else
20801
a542a9bf177e eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3283 error ("fdisp: stream FID not open for writing");
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3284
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
3285 return ovl ();
3685
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3286 }
9d8306640373 [project @ 2000-06-28 19:25:02 by jwe]
jwe
parents: 3683
diff changeset
3287
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3288 /*
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3289 ## FIXME: This test writes values to a file, but then never checks them.
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3290 %!test
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3291 %! [old_fmt, old_spacing] = format ();
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3292 %! unwind_protect
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3293 %! format short
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3294 %! fd = tmpfile ();
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3295 %! for r = [0, Inf -Inf, NaN]
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3296 %! for i = [0, Inf -Inf, NaN]
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3297 %! fdisp (fd, complex (r, i));
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3298 %! endfor
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3299 %! endfor
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3300 %! fclose (fd);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3301 %! unwind_protect_cleanup
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3302 %! format (old_fmt);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3303 %! format (old_spacing);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3304 %! end_unwind_protect
13129
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3305
155d7a5e70f5 src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents: 13112
diff changeset
3306 %!test
25108
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3307 %! [old_fmt, old_spacing] = format ();
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3308 %! unwind_protect
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3309 %! foo.real = pi * ones (3,20,3);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3310 %! foo.complex = pi * ones (3,20,3) + 1i;
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3311 %! foo.char = repmat ("- Hello World -", [3, 20]);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3312 %! foo.cell = {foo.real, foo.complex, foo.char};
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3313 %! fields = fieldnames (foo);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3314 %! for f = 1:numel (fields)
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3315 %! format loose;
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3316 %! loose = disp (foo.(fields{f}));
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3317 %! format compact;
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3318 %! compact = disp (foo.(fields{f}));
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3319 %! expected = strrep (loose, "\n\n", "\n");
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3320 %! assert (expected, compact);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3321 %! endfor
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3322 %! unwind_protect_cleanup
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3323 %! format (old_fmt);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3324 %! format (old_spacing);
7561fb4ab972 pr-output.cc: Fix BIST tests so that display format is saved & restored.
Rik <rik@octave.org>
parents: 25107
diff changeset
3325 %! end_unwind_protect
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
3326 */
9629
e1345a9002e8 pr-output.cc: new test
John W. Eaton <jwe@octave.org>
parents: 9612
diff changeset
3327
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3328 DEFUN (display, args, ,
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3329 classes: cell char double function_handle int8 int16 int32 int64 logical single struct uint8 uint16 uint32 uint64
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3330 doc: /* -*- texinfo -*-
23565
3a730821e4a2 doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents: 23564
diff changeset
3331 @deftypefn {} {} display (@var{obj})
23332
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3332 Display the contents of the object @var{obj} prepended by its name.
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3333
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3334 The Octave interpreter calls the @code{display} function whenever it needs
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3335 to present a class on-screen. Typically, this would be a statement which
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3336 does not end in a semicolon to suppress output. For example:
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3337
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3338 @example
23182
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3339 myclass (@dots{})
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3340 @end example
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3341
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3342 Or:
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3343
8a37443f1a7b doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23084
diff changeset
3344 @example
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3345 myobj = myclass (@dots{})
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3346 @end example
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3347
23410
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3348 In general, user-defined classes should overload the @code{disp} method to
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3349 avoid the default output:
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3350
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3351 @example
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3352 @group
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3353 myobj = myclass (@dots{})
23410
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3354 @result{} myobj =
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3355
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3356 <class myclass>
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3357 @end group
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3358 @end example
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3359
23410
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3360 When overloading the @code{display} method instead, one has to take care
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3361 of properly displaying the object's name. This can be done by using the
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3362 @code{inputname} function.
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3363
705361dfe353 doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 23398
diff changeset
3364 @seealso{disp, class, subsref, subsasgn}
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3365 @end deftypefn */)
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3366 {
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3367 int nargin = args.length ();
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3368
23332
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3369 // Matlab apparently accepts two arguments with the second set to the
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3370 // inputname of the first. This is undocumented, but we'll use it.
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3371 // However, we never call display methods for classes with more than
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3372 // one argument.
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3373
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3374 if (nargin < 1 || nargin > 2)
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3375 print_usage ();
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3376
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3377 std::string name;
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3378
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3379 if (nargin == 2)
23332
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3380 name = args(1).xstring_value ("NAME must be a string");
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3381 else
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3382 {
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3383 string_vector names = args.name_tags ();
22921
b28801182c08 don't display "ans" for "display (expr)" (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22898
diff changeset
3384 name = names(0);
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3385 }
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3386
23332
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3387 // We are here because there is no overloaded display method for this
7d4ca8c01bbb don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
3388 // object type.
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3389
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3390 octave_value value = args(0);
22989
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3391
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3392 // If print_name_tag displays a newline, then also print one after
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3393 // disp is done.
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3394
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3395 bool print_newlines = false;
25646
4d565baa475e move libinterp/utils functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25569
diff changeset
3396 if (octave::valid_identifier (name))
22989
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3397 print_newlines = value.print_name_tag (octave_stdout, name);
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3398
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3399 // Use feval so that dispatch will also work for disp.
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3400
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23059
diff changeset
3401 octave::feval ("disp", ovl (value));
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3402
22989
698c1190d790 * pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents: 22921
diff changeset
3403 if (print_newlines)
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3404 octave_stdout << std::endl;
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3405
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3406 return ovl ();
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3407 }
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3408
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3409 /*
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3410 %!test
26585
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3411 %! [old_fmt, old_spacing] = format ();
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3412 %! unwind_protect
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3413 %! format short;
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3414 %! str = evalc ("x = 1.1; display (x)");
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3415 %! assert (str, "x = 1.1000\n");
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3416 %! unwind_protect_cleanup
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3417 %! format (old_fmt);
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3418 %! format (old_spacing);
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3419 %! end_unwind_protect
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3420
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3421 %!test
26585
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3422 %! [old_fmt, old_spacing] = format ();
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3423 %! unwind_protect
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3424 %! format short;
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3425 %! str = evalc ("display (1.1)");
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3426 %! assert (str, " 1.1000\n");
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3427 %! unwind_protect_cleanup
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3428 %! format (old_fmt);
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3429 %! format (old_spacing);
d673b506f382 test: use "format short" in tests depending on output format (bug #55539)
Mike Miller <mtmiller@octave.org>
parents: 26501
diff changeset
3430 %! end_unwind_protect
22898
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3431
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3432 ## Test input validation
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3433 %!error display ()
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3434 %!error display (1,2)
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3435 */
9baa19102908 refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents: 22881
diff changeset
3436
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
3437 static inline void
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3438 init_format_state (void)
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3439 {
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3440 free_format = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3441 plus_format = false;
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3442 rat_format = false;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3443 bank_format = false;
3608
ccfafa1d8510 [project @ 2000-03-15 08:47:35 by jwe]
jwe
parents: 3568
diff changeset
3444 hex_format = 0;
1309
c0187e1c02f9 [project @ 1995-06-25 04:00:46 by jwe]
jwe
parents: 1282
diff changeset
3445 bit_format = 0;
2387
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3446 print_e = false;
be4616e36133 [project @ 1996-10-12 18:45:13 by jwe]
jwe
parents: 2317
diff changeset
3447 print_big_e = false;
4509
9ec494b3eb5f [project @ 2003-09-11 19:08:25 by jwe]
jwe
parents: 4431
diff changeset
3448 print_g = false;
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3449 print_eng = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3450 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3451
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3452 static std::string format_string ("short");
24782
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
3453
0eb41237424e more templates for pr-output.cc functions
John W. Eaton <jwe@octave.org>
parents: 24781
diff changeset
3454 static inline void
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3455 set_format_style (int argc, const string_vector& argv)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3456 {
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3457 int idx = 1;
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3458 std::string format;
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3459
1899
2f19333b1e72 [project @ 1996-02-09 17:46:58 by jwe]
jwe
parents: 1884
diff changeset
3460 if (--argc > 0)
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3461 {
3523
b80bbb43a1a9 [project @ 2000-02-02 10:25:52 by jwe]
jwe
parents: 3503
diff changeset
3462 std::string arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3463 format = arg;
2584
5e41d9c42283 [project @ 1996-12-10 09:39:44 by jwe]
jwe
parents: 2522
diff changeset
3464
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3465 if (arg == "short")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3466 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3467 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3468 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3469 arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3470 format.append (arg);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3471
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3472 if (arg == "e")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3473 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3474 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3475 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3476 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3477 else if (arg == "E")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3478 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3479 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3480 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3481 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3482 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3483 else if (arg == "g")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3484 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3485 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3486 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3487 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3488 else if (arg == "G")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3489 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3490 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3491 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3492 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3493 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3494 else if (arg == "eng")
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3495 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3496 init_format_state ();
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3497 print_eng = true;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3498 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3499 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3500 error ("format: unrecognized option 'short %s'", arg.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3501 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3502 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3503 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3504
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3505 set_output_prec (5);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3506 }
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3507 else if (arg == "shorte")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3508 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3509 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3510 print_e = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3511 set_output_prec (5);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3512 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3513 else if (arg == "shortE")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3514 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3515 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3516 print_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3517 print_big_e = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3518 set_output_prec (5);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3519 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3520 else if (arg == "shortg")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3521 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3522 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3523 print_g = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3524 set_output_prec (5);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3525 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3526 else if (arg == "shortG")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3527 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3528 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3529 print_g = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3530 print_big_e = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3531 set_output_prec (5);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3532 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3533 else if (arg == "shortEng")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3534 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3535 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3536 print_eng = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3537 set_output_prec (5);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3538 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3539 else if (arg == "long")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3540 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3541 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3542 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3543 arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3544 format.append (arg);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3545
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3546 if (arg == "e")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3547 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3548 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3549 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3550 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3551 else if (arg == "E")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3552 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3553 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3554 print_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3555 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3556 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3557 else if (arg == "g")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3558 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3559 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3560 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3561 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3562 else if (arg == "G")
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3563 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3564 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3565 print_g = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3566 print_big_e = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3567 }
10741
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3568 else if (arg == "eng")
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3569 {
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3570 init_format_state ();
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3571 print_eng = true;
38bdcbb58df7 Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents: 10706
diff changeset
3572 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3573 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3574 error ("format: unrecognized option 'long %s'", arg.c_str ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3575 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3576 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3577 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3578
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3579 set_output_prec (16);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3580 }
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3581 else if (arg == "longe")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3582 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3583 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3584 print_e = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3585 set_output_prec (16);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3586 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3587 else if (arg == "longE")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3588 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3589 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3590 print_e = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3591 print_big_e = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3592 set_output_prec (16);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3593 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3594 else if (arg == "longg")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3595 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3596 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3597 print_g = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3598 set_output_prec (16);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3599 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3600 else if (arg == "longG")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3601 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3602 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3603 print_g = true;
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3604 print_big_e = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3605 set_output_prec (16);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3606 }
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3607 else if (arg == "longEng")
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3608 {
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3609 init_format_state ();
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3610 print_eng = true;
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3611 set_output_prec (16);
18464
917f1af7d2e4 Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents: 18438
diff changeset
3612 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3613 else if (arg == "hex")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3614 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3615 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3616 hex_format = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3617 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3618 else if (arg == "native-hex")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3619 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3620 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3621 hex_format = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3622 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3623 else if (arg == "bit")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3624 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3625 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3626 bit_format = 1;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3627 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3628 else if (arg == "native-bit")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3629 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3630 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3631 bit_format = 2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3632 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3633 else if (arg == "+" || arg == "plus")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3634 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3635 if (--argc > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3636 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3637 arg = argv[idx++];
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3638 format.append (arg);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3639
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3640 if (arg.length () == 3)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3641 plus_format_chars = arg;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3642 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3643 error ("format: invalid option for plus format");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3644 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3645 else
19232
97eea1e2d9ff pr-output.cc: fix default chars for "format +" for Matlab compatibility
Andreas Weber <andy.weber.aw@gmail.com>
parents: 18433
diff changeset
3646 plus_format_chars = "+- ";
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3647
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3648 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3649 plus_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3650 }
6788
c81a0f3f5a82 [project @ 2007-07-23 22:05:29 by dbateman]
dbateman
parents: 6670
diff changeset
3651 else if (arg == "rat")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3652 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3653 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3654 rat_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3655 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3656 else if (arg == "bank")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3657 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3658 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3659 bank_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3660 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3661 else if (arg == "free")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3662 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3663 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3664 free_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3665 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3666 else if (arg == "none")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3667 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3668 init_format_state ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3669 free_format = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3670 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3671 else if (arg == "compact")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3672 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3673 Vcompact_format = true;
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3674 return;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3675 }
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1742
diff changeset
3676 else if (arg == "loose")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3677 {
13112
969ed305dde5 Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 13102
diff changeset
3678 Vcompact_format = false;
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3679 return;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
3680 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3681 else
20831
35241c4b696c eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents: 20819
diff changeset
3682 error ("format: unrecognized format state '%s'", arg.c_str ());
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3683 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3684 else
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3685 {
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3686 init_format_state ();
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3687 set_output_prec (5);
23829
01899bdd2a3a Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents: 23807
diff changeset
3688 format = "short";
25107
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3689 Vcompact_format = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3690 }
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3691
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3692 format_string = format;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3693 }
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
3694
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3695 DEFUN (format, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3696 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3697 @deftypefn {} {} format
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3698 @deftypefnx {} {} format options
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3699 @deftypefnx {} {[@var{format}, @var{formatspacing}] =} format
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3700 Reset or specify the format of the output produced by @code{disp} and Octave's
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3701 normal echoing mechanism.
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3702
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3703 This command only affects the display of numbers, but not how they are stored
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3704 or computed. To change the internal representation from the default double use
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3705 one of the conversion functions such as @code{single}, @code{uint8},
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3706 @code{int64}, etc.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3707
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3708 By default, Octave displays 5 significant digits in a human readable form
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3709 (option @samp{short} paired with @samp{loose} format for matrices). If
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3710 @code{format} is invoked without any options, this default format is restored.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3711
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3712 Valid formats for floating point numbers are listed in the following
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3713 table.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3714
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3715 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3716 @item short
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3717 Fixed point format with 5 significant figures (default).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3718
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3719 @item long
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3720 Fixed point format with 16 significant figures.
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3721
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3722 As with the @samp{short} format, Octave will switch to an exponential @samp{e}
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3723 format if it is unable to format a matrix properly using the current format.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3724
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3725 @item short e
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3726 @itemx long e
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3727 Exponential format. The number to be represented is split between a mantissa
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3728 and an exponent (power of 10). The mantissa has 5 significant digits in the
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3729 short format. In the long format, double values are displayed with 16
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3730 significant digits and single values are displayed with 8. For example,
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3731 with the @samp{short e} format, @code{pi} is displayed as @code{3.1416e+00}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3732
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3733 @item short E
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3734 @itemx long E
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3735 Identical to @samp{short e} or @samp{long e} but displays an uppercase @samp{E}
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3736 to indicate the exponent. For example, with the @samp{long E} format,
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3737 @code{pi} is displayed as @code{3.141592653589793E+00}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3738
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3739 @item short g
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3740 @itemx long g
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3741 Optimally choose between fixed point and exponential format based on the
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3742 magnitude of the number. For example, with the @samp{short g} format,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3743 @code{pi .^ [2; 4; 8; 16; 32]} is displayed as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3744
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3745 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3746 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3747 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3748
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3749 9.8696
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3750 97.409
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3751 9488.5
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3752 9.0032e+07
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3753 8.1058e+15
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3754 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3755 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3756
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3757 @item short eng
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3758 @itemx long eng
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3759 Identical to @samp{short e} or @samp{long e} but displays the value using an
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3760 engineering format, where the exponent is divisible by 3. For example, with
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3761 the @samp{short eng} format, @code{10 * pi} is displayed as @code{31.416e+00}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3762
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3763 @item long G
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3764 @itemx short G
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3765 Identical to @samp{short g} or @samp{long g} but displays an uppercase @samp{E}
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3766 to indicate the exponent.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3767
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3768 @item free
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3769 @itemx none
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3770 Print output in free format, without trying to line up columns of matrices on
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3771 the decimal point. This is a raw format equivalent to the C++ code
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3772 @code{std::cout << @var{variable}}. In general, the result is a presentation
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3773 with 6 significant digits where unnecessary precision (such as trailing zeros
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3774 for integers) is suppressed. Complex numbers are formatted as numeric pairs
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3775 like this @samp{(0.60419, 0.60709)} instead of like this
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3776 @samp{0.60419 + 0.60709i}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3777 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3778
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3779 The following formats affect all numeric output (floating point and integer
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3780 types).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3781
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3782 @table @asis
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3783 @item @qcode{"+"}
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3784 @itemx @qcode{"+"} @qcode{"@var{chars}"}
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3785 @itemx @code{plus}
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3786 @itemx @code{plus @var{chars}}
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3787 Print a @samp{+} symbol for matrix elements greater than zero, a @samp{-}
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3788 symbol for elements less than zero, and a space for zero matrix elements. This
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3789 format can be useful for examining the sparsity structure of a large matrix.
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3790 For very large matrices the function @code{spy} which plots the sparsity
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3791 pattern will be clearer.
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3792
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3793 The optional argument @var{chars} specifies a list of 3 characters to use for
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3794 printing values greater than zero, less than zero, and equal to zero. For
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3795 example, with the format @qcode{"+" "+-."}, the matrix
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3796 @code{[1, 0, -1; -1, 0, 1]} is displayed as
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3797
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3798 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3799 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3800 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3801
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3802 +.-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3803 -.+
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3804 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3805 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3806
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3807 @item bank
24771
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3808 Print variable in a format appropriate for a currency (fixed format with two
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3809 digits to the right of the decimal point). Only the real part of a variable is
d277debe9c2f doc: Update format() documentation for "free", "+", "bank" formats (bug #53169).
Rik <rik@octave.org>
parents: 24770
diff changeset
3810 displayed, as the imaginary part makes no sense for a currency.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3811
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3812 @item native-hex
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3813 Print the hexadecimal representation of numbers as they are stored in memory.
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3814 For example, on a workstation which stores 8 byte real values in IEEE format
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3815 with the least significant byte first, the value of @code{pi} when printed in
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3816 @code{native-hex} format is @code{400921fb54442d18}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3817
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3818 @item hex
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3819 The same as @code{native-hex}, but always print the most significant byte
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3820 first.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3821
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3822 @item native-bit
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3823 Print the bit representation of numbers as stored in memory. For example, the
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3824 value of @code{pi} is
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3825
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3826 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3827 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3828 01000000000010010010000111111011
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3829 01010100010001000010110100011000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3830 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3831 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3832
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3833 (shown here in two 32 bit sections for typesetting purposes) when printed in
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3834 native-bit format on a workstation which stores 8 byte real values in IEEE
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3835 format with the least significant byte first.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3836
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3837 @item bit
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3838 The same as @code{native-bit}, but always print the most significant bits
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3839 first.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3840
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3841 @item rat
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3842 Print a rational approximation, i.e., values are approximated as the ratio of
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3843 small integers. For example, with the @samp{rat} format, @code{pi} is
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3844 displayed as @code{355/113}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3845 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3846
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3847 The following two options affect the display of all matrices.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3848
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3849 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3850 @item compact
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3851 Remove blank lines around column number labels and between matrices producing
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3852 more compact output with more data per page.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3853
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3854 @item loose
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3855 Insert blank lines above and below column number labels and between matrices to
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3856 produce a more readable output with less data per page. (default).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3857 @end table
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3858
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3859 If called with one or two output arguments, and no inputs, return the current
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3860 format and format spacing.
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3861
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3862 @seealso{fixed_point_format, output_precision, split_long_rows, print_empty_dimensions, rats}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3863 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3864 {
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3865 octave_value_list retval (std::min (nargout, 2));
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3866
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3867 if (nargout == 0)
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3868 {
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3869 int argc = args.length () + 1;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3870
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3871 string_vector argv = args.make_argv ("format");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3872
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3873 set_format_style (argc, argv);
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3874 }
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3875 else
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3876 {
25107
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3877 if (args.length () > 0)
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3878 warning ("format: cannot query and set format at the same time, ignoring set operation");
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3879
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3880 if (nargout >= 2)
23450
855122b993da maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents: 23433
diff changeset
3881 retval(1) = (Vcompact_format ? "compact" : "loose");
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3882
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3883 retval(0) = format_string;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3884 }
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3885
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3886 return retval;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3887 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
3888
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3889 /*
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3890 %!test
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3891 %! [old_fmt, old_spacing] = format ();
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3892 %! unwind_protect
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3893 %! ## Test one of the formats
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3894 %! format long;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3895 %! str = disp (pi);
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3896 %! assert (str, " 3.141592653589793\n");
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3897 %! str = disp (single (pi));
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3898 %! assert (str, " 3.1415927\n");
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3899 %! new_fmt = format ();
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3900 %! assert (new_fmt, "long");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3901 %! ## Test resetting format
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3902 %! format compact;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3903 %! [~, new_spacing] = format ();
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3904 %! assert (new_spacing, "compact");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3905 %! format;
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3906 %! [new_fmt, new_spacing] = format ();
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3907 %! assert (new_fmt, "short");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3908 %! assert (new_spacing, "loose");
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3909 %! unwind_protect_cleanup
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3910 %! format (old_fmt);
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3911 %! format (old_spacing);
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3912 %! end_unwind_protect
25107
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3913
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3914 %!test <*53427>
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3915 %! [old_fmt, old_spacing] = format ();
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3916 %! unwind_protect
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3917 %! format; # reset format to short and loose
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3918 %! format compact; # set compact format
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3919 %! format long; # set long format
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3920 %! [fmt, spacing] = format ();
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3921 %! assert (fmt, "long");
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3922 %! assert (spacing, "compact");
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3923 %! unwind_protect_cleanup
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3924 %! format (old_fmt);
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3925 %! format (old_spacing);
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3926 %! end_unwind_protect
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3927
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3928 ## Test input validation
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3929 %!test
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3930 %! fail ("fmt = format ('long')", "warning", "cannot query and set format");
13cd142c3f88 Don't reset compact/loose spacing when changing numerical format (Bug #53427).
Rik <rik@octave.org>
parents: 25054
diff changeset
3931
22881
f84aa17075d4 Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents: 22868
diff changeset
3932 */
18735
28eab2d84190 Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 18676
diff changeset
3933
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3934 DEFUN (fixed_point_format, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3935 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3936 @deftypefn {} {@var{val} =} fixed_point_format ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3937 @deftypefnx {} {@var{old_val} =} fixed_point_format (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3938 @deftypefnx {} {} fixed_point_format (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3939 Query or set the internal variable that controls whether Octave will
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3940 use a scaled format to print matrix values.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3941
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3942 The scaled format prints a scaling factor on the first line of output chosen
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3943 such that the largest matrix element can be written with a single leading
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3944 digit. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3945
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3946 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3947 @group
26205
cf037b842a9f doc: Clarify example code in fixed_point_format documentation (bug #55208).
Rik <rik@octave.org>
parents: 26111
diff changeset
3948 fixed_point_format (true)
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3949 logspace (1, 7, 5)'
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3950 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3951
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3952 1.0e+07 *
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3953
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3954 0.00000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3955 0.00003
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3956 0.00100
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3957 0.03162
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3958 1.00000
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3959 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3960 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3961
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3962 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3963 Notice that the first value appears to be 0 when it is actually 1. Because
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3964 of the possibility for confusion you should be careful about enabling
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3965 @code{fixed_point_format}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3967 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3968 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3969 The original variable value is restored when exiting the function.
24784
4d945f2e5914 eliminate output_max_field width; limit output precision (bug #53167)
John W. Eaton <jwe@octave.org>
parents: 24782
diff changeset
3970 @seealso{format, output_precision}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3971 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3972 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3973 return SET_INTERNAL_VARIABLE (fixed_point_format);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3974 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3975
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
3976 DEFUN (print_empty_dimensions, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3977 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3978 @deftypefn {} {@var{val} =} print_empty_dimensions ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3979 @deftypefnx {} {@var{old_val} =} print_empty_dimensions (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3980 @deftypefnx {} {} print_empty_dimensions (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3981 Query or set the internal variable that controls whether the dimensions of
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3982 empty matrices are printed along with the empty matrix symbol, @samp{[]}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3983
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3984 For example, the expression
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3985
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3986 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3987 zeros (3, 0)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3988 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3989
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3990 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3991 will print
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3992
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3993 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3994 ans = [](3x0)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3995 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3996
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3997 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3998 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
3999 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4000 @seealso{format}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4001 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4002 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4003 return SET_INTERNAL_VARIABLE (print_empty_dimensions);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4004 }
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4005
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4006 DEFUN (split_long_rows, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4007 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4008 @deftypefn {} {@var{val} =} split_long_rows ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4009 @deftypefnx {} {@var{old_val} =} split_long_rows (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4010 @deftypefnx {} {} split_long_rows (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4011 Query or set the internal variable that controls whether rows of a matrix
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4012 may be split when displayed to a terminal window.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4013
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4014 If the rows are split, Octave will display the matrix in a series of smaller
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4015 pieces, each of which can fit within the limits of your terminal width and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4016 each set of rows is labeled so that you can easily see which columns are
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4017 currently being displayed. For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4018
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4019 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4020 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4021 octave:13> rand (2,10)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4022 ans =
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4023
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4024 Columns 1 through 6:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4025
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4026 0.75883 0.93290 0.40064 0.43818 0.94958 0.16467
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4027 0.75697 0.51942 0.40031 0.61784 0.92309 0.40201
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4028
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4029 Columns 7 through 10:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4030
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4031 0.90174 0.11854 0.72313 0.73326
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4032 0.44672 0.94303 0.56564 0.82150
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4033 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4034 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4035
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4036 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4037 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4038 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4039 @seealso{format}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21942
diff changeset
4040 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4041 {
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4042 return SET_INTERNAL_VARIABLE (split_long_rows);
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
4043 }