Mercurial > octave
annotate libinterp/corefcn/pr-output.cc @ 24760:b784d68f7c44
fix printing of logical values (bug #53160)
* pr-output.h, pr-output.cc (make_format): Provide specialization for
boolNDArray objects.
(octave_print_internal): Define more consistently.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 14 Feb 2018 23:28:40 -0500 |
parents | 6114be517240 |
children | d7c3918955e6 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 1993-2017 John W. Eaton |
1 | 4 |
5 This file is part of Octave. | |
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 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 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 | 20 |
21 */ | |
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 | 25 #endif |
26 | |
23662
bd77ab816e43
eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents:
23619
diff
changeset
|
27 #include <cmath> |
bd77ab816e43
eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents:
23619
diff
changeset
|
28 |
3503 | 29 #include <iomanip> |
30 #include <iostream> | |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
31 #include <limits> |
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
32 #include <list> |
5765 | 33 #include <sstream> |
1728 | 34 #include <string> |
35 | |
4655 | 36 #include "Array-util.h" |
453 | 37 #include "CMatrix.h" |
1 | 38 #include "Range.h" |
2926 | 39 #include "cmd-edit.h" |
1352 | 40 #include "dMatrix.h" |
2891 | 41 #include "lo-mappers.h" |
2317 | 42 #include "mach-info.h" |
1651 | 43 #include "oct-cmplx.h" |
4153 | 44 #include "quit.h" |
1 | 45 |
3933 | 46 #include "Cell.h" |
1352 | 47 #include "defun.h" |
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 | 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 | 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 | 56 #include "pr-output.h" |
1282 | 57 #include "sysdep.h" |
6803 | 58 #include "unwind-prot.h" |
1 | 59 #include "utils.h" |
1352 | 60 #include "variables.h" |
1 | 61 |
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 | 64 static bool Vfixed_point_format = false; |
3105 | 65 |
5360 | 66 // TRUE means that the dimensions of empty objects should be printed |
2165 | 67 // like this: x = [](2x0). |
5794 | 68 bool Vprint_empty_dimensions = true; |
2165 | 69 |
70 // TRUE means that the rows of big matrices should be split into | |
71 // smaller slices that fit on the screen. | |
5794 | 72 static bool Vsplit_long_rows = true; |
2165 | 73 |
3018 | 74 // TRUE means don't do any fancy formatting. |
2387 | 75 static bool free_format = false; |
1 | 76 |
3018 | 77 // TRUE means print plus sign for nonzero, blank for zero. |
2387 | 78 static bool plus_format = false; |
1 | 79 |
4632 | 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 | 82 |
6788 | 83 // TRUE means always print in a rational approximation |
84 static bool rat_format = false; | |
85 | |
86 // Used to force the length of the rational approximation string for Frats | |
87 static int rat_string_len = -1; | |
88 | |
3018 | 89 // TRUE means always print like dollars and cents. |
2387 | 90 static bool bank_format = false; |
1282 | 91 |
3018 | 92 // TRUE means print data in hexadecimal format. |
3608 | 93 static int hex_format = 0; |
1282 | 94 |
3018 | 95 // TRUE means print data in binary-bit-pattern format. |
1309 | 96 static int bit_format = 0; |
97 | |
3018 | 98 // TRUE means don't put newlines around the column number headers. |
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 | 100 |
3018 | 101 // TRUE means use an e format. |
2387 | 102 static bool print_e = false; |
1 | 103 |
4509 | 104 // TRUE means use a g format. |
105 static bool print_g = false; | |
106 | |
3018 | 107 // TRUE means print E instead of e for exponent field. |
2387 | 108 static bool print_big_e = false; |
1 | 109 |
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 | 120 |
121 // The expression above is equivalent to x - (x % 3). | |
122 | |
123 // According to the ISO specification for C++ the modulo operator is | |
124 // compiler dependent if any of the arguments are negative. Since | |
125 // this function will need to work on negative arguments, and we want | |
126 // to avoid portability issues, we re-implement the modulo function to | |
127 // the desired behavior (truncation). There may be a gnulib | |
128 // replacement. | |
129 | |
130 // ISO/IEC 14882:2003 : Programming languages -- C++. 5.6.4: ISO, | |
131 // IEC. 2003 . "the binary % operator yields the remainder from the | |
132 // division of the first expression by the second. .... If both | |
133 // operands are nonnegative then the remainder is nonnegative; if not, | |
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 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
137 static int |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
138 engineering_exponent (double x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
139 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
140 int ex = 0; |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
141 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
142 if (x != 0) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
143 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
144 double absval = (x < 0.0 ? -x : x); |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
145 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
|
146 |
20946 | 147 // Avoid using modulo function with negative arguments for |
148 // 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
|
149 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
150 if (logabsval < 0.0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
151 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
|
152 else |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
153 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
|
154 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
155 |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
156 return ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
157 } |
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 static int |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
160 num_digits (const double& x) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
161 { |
11450
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
162 return 1 + (print_eng |
5eb10763069f
substitute and use LAPACK_LIBS in mkoctfile script
John W. Eaton <jwe@octave.org>
parents:
10987
diff
changeset
|
163 ? engineering_exponent (x) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
164 : 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
|
165 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
166 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
167 int |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
168 pr_engineering_float::exponent (void) const |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
169 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
170 return engineering_exponent (m_val); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
171 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
172 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
173 double |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
174 pr_engineering_float::mantissa (void) const |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
175 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
176 return m_val / std::pow (10.0, exponent ()); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
177 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
178 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
179 std::ostream& |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
180 operator << (std::ostream& os, const pr_engineering_float& pef) |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
181 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
182 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
|
183 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
184 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
|
185 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
186 if (real_fmt.fw >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
187 os << std::setw (real_fmt.fw - real_fmt.ex); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
188 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
189 if (real_fmt.prec >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
190 os << std::setprecision (real_fmt.prec); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
191 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
192 os.flags (static_cast<std::ios::fmtflags> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
193 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); |
10771
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
194 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
195 os << pef.mantissa (); |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
196 |
82d9efde7e96
pr-output.cc: Avoid use of % operator on negative operands
Rik <octave@nomad.inbox5.com>
parents:
10741
diff
changeset
|
197 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
|
198 if (ex < 0) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
199 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
200 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
|
201 ex = -ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
202 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
203 else |
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 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
206 os << std::setw (real_fmt.ex - 2) << 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
|
207 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
208 return os; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
209 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
210 |
3608 | 211 std::ostream& |
212 operator << (std::ostream& os, const pr_formatted_float& pff) | |
213 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
214 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
|
215 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
216 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
|
217 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
218 if (real_fmt.fw >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
219 os << std::setw (real_fmt.fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
220 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
221 if (real_fmt.prec >= 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
222 os << std::setprecision (real_fmt.prec); |
3608 | 223 |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
224 os.flags (static_cast<std::ios::fmtflags> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
225 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
226 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
227 os << pff.m_val; |
3608 | 228 |
229 return os; | |
230 } | |
231 | |
6788 | 232 static inline std::string |
233 rational_approx (double val, int len) | |
234 { | |
235 std::string s; | |
236 | |
237 if (len <= 0) | |
238 len = 10; | |
239 | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
240 if (octave::math::isinf (val)) |
6788 | 241 s = "1/0"; |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
242 else if (octave::math::isnan (val)) |
6788 | 243 s = "0/0"; |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
244 else if (val < std::numeric_limits<int>::min () |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15213
diff
changeset
|
245 || val > std::numeric_limits<int>::max () |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
246 || octave::math::x_nint (val) == val) |
6788 | 247 { |
248 std::ostringstream buf; | |
249 buf.flags (std::ios::fixed); | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
250 buf << std::setprecision (0) << octave::math::round (val); |
6788 | 251 s = buf.str (); |
252 } | |
253 else | |
254 { | |
255 double lastn = 1.; | |
256 double lastd = 0.; | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
257 double n = octave::math::round (val); |
6788 | 258 double d = 1.; |
259 double frac = val - n; | |
260 int m = 0; | |
261 | |
262 std::ostringstream buf2; | |
263 buf2.flags (std::ios::fixed); | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
264 buf2 << std::setprecision (0) << static_cast<int> (n); |
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
|
265 s = buf2.str (); |
6788 | 266 |
267 while (1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
268 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
269 double flip = 1. / frac; |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
270 double step = octave::math::round (flip); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
271 double nextn = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
272 double nextd = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
273 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
274 // Have we converged to 1/intmax ? |
21747
61f3575250e4
rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents:
21743
diff
changeset
|
275 if (std::abs (flip) > static_cast<double> (std::numeric_limits<int>::max ())) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
277 lastn = n; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
278 lastd = d; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 } |
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 frac = flip - step; |
20230
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
283 n = step * n + lastn; |
e914b5399c67
Use in-place operators in C++ code where possible.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
284 d = step * d + lastd; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
285 lastn = nextn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 lastd = nextd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
288 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
289 buf.flags (std::ios::fixed); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
290 buf << std::setprecision (0) << static_cast<int> (n) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
291 << '/' << static_cast<int> (d); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
292 m++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
293 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
294 if (n < 0 && d < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
295 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
296 // Double negative, string can be two characters longer.. |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
297 if (buf.str ().length () > static_cast<unsigned int> (len + 2)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
298 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
299 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
300 else if (buf.str ().length () > static_cast<unsigned int> (len)) |
19363
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
301 break; |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
302 |
21747
61f3575250e4
rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents:
21743
diff
changeset
|
303 if (std::abs (n) > std::numeric_limits<int>::max () |
61f3575250e4
rats: Fix round-off corner case for 32-bit systems (bug #47964)
Mike Miller <mtmiller@octave.org>
parents:
21743
diff
changeset
|
304 || std::abs (d) > std::numeric_limits<int>::max ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 |
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
|
307 s = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 } |
6788 | 309 |
310 if (lastd < 0.) | |
10315
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 // Move sign to the top |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 lastd = - lastd; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 lastn = - lastn; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
316 buf.flags (std::ios::fixed); |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
317 buf << std::setprecision (0) << static_cast<int> (lastn) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
318 << '/' << static_cast<int> (lastd); |
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
|
319 s = buf.str (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
320 } |
6788 | 321 } |
322 | |
323 return s; | |
324 } | |
325 | |
19363
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
326 /* |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
327 %!assert (rats (2.0005, 9), "4001/2000") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
328 %!assert (rats (-2.0005, 10), "-4001/2000") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
329 %!assert (strtrim (rats (2.0005, 30)), "4001/2000") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
330 %!assert (pi - str2num (rats (pi, 30)), 0, 4 * eps) |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
331 %!assert (e - str2num (rats (e, 30)), 0, 4 * eps) |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
332 %!assert (rats (123, 2), " *") |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
333 |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
334 %!test |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
335 %! v = 1 / double (intmax); |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
336 %! err = v - str2num (rats(v, 12)); |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
337 %! assert (err, 0, 4 * eps); |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
338 */ |
c490eac28bbb
pr-output.cc: Fix overflow in rational_approx (bug #43367..43369)
Andreas Weber <andy.weber.aw@gmail.com>
parents:
18433
diff
changeset
|
339 |
6788 | 340 std::ostream& |
341 operator << (std::ostream& os, const pr_rational_float& prf) | |
342 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
343 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
|
344 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
345 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
|
346 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
347 int fw = (rat_string_len > 0 ? rat_string_len : real_fmt.fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
348 std::string s = rational_approx (prf.m_val, fw); |
6788 | 349 |
350 if (fw >= 0) | |
351 os << std::setw (fw); | |
352 | |
17818
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
353 os.flags (static_cast<std::ios::fmtflags> |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
354 (real_fmt.fmt | real_fmt.up | real_fmt.sp)); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
355 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
356 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
|
357 os << '*'; |
6788 | 358 else |
359 os << s; | |
360 | |
361 return os; | |
362 } | |
363 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
364 // Current format for floating point numbers. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
365 static float_display_format curr_float_display_fmt; |
1309 | 366 |
1 | 367 static double |
164 | 368 pr_max_internal (const Matrix& m) |
1 | 369 { |
5275 | 370 octave_idx_type nr = m.rows (); |
371 octave_idx_type nc = m.columns (); | |
1 | 372 |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
373 double result = -std::numeric_limits<double>::max (); |
1 | 374 |
5748 | 375 bool all_inf_or_nan = true; |
376 | |
5275 | 377 for (octave_idx_type j = 0; j < nc; j++) |
378 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 379 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
380 double val = m(i,j); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
381 if (! octave::math::isfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
382 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
383 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
384 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
385 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
386 if (val > result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
387 result = val; |
1 | 388 } |
3608 | 389 |
5748 | 390 if (all_inf_or_nan) |
391 result = 0.0; | |
392 | |
1 | 393 return result; |
394 } | |
395 | |
396 static double | |
164 | 397 pr_min_internal (const Matrix& m) |
1 | 398 { |
5275 | 399 octave_idx_type nr = m.rows (); |
400 octave_idx_type nc = m.columns (); | |
1 | 401 |
15213
336f42406671
use numeric_limits functions instead of DBL_MIN, DBL_MAX, etc.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
402 double result = std::numeric_limits<double>::max (); |
1 | 403 |
5748 | 404 bool all_inf_or_nan = true; |
405 | |
5275 | 406 for (octave_idx_type j = 0; j < nc; j++) |
407 for (octave_idx_type i = 0; i < nr; i++) | |
1 | 408 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
409 double val = m(i,j); |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
410 if (! octave::math::isfinite (val)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
411 continue; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
412 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
413 all_inf_or_nan = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
414 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
415 if (val < result) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
416 result = val; |
1 | 417 } |
3608 | 418 |
5748 | 419 if (all_inf_or_nan) |
420 result = 0.0; | |
421 | |
1 | 422 return result; |
423 } | |
424 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
425 // FIXME: it would be nice to share more code among these functions,.. |
1658 | 426 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
427 static float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
428 make_real_format (int digits, bool inf_or_nan, bool int_only, int& fw) |
1 | 429 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
430 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
431 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
432 int prec = output_precision (); |
1 | 433 |
434 int ld, rd; | |
435 | |
6788 | 436 if (rat_format) |
437 { | |
438 fw = 0; | |
439 rd = 0; | |
440 } | |
441 else if (bank_format) | |
1 | 442 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
443 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
|
444 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
|
445 fw = 5; |
1 | 446 rd = 2; |
447 } | |
1282 | 448 else if (hex_format) |
449 { | |
450 fw = 2 * sizeof (double); | |
451 rd = 0; | |
452 } | |
1309 | 453 else if (bit_format) |
454 { | |
455 fw = 8 * sizeof (double); | |
456 rd = 0; | |
457 } | |
3611 | 458 else if (inf_or_nan || int_only) |
1 | 459 { |
5832 | 460 fw = 1 + digits; |
5748 | 461 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
462 fw = 4; |
3682 | 463 rd = fw; |
1 | 464 } |
465 else | |
466 { | |
467 if (digits > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
468 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
469 ld = digits; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
470 rd = (prec > digits ? prec - digits : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
471 } |
1 | 472 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
473 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
474 ld = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
475 rd = (prec > digits ? prec - digits : prec); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
476 } |
1 | 477 |
5832 | 478 fw = 1 + ld + 1 + rd; |
5748 | 479 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
480 fw = 4; |
1 | 481 } |
482 | |
6788 | 483 if (! (rat_format || bank_format || hex_format || bit_format) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
484 && (fw > output_max_field_width () || print_e || print_g || print_eng)) |
1 | 485 { |
4509 | 486 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
487 fmt = float_format (); |
4509 | 488 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
490 // e+ddd |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
491 int ex = 5; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
492 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
493 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
494 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
495 // -ddd. |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
496 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
|
497 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
|
498 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
499 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
|
500 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
501 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
502 { |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
503 // -d. |
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
504 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
|
505 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
|
506 fw = 4; |
16339
0c340bf413d7
allow exponent in output to always have 3 digits
John W. Eaton <jwe@octave.org>
parents:
16169
diff
changeset
|
507 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
|
508 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 } |
3608 | 510 |
1 | 511 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
512 fmt.uppercase (); |
1 | 513 } |
5086 | 514 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 515 fmt = float_format (fw, rd); |
1 | 516 else |
3608 | 517 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 518 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
519 return float_display_format (fmt); |
1 | 520 } |
521 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
522 float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
523 make_format (double d, int& fw) |
1658 | 524 { |
525 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
526 return float_display_format (); |
1658 | 527 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
528 bool inf_or_nan = (octave::math::isinf (d) || octave::math::isnan (d)); |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
529 |
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
530 bool int_only = (! inf_or_nan && octave::math::x_nint (d) == d); |
1658 | 531 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
532 double d_abs = (d < 0.0 ? -d : d); |
1658 | 533 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
534 int digits = (inf_or_nan || d_abs == 0.0) ? 0 : num_digits (d_abs); |
1658 | 535 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
536 return make_real_format (digits, inf_or_nan, int_only, fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
537 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
538 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
539 static void |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
540 set_format (double d, int& fw) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
541 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
542 curr_float_display_fmt = make_format (d, fw); |
1658 | 543 } |
544 | |
1 | 545 static inline void |
546 set_format (double d) | |
547 { | |
548 int fw; | |
549 set_format (d, fw); | |
550 } | |
551 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
552 static float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
553 make_real_matrix_format (int x_max, int x_min, bool inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
554 int int_or_inf_or_nan, int& fw) |
1 | 555 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
556 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
557 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
558 int prec = output_precision (); |
1 | 559 |
560 int ld, rd; | |
561 | |
6788 | 562 if (rat_format) |
563 { | |
564 fw = 9; | |
565 rd = 0; | |
566 } | |
567 else if (bank_format) | |
1 | 568 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
569 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
|
570 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
|
571 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
|
572 fw = 5; |
1 | 573 rd = 2; |
574 } | |
1282 | 575 else if (hex_format) |
576 { | |
577 fw = 2 * sizeof (double); | |
578 rd = 0; | |
579 } | |
1309 | 580 else if (bit_format) |
581 { | |
582 fw = 8 * sizeof (double); | |
583 rd = 0; | |
584 } | |
4509 | 585 else if (Vfixed_point_format && ! print_g) |
3268 | 586 { |
587 rd = prec; | |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
588 fw = rd + 3; |
5748 | 589 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
590 fw = 4; |
3268 | 591 } |
1715 | 592 else if (int_or_inf_or_nan) |
1 | 593 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
594 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
|
595 fw = (digits <= 0 ? 2 : digits + 1); |
5748 | 596 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
597 fw = 4; |
3682 | 598 rd = fw; |
1 | 599 } |
600 else | |
601 { | |
602 int ld_max, rd_max; | |
603 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
604 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
605 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
606 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
|
607 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
608 } |
1 | 609 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
610 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
611 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
612 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
|
613 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
614 } |
1 | 615 |
616 int ld_min, rd_min; | |
617 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
618 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
619 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
620 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
|
621 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
622 } |
1 | 623 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
624 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
625 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
626 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
|
627 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
628 } |
1 | 629 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
630 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
|
631 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 632 |
5832 | 633 fw = 1 + ld + 1 + rd; |
5748 | 634 if (inf_or_nan && fw < 4) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
635 fw = 4; |
1 | 636 } |
637 | |
6788 | 638 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 639 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
640 || print_eng || print_g |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
641 || (! Vfixed_point_format && fw > output_max_field_width ()))) |
1 | 642 { |
4509 | 643 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
644 fmt = float_format (); |
4509 | 645 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
646 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
647 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
648 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
|
649 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
650 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
651 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
652 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
653 fw = 4 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
654 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
|
655 fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
656 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
|
657 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
658 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
659 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
660 fw = 2 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
661 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
|
662 fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
663 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
|
664 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
665 } |
3608 | 666 |
1 | 667 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
668 fmt.uppercase (); |
1 | 669 } |
5086 | 670 else if (! bank_format && int_or_inf_or_nan) |
3611 | 671 fmt = float_format (fw, rd); |
1 | 672 else |
3608 | 673 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 674 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
675 return float_display_format (fmt); |
1 | 676 } |
677 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
678 float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
679 make_format (const Matrix& m, int& fw, double& scale) |
1658 | 680 { |
681 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
682 return float_display_format (); |
1658 | 683 |
2387 | 684 bool inf_or_nan = m.any_element_is_inf_or_nan (); |
1658 | 685 |
2387 | 686 bool int_or_inf_or_nan = m.all_elements_are_int_or_inf_or_nan (); |
1658 | 687 |
2387 | 688 Matrix m_abs = m.abs (); |
1658 | 689 double max_abs = pr_max_internal (m_abs); |
690 double min_abs = pr_min_internal (m_abs); | |
691 | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
692 int x_max = (max_abs == 0.0 ? 0 : num_digits (max_abs)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
693 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
694 int x_min = (min_abs == 0.0 ? 0 : num_digits (min_abs)); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
695 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
696 scale = (x_max == 0 || int_or_inf_or_nan) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
697 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 698 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
699 return make_real_matrix_format (x_max, x_min, inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
700 int_or_inf_or_nan, fw); |
1658 | 701 } |
702 | |
1 | 703 static void |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
704 set_format (const Matrix& m, int& fw, double& scale) |
1 | 705 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
706 curr_float_display_fmt = make_format (m, fw, scale); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
707 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
708 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
709 static float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
710 make_complex_format (int x_max, int x_min, int r_x, bool inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
711 int int_only, int& r_fw, int& i_fw) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
712 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
713 float_format r_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
714 float_format i_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
715 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
716 int prec = output_precision (); |
1 | 717 |
718 int ld, rd; | |
719 | |
6788 | 720 if (rat_format) |
721 { | |
722 i_fw = 0; | |
723 r_fw = 0; | |
724 rd = 0; | |
725 } | |
726 else if (bank_format) | |
1 | 727 { |
728 int digits = r_x; | |
729 i_fw = 0; | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
730 r_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
|
731 if (inf_or_nan && r_fw < 5) |
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
732 r_fw = 5; |
1 | 733 rd = 2; |
734 } | |
1282 | 735 else if (hex_format) |
736 { | |
737 r_fw = 2 * sizeof (double); | |
738 i_fw = 2 * sizeof (double); | |
739 rd = 0; | |
740 } | |
1309 | 741 else if (bit_format) |
742 { | |
743 r_fw = 8 * sizeof (double); | |
744 i_fw = 8 * sizeof (double); | |
745 rd = 0; | |
746 } | |
1658 | 747 else if (inf_or_nan || int_only) |
1 | 748 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
749 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
|
750 i_fw = (digits <= 0 ? 1 : digits); |
5945 | 751 r_fw = i_fw + 1; |
752 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
753 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
754 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
755 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
756 } |
3682 | 757 rd = r_fw; |
1 | 758 } |
759 else | |
760 { | |
761 int ld_max, rd_max; | |
762 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
764 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
765 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
|
766 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
767 } |
1 | 768 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
769 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
770 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
771 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
|
772 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
773 } |
1 | 774 |
775 int ld_min, rd_min; | |
776 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
777 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
778 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
779 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
|
780 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
781 } |
1 | 782 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
783 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
784 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
785 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
|
786 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
787 } |
1 | 788 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
789 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
|
790 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 791 |
5945 | 792 i_fw = ld + 1 + rd; |
793 r_fw = i_fw + 1; | |
794 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
795 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
796 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
797 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
798 } |
1 | 799 } |
800 | |
6788 | 801 if (! (rat_format || bank_format || hex_format || bit_format) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
802 && (r_fw > output_max_field_width () || print_e || print_eng || print_g)) |
1 | 803 { |
4509 | 804 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
805 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
806 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
807 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
808 } |
4509 | 809 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
810 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
811 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
812 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
|
813 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
814 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
815 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
816 { |
21568
3d60ed163b70
maint: Eliminate bad spacing around '='.
Rik <rik@octave.org>
parents:
21547
diff
changeset
|
817 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
|
818 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
|
819 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
|
820 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
821 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
822 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
823 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
824 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
|
825 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
|
826 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
827 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
828 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
829 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
|
830 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
|
831 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
|
832 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
833 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
834 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
835 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
836 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
|
837 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
|
838 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
839 } |
3608 | 840 |
1 | 841 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
842 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
843 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
844 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
845 } |
1 | 846 } |
5086 | 847 else if (! bank_format && (inf_or_nan || int_only)) |
3611 | 848 { |
849 r_fmt = float_format (r_fw, rd); | |
850 i_fmt = float_format (i_fw, rd); | |
851 } | |
1 | 852 else |
853 { | |
3608 | 854 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
855 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 856 } |
857 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
858 return float_display_format (r_fmt, i_fmt); |
1 | 859 } |
860 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
861 float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
862 make_format (const Complex& c, int& r_fw, int& i_fw) |
1658 | 863 { |
864 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
865 return float_display_format (); |
1658 | 866 |
867 double rp = c.real (); | |
868 double ip = c.imag (); | |
869 | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
870 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
|
871 |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
872 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
|
873 && octave::math::x_nint (ip) == ip); |
1658 | 874 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
875 double r_abs = (rp < 0.0 ? -rp : rp); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
876 double i_abs = (ip < 0.0 ? -ip : ip); |
1658 | 877 |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
878 int r_x = (! octave::math::isfinite (rp) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
879 || r_abs == 0.0) ? 0 : num_digits (r_abs); |
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
880 |
23564
7049da1648c0
Deprecate octave::math::finite in favor of octave::math::isfinite.
Rik <rik@octave.org>
parents:
23534
diff
changeset
|
881 int i_x = (! octave::math::isfinite (ip) |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
882 || i_abs == 0.0) ? 0 : num_digits (i_abs); |
1658 | 883 |
884 int x_max, x_min; | |
885 | |
886 if (r_x > i_x) | |
887 { | |
888 x_max = r_x; | |
889 x_min = i_x; | |
890 } | |
891 else | |
892 { | |
893 x_max = i_x; | |
894 x_min = r_x; | |
895 } | |
896 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
897 return make_complex_format (x_max, x_min, r_x, inf_or_nan, int_only, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
898 r_fw, i_fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
899 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
900 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
901 static void |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
902 set_format (const Complex& c, int& r_fw, int& i_fw) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
903 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
904 if (free_format) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
905 curr_float_display_fmt = float_display_format (); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
906 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
907 curr_float_display_fmt = make_format (c, r_fw, i_fw); |
1658 | 908 } |
909 | |
1 | 910 static inline void |
164 | 911 set_format (const Complex& c) |
1 | 912 { |
913 int r_fw, i_fw; | |
914 set_format (c, r_fw, i_fw); | |
915 } | |
916 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
917 static float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
918 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
|
919 int r_x_min, bool inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
920 int int_or_inf_or_nan, int& r_fw, int& i_fw) |
1 | 921 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
922 float_format r_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
923 float_format i_fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
924 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
925 int prec = output_precision (); |
1 | 926 |
927 int ld, rd; | |
928 | |
6788 | 929 if (rat_format) |
930 { | |
931 i_fw = 9; | |
932 r_fw = 9; | |
933 rd = 0; | |
934 } | |
935 else if (bank_format) | |
1 | 936 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
937 int digits = (r_x_max > r_x_min ? r_x_max : r_x_min); |
1 | 938 i_fw = 0; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
939 r_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
|
940 if (inf_or_nan && r_fw < 5) |
3a0075793fcd
allow format bank to work for mixed +/- values
John W. Eaton <jwe@octave.org>
parents:
17818
diff
changeset
|
941 r_fw = 5; |
1 | 942 rd = 2; |
943 } | |
1282 | 944 else if (hex_format) |
945 { | |
946 r_fw = 2 * sizeof (double); | |
947 i_fw = 2 * sizeof (double); | |
948 rd = 0; | |
949 } | |
1309 | 950 else if (bit_format) |
951 { | |
952 r_fw = 8 * sizeof (double); | |
953 i_fw = 8 * sizeof (double); | |
954 rd = 0; | |
955 } | |
4509 | 956 else if (Vfixed_point_format && ! print_g) |
3268 | 957 { |
958 rd = prec; | |
5945 | 959 i_fw = rd + 1; |
960 r_fw = i_fw + 1; | |
961 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
962 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
963 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
964 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
965 } |
3268 | 966 } |
1715 | 967 else if (int_or_inf_or_nan) |
1 | 968 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
969 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
|
970 i_fw = (digits <= 0 ? 1 : digits); |
5945 | 971 r_fw = i_fw + 1; |
972 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
973 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
974 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
975 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
976 } |
3682 | 977 rd = r_fw; |
1 | 978 } |
979 else | |
980 { | |
981 int ld_max, rd_max; | |
982 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
983 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
984 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
985 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
|
986 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
987 } |
1 | 988 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
989 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
990 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
991 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
|
992 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
993 } |
1 | 994 |
995 int ld_min, rd_min; | |
996 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
997 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
998 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
999 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
|
1000 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1001 } |
1 | 1002 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1003 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1004 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1005 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
|
1006 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1007 } |
1 | 1008 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1009 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
|
1010 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 1011 |
5945 | 1012 i_fw = ld + 1 + rd; |
1013 r_fw = i_fw + 1; | |
1014 if (inf_or_nan && i_fw < 3) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1015 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1016 i_fw = 3; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1017 r_fw = 4; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1018 } |
1 | 1019 } |
1020 | |
6788 | 1021 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1022 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1023 || print_eng || print_g |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1024 || (! Vfixed_point_format && r_fw > output_max_field_width ()))) |
1 | 1025 { |
4509 | 1026 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1027 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1028 r_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1029 i_fmt = float_format (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1030 } |
4509 | 1031 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1032 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1033 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1034 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
|
1035 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1036 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1037 if (print_eng) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1038 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1039 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
|
1040 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
|
1041 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
|
1042 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1043 i_fw = 5; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1044 r_fw = 6; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1045 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1046 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
|
1047 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
|
1048 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1049 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1050 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1051 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
|
1052 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
|
1053 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
|
1054 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1055 i_fw = 3; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1056 r_fw = 4; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1057 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1058 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
|
1059 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
|
1060 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1061 } |
3608 | 1062 |
1 | 1063 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1064 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1065 r_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1066 i_fmt.uppercase (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1067 } |
1 | 1068 } |
5086 | 1069 else if (! bank_format && int_or_inf_or_nan) |
3611 | 1070 { |
1071 r_fmt = float_format (r_fw, rd); | |
1072 i_fmt = float_format (i_fw, rd); | |
1073 } | |
1 | 1074 else |
1075 { | |
3608 | 1076 r_fmt = float_format (r_fw, rd, std::ios::fixed); |
1077 i_fmt = float_format (i_fw, rd, std::ios::fixed); | |
1 | 1078 } |
1079 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1080 return float_display_format (r_fmt, i_fmt); |
1 | 1081 } |
1082 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1083 float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1084 make_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1658 | 1085 { |
1086 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1087 return float_display_format (); |
1658 | 1088 |
1089 Matrix rp = real (cm); | |
1090 Matrix ip = imag (cm); | |
1091 | |
2387 | 1092 bool inf_or_nan = cm.any_element_is_inf_or_nan (); |
1658 | 1093 |
2387 | 1094 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
|
1095 && ip.all_elements_are_int_or_inf_or_nan ()); |
1658 | 1096 |
2387 | 1097 Matrix r_m_abs = rp.abs (); |
1658 | 1098 double r_max_abs = pr_max_internal (r_m_abs); |
1099 double r_min_abs = pr_min_internal (r_m_abs); | |
1100 | |
2387 | 1101 Matrix i_m_abs = ip.abs (); |
1658 | 1102 double i_max_abs = pr_max_internal (i_m_abs); |
1103 double i_min_abs = pr_min_internal (i_m_abs); | |
1104 | |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1105 int r_x_max = (r_max_abs == 0.0 ? 0 : num_digits (r_max_abs)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1106 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1107 int r_x_min = (r_min_abs == 0.0 ? 0 : num_digits (r_min_abs)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1108 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1109 int i_x_max = (i_max_abs == 0.0 ? 0 : num_digits (i_max_abs)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1110 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1111 int i_x_min = (i_min_abs == 0.0 ? 0 : num_digits (i_min_abs)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1112 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1113 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
|
1114 int x_min = (r_x_min > i_x_min ? r_x_min : i_x_min); |
1658 | 1115 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1116 scale = (x_max == 0 || int_or_inf_or_nan) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1117 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 1118 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1119 return make_complex_matrix_format (x_max, x_min, r_x_max, r_x_min, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1120 inf_or_nan, int_or_inf_or_nan, |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1121 r_fw, i_fw); |
1658 | 1122 } |
1123 | |
1 | 1124 static void |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1125 set_format (const ComplexMatrix& cm, int& r_fw, int& i_fw, double& scale) |
1 | 1126 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1127 if (free_format) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1128 curr_float_display_fmt = float_display_format (); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1129 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1130 curr_float_display_fmt = make_format (cm, r_fw, i_fw, scale); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1131 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1132 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1133 static float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1134 make_range_format (int x_max, int x_min, int all_ints, int& fw) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1135 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1136 float_format fmt; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1137 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1138 int prec = output_precision (); |
1 | 1139 |
1140 int ld, rd; | |
1141 | |
6788 | 1142 if (rat_format) |
1143 { | |
1144 fw = 9; | |
1145 rd = 0; | |
1146 } | |
1147 else if (bank_format) | |
1 | 1148 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1149 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
|
1150 fw = (digits < 0 ? 5 : digits + 4); |
1 | 1151 rd = 2; |
1152 } | |
1282 | 1153 else if (hex_format) |
1154 { | |
1155 fw = 2 * sizeof (double); | |
1156 rd = 0; | |
1157 } | |
1309 | 1158 else if (bit_format) |
1159 { | |
1160 fw = 8 * sizeof (double); | |
1161 rd = 0; | |
1162 } | |
1658 | 1163 else if (all_ints) |
1 | 1164 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1165 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
|
1166 fw = digits + 1; |
3682 | 1167 rd = fw; |
1 | 1168 } |
4509 | 1169 else if (Vfixed_point_format && ! print_g) |
3105 | 1170 { |
1171 rd = prec; | |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1172 fw = rd + 3; |
3105 | 1173 } |
1 | 1174 else |
1175 { | |
1176 int ld_max, rd_max; | |
1177 if (x_max > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1178 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1179 ld_max = x_max; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1180 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
|
1181 x_max++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1182 } |
1 | 1183 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1184 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1185 ld_max = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1186 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
|
1187 x_max = -x_max + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1188 } |
1 | 1189 |
1190 int ld_min, rd_min; | |
1191 if (x_min > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1192 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1193 ld_min = x_min; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1194 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
|
1195 x_min++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1196 } |
1 | 1197 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1198 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1199 ld_min = 1; |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1200 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
|
1201 x_min = -x_min + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1202 } |
1 | 1203 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1204 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
|
1205 rd = (rd_max > rd_min ? rd_max : rd_min); |
1 | 1206 |
7465
8d6ab12f8fda
format Range output more like N-d arrays
John W. Eaton <jwe@octave.org>
parents:
7231
diff
changeset
|
1207 fw = ld + rd + 3; |
1 | 1208 } |
1209 | |
6788 | 1210 if (! (rat_format || bank_format || hex_format || bit_format) |
3105 | 1211 && (print_e |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1212 || print_eng || print_g |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1213 || (! Vfixed_point_format && fw > output_max_field_width ()))) |
1 | 1214 { |
4509 | 1215 if (print_g) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1216 fmt = float_format (); |
4509 | 1217 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1218 { |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1219 int ex = 4; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1220 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
|
1221 ex++; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1222 |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1223 if (print_eng) |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1224 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1225 fw = 5 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1226 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
|
1227 } |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1228 else |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1229 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1230 fw = 3 + prec + ex; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1231 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
|
1232 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1233 } |
3608 | 1234 |
1 | 1235 if (print_big_e) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1236 fmt.uppercase (); |
1 | 1237 } |
5086 | 1238 else if (! bank_format && all_ints) |
3611 | 1239 fmt = float_format (fw, rd); |
1 | 1240 else |
3608 | 1241 fmt = float_format (fw, rd, std::ios::fixed); |
1 | 1242 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1243 return float_display_format (fmt); |
1 | 1244 } |
1245 | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1246 float_display_format |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1247 make_format (const Range& r, int& fw, double& scale) |
1658 | 1248 { |
1249 if (free_format) | |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1250 return float_display_format (); |
1658 | 1251 |
1252 double r_min = r.base (); | |
1253 double r_max = r.limit (); | |
1254 | |
1255 if (r_max < r_min) | |
1256 { | |
1257 double tmp = r_max; | |
1258 r_max = r_min; | |
1259 r_min = tmp; | |
1260 } | |
1261 | |
2387 | 1262 bool all_ints = r.all_elements_are_ints (); |
1658 | 1263 |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1264 double max_abs = (r_max < 0.0 ? -r_max : r_max); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1265 double min_abs = (r_min < 0.0 ? -r_min : r_min); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1266 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1267 int x_max = (max_abs == 0.0 ? 0 : num_digits (max_abs)); |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1268 |
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1269 int x_min = (min_abs == 0.0 ? 0 : num_digits (min_abs)); |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
1270 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1271 scale = (x_max == 0 || all_ints) |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
1272 ? 1.0 : std::pow (10.0, calc_scale_exp (x_max - 1)); |
3105 | 1273 |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1274 return make_range_format (x_max, x_min, all_ints, fw); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1275 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1276 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1277 static void |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1278 set_format (const Range& r, int& fw, double& scale) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1279 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1280 curr_float_display_fmt = make_format (r, fw, scale); |
1658 | 1281 } |
1282 | |
1282 | 1283 union equiv |
1284 { | |
1285 double d; | |
1286 unsigned char i[sizeof (double)]; | |
1287 }; | |
1288 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1289 #define PRINT_CHAR_BITS(os, c) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1290 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1291 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1292 unsigned char ctmp = c; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1293 char stmp[9]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1294 stmp[0] = (ctmp & 0x80) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1295 stmp[1] = (ctmp & 0x40) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1296 stmp[2] = (ctmp & 0x20) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1297 stmp[3] = (ctmp & 0x10) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1298 stmp[4] = (ctmp & 0x08) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1299 stmp[5] = (ctmp & 0x04) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1300 stmp[6] = (ctmp & 0x02) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1301 stmp[7] = (ctmp & 0x01) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1302 stmp[8] = '\0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1303 os << stmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1304 } \ |
1309 | 1305 while (0) |
1306 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1307 #define PRINT_CHAR_BITS_SWAPPED(os, c) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1308 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1309 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1310 unsigned char ctmp = c; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1311 char stmp[9]; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1312 stmp[0] = (ctmp & 0x01) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1313 stmp[1] = (ctmp & 0x02) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1314 stmp[2] = (ctmp & 0x04) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1315 stmp[3] = (ctmp & 0x08) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1316 stmp[4] = (ctmp & 0x10) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1317 stmp[5] = (ctmp & 0x20) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1318 stmp[6] = (ctmp & 0x40) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1319 stmp[7] = (ctmp & 0x80) ? '1' : '0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1320 stmp[8] = '\0'; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1321 os << stmp; \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
1322 } \ |
1309 | 1323 while (0) |
1324 | |
2522 | 1325 static void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1326 pr_any_float (std::ostream& os, const float_format& fmt, double d, int fw = 0) |
1 | 1327 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1328 // 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
|
1329 // for hex and bit formats. |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1330 // |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1331 // {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
|
1332 // {bit,hex}_format == 2: print native |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1333 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1334 if (hex_format) |
1 | 1335 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1336 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
|
1337 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1338 equiv tmp; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1339 tmp.d = d; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1340 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1341 // 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
|
1342 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1343 // 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
|
1344 // 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
|
1345 // character? |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1346 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1347 octave::mach_info::float_format flt_fmt = |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1348 octave::mach_info::native_float_format (); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1349 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1350 os.fill ('0'); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1351 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
|
1352 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1353 if (hex_format > 1 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1354 || 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
|
1355 { |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1356 for (size_t i = 0; i < sizeof (double); i++) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1357 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
|
1358 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1359 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1360 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1361 for (int i = sizeof (double) - 1; i >= 0; i--) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1362 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
|
1363 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1364 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1365 else if (bit_format) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1366 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1367 equiv tmp; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1368 tmp.d = d; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1369 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1370 octave::mach_info::float_format flt_fmt = |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1371 octave::mach_info::native_float_format (); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1372 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1373 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
|
1374 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1375 for (size_t i = 0; i < sizeof (double); i++) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1376 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
|
1377 } |
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 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1380 if (bit_format > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1381 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1382 for (size_t i = 0; i < sizeof (double); i++) |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1383 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
|
1384 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1385 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1386 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1387 for (int i = sizeof (double) - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1388 PRINT_CHAR_BITS (os, tmp.i[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1389 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1390 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1391 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1392 else if (octave::math::isna (d)) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1393 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1394 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
|
1395 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1396 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1397 os << std::setw (fw) << "NA"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1398 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1399 os << "NA"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1400 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1401 else if (rat_format) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1402 os << pr_rational_float (fmt, d); |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1403 else if (octave::math::isinf (d)) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1404 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1405 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
|
1406 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1407 const char *s; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1408 if (d < 0.0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1409 s = "-Inf"; |
1 | 1410 else |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1411 s = "Inf"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1412 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1413 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1414 os << std::setw (fw) << s; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1415 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1416 os << s; |
1 | 1417 } |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1418 else if (octave::math::isnan (d)) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1419 { |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1420 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
|
1421 |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1422 if (fw > 0) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1423 os << std::setw (fw) << "NaN"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1424 else |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1425 os << "NaN"; |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1426 } |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1427 else if (print_eng) |
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1428 os << pr_engineering_float (fmt, d); |
529 | 1429 else |
24667
56f889d66b7c
move float_format container to setparate file
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1430 os << pr_formatted_float (fmt, d); |
1 | 1431 } |
1432 | |
1433 static inline void | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1434 pr_float (std::ostream& os, const float_display_format& fmt, double d, |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1435 int fw = 0, double scale = 1.0) |
1 | 1436 { |
4509 | 1437 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3608 | 1438 d /= scale; |
1439 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1440 pr_any_float (os, fmt.real_format (), d, fw); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1441 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1442 |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1443 static inline void |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1444 pr_float (std::ostream& os, double d, int fw = 0, double scale = 1.0) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1445 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1446 pr_float (os, curr_float_display_fmt, d, fw, scale); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1447 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1448 |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1449 static inline void |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1450 pr_imag_float (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
|
1451 double d, int fw = 0) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1452 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1453 pr_any_float (os, fmt.imag_format (), d, fw); |
1 | 1454 } |
1455 | |
1456 static inline void | |
3523 | 1457 pr_imag_float (std::ostream& os, double d, int fw = 0) |
1 | 1458 { |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1459 pr_imag_float (os, curr_float_display_fmt, d, fw); |
1 | 1460 } |
1461 | |
2522 | 1462 static void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1463 pr_complex (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
|
1464 const Complex& c, int r_fw = 0, int i_fw = 0, double scale = 1.0) |
1 | 1465 { |
4509 | 1466 Complex tmp |
1467 = (Vfixed_point_format && ! print_g && scale != 1.0) ? c / scale : c; | |
3608 | 1468 |
1469 double r = tmp.real (); | |
1470 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1471 pr_float (os, fmt, r, r_fw); |
3608 | 1472 |
1 | 1473 if (! bank_format) |
1474 { | |
3608 | 1475 double i = tmp.imag (); |
4349 | 1476 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
|
1477 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1478 os << " - "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1479 i = -i; |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1480 pr_imag_float (os, fmt, i, i_fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1481 } |
1 | 1482 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1483 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1484 if (hex_format || bit_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1485 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1486 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1487 os << " + "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1488 |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1489 pr_imag_float (os, fmt, i, i_fw); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1490 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1491 os << 'i'; |
1 | 1492 } |
1493 } | |
1494 | |
626 | 1495 static void |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1496 pr_complex (std::ostream& os, const Complex& c, int r_fw = 0, int i_fw = 0, |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1497 double scale = 1.0) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1498 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1499 pr_complex (os, curr_float_display_fmt, c, r_fw, i_fw, scale); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1500 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1501 |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1502 static void |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1503 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
|
1504 bool pr_as_read_syntax) |
626 | 1505 { |
1506 assert (nr == 0 || nc == 0); | |
1507 | |
1508 if (pr_as_read_syntax) | |
1509 { | |
1510 if (nr == 0 && nc == 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1511 os << "[]"; |
626 | 1512 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
1513 os << "zeros (" << nr << ", " << nc << ')'; |
626 | 1514 } |
1515 else | |
1516 { | |
1517 os << "[]"; | |
4559 | 1518 |
2165 | 1519 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
|
1520 os << '(' << nr << 'x' << nc << ')'; |
626 | 1521 } |
1522 } | |
1523 | |
1186 | 1524 static void |
4559 | 1525 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
|
1526 bool pr_as_read_syntax) |
4559 | 1527 { |
1528 assert (dims.any_zero ()); | |
1529 | |
1530 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
|
1531 os << "zeros (" << dims.str (',') << ')'; |
4559 | 1532 else |
1533 { | |
1534 os << "[]"; | |
1535 | |
1536 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
|
1537 os << '(' << dims.str () << ')'; |
4559 | 1538 } |
1539 } | |
1540 | |
1541 static void | |
3523 | 1542 pr_scale_header (std::ostream& os, double scale) |
3105 | 1543 { |
4509 | 1544 if (Vfixed_point_format && ! print_g && scale != 1.0) |
3105 | 1545 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1546 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
|
1547 |
3568 | 1548 os << " " |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1549 << std::setw (8) << std::setprecision (1) |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21583
diff
changeset
|
1550 << 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
|
1551 << scale |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1552 << "*\n"; |
3105 | 1553 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1554 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1555 os << "\n"; |
3105 | 1556 } |
1557 } | |
1558 | |
1559 static void | |
5275 | 1560 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
|
1561 octave_idx_type lim, octave_idx_type col, int extra_indent) |
1186 | 1562 { |
2165 | 1563 if (total_width > max_width && Vsplit_long_rows) |
1186 | 1564 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1565 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
|
1566 |
4833 | 1567 if (col != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1568 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1569 if (Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1570 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1571 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1572 os << "\n\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1573 } |
1186 | 1574 |
5275 | 1575 octave_idx_type num_cols = lim - col; |
1186 | 1576 |
3548 | 1577 os << std::setw (extra_indent) << ""; |
1972 | 1578 |
1186 | 1579 if (num_cols == 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1580 os << " Column " << col + 1 << ":\n"; |
1186 | 1581 else if (num_cols == 2) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1582 os << " Columns " << col + 1 << " and " << lim << ":\n"; |
1186 | 1583 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1584 os << " Columns " << col + 1 << " through " << lim << ":\n"; |
2915 | 1585 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
1586 if (! Vcompact_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1587 os << "\n"; |
1186 | 1588 } |
1589 } | |
1590 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
1591 template <typename T> |
6018 | 1592 /* static */ inline void |
5030 | 1593 pr_plus_format (std::ostream& os, const T& val) |
3248 | 1594 { |
5030 | 1595 if (val > T (0)) |
4632 | 1596 os << plus_format_chars[0]; |
5030 | 1597 else if (val < T (0)) |
4632 | 1598 os << plus_format_chars[1]; |
3248 | 1599 else |
4632 | 1600 os << plus_format_chars[2]; |
3248 | 1601 } |
1602 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1603 template <> |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1604 float_display_format |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1605 make_format (const Range& rng) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1606 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1607 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1608 double scale = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1609 return make_format (rng, fw, scale); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1610 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1611 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1612 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1613 float_display_format |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1614 make_format (const NDArray& nda) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1615 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1616 int fw = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1617 double scale = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1618 return make_format (Matrix (nda), fw, scale); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1619 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1620 |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1621 template <> |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1622 float_display_format |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1623 make_format (const FloatNDArray& nda) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1624 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1625 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1626 double scale = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1627 return make_format (FloatMatrix (nda), fw, scale); |
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 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1631 float_display_format |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1632 make_format (const ComplexNDArray& nda) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1633 { |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1634 int r_fw = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1635 int i_fw = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1636 double scale = 0; |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1637 return make_format (ComplexMatrix (nda), r_fw, i_fw, scale); |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1638 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1639 |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1640 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1641 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
|
1642 make_format (const FloatComplexNDArray& nda) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1643 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1644 int r_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1645 int i_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1646 double scale = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1647 return make_format (FloatComplexMatrix (nda), r_fw, i_fw, scale); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1648 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1649 |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1650 template <> |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1651 float_display_format |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1652 make_format (const boolNDArray&) |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1653 { |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1654 return float_display_format (float_format (1, 1)); |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1655 } |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1656 |
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
|
1657 // 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
|
1658 // |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1659 // 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
|
1660 // |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1661 // 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
|
1662 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1663 template <typename 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
|
1664 /* static */ inline 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
|
1665 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
|
1666 { |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1667 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
|
1668 } |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1669 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1670 #define INSTANTIATE_ABS(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
|
1671 template /* static */ T abs (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
|
1672 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1673 INSTANTIATE_ABS(signed char); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1674 INSTANTIATE_ABS(short); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1675 INSTANTIATE_ABS(int); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1676 INSTANTIATE_ABS(long); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1677 INSTANTIATE_ABS(long long); |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1678 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1679 #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
|
1680 template <> \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1681 /* static */ inline unsigned 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
|
1682 abs (unsigned 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
|
1683 { \ |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1684 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
|
1685 } |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1686 |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1687 SPECIALIZE_UABS(char) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1688 SPECIALIZE_UABS(short) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1689 SPECIALIZE_UABS(int) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1690 SPECIALIZE_UABS(long) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1691 SPECIALIZE_UABS(long long) |
6114be517240
* pr-output.cc: Move defn of specialized abs before first use (bug #53114)
John W. Eaton <jwe@octave.org>
parents:
24745
diff
changeset
|
1692 |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1693 #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
|
1694 template <> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1695 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
|
1696 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
|
1697 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1698 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
|
1699 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
|
1700 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1701 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
|
1702 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1703 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
|
1704 = static_cast<int> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1705 (std::floor (log10 (double (abs (nda(i).value ()))) + 1.0)); \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1706 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1707 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
|
1708 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
|
1709 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1710 if (! isneg) \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1711 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
|
1712 } \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1713 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1714 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
|
1715 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1716 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1717 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
|
1718 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
|
1719 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
|
1720 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
|
1721 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
|
1722 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
|
1723 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
|
1724 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
|
1725 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1726 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1727 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
|
1728 make_format (const double& d) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1729 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1730 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1731 return make_format (d, fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1732 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1733 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1734 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1735 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
|
1736 make_format (const float& f) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1737 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1738 int fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1739 return make_format (f, fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1740 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1741 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1742 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1743 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
|
1744 make_format (const Complex& c) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1745 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1746 int r_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1747 int i_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1748 return make_format (c, r_fw, i_fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1749 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1750 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1751 template <> |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1752 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
|
1753 make_format (const FloatComplex& c) |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1754 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1755 int r_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1756 int i_fw = 0; |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1757 return make_format (c, r_fw, i_fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1758 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1759 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1760 #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
|
1761 template <> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1762 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
|
1763 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
|
1764 { \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1765 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
|
1766 int digits \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1767 = static_cast<int> \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1768 (std::floor (log10 (double (abs (val.value ()))) + 1.0)); \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1769 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1770 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
|
1771 \ |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1772 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
|
1773 } |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1774 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
1775 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
|
1776 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
|
1777 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
|
1778 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
|
1779 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
|
1780 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
|
1781 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
|
1782 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
|
1783 |
1 | 1784 void |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1785 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
|
1786 bool d, bool pr_as_read_syntax) |
1 | 1787 { |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1788 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
|
1789 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1790 |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1791 void |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1792 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
|
1793 { |
24760
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1794 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
|
1795 } |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1796 |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1797 void |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1798 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
|
1799 char, bool) |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1800 { |
b784d68f7c44
fix printing of logical values (bug #53160)
John W. Eaton <jwe@octave.org>
parents:
24747
diff
changeset
|
1801 panic_impossible (); |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1802 } |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1803 |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1804 void |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1805 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
|
1806 double d, bool pr_as_read_syntax) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1807 { |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1808 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
|
1809 os << d; |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1810 else if (plus_format) |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
1811 pr_plus_format (os, d); |
1 | 1812 else |
1813 { | |
1814 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1815 os << d; |
1 | 1816 else |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
1817 pr_float (os, fmt, d); |
1 | 1818 } |
1819 } | |
1820 | |
1821 void | |
3608 | 1822 octave_print_internal (std::ostream& os, const Matrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1823 bool pr_as_read_syntax, int extra_indent) |
1 | 1824 { |
5275 | 1825 octave_idx_type nr = m.rows (); |
1826 octave_idx_type nc = m.columns (); | |
1 | 1827 |
2408 | 1828 if (nr == 0 || nc == 0) |
626 | 1829 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
1830 else if (plus_format && ! pr_as_read_syntax) | |
1 | 1831 { |
5275 | 1832 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1833 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1834 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1835 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1836 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1837 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1838 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1839 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1842 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1843 } |
1 | 1844 } |
1845 else | |
1846 { | |
23797
755b4c622972
Fix "variable may be used uninitialized" warning reported by gcc.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
1847 int fw = 0; |
3105 | 1848 double scale = 1.0; |
1849 set_format (m, fw, scale); | |
1 | 1850 int column_width = fw + 2; |
5275 | 1851 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
|
1852 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
1 | 1853 |
626 | 1854 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1855 max_width -= 4; |
1972 | 1856 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1857 max_width -= extra_indent; |
1972 | 1858 |
1859 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1860 max_width = 0; |
626 | 1861 |
1 | 1862 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1863 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1864 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1865 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1866 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1867 os << m; |
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 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
|
1870 os << ']'; |
10315
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 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1873 } |
1 | 1874 |
5275 | 1875 octave_idx_type inc = nc; |
2165 | 1876 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
|
1877 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1878 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1879 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1880 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1881 } |
1 | 1882 |
626 | 1883 if (pr_as_read_syntax) |
10315
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 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
|
1886 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1887 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1888 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1889 { |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
1890 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
|
1891 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1892 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
|
1893 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1894 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1895 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1896 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1897 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1898 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1900 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1901 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1902 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1903 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1904 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1905 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1906 pr_float (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1907 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1908 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1909 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1910 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1911 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1912 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1913 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1914 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1915 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1916 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1917 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1918 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1919 os << " ...\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1920 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1921 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1922 } |
626 | 1923 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1924 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
1925 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
|
1926 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1927 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1928 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1929 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
|
1930 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
1931 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
|
1932 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1933 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
|
1934 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1935 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1936 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
|
1937 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1938 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1939 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1940 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
|
1941 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1942 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1943 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1944 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1945 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1946 pr_float (os, m(i,j), fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1947 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1948 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1949 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1950 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1951 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1952 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1953 } |
1 | 1954 } |
1955 } | |
1956 | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1957 void |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1958 octave_print_internal (std::ostream& os, const DiagMatrix& m, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1959 bool pr_as_read_syntax, int extra_indent) |
8625
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 octave_idx_type nr = m.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1962 octave_idx_type nc = m.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1963 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1964 if (nr == 0 || nc == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1965 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
|
1966 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1967 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1968 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1969 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1970 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1971 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1972 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1973 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1974 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1975 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1976 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1977 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1978 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1979 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1980 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1981 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1982 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1983 int fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1984 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1985 set_format (Matrix (m.diag ()), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1986 int column_width = fw + 2; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1987 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
|
1988 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
|
1989 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1990 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1991 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1992 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1993 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1994 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1995 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
1996 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1997 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
1998 if (free_format) |
10315
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 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2001 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2002 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2003 os << Matrix (m); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2004 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2005 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
|
2006 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2007 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2008 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2009 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2010 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2011 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2012 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
|
2013 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2014 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2015 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2016 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2017 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2018 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2019 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2020 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2021 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2022 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2023 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2024 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2025 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2026 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
|
2027 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2028 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2029 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2030 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2031 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2032 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2033 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2034 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2035 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2036 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2037 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2038 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2039 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2040 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2041 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2042 pr_float (os, m(j,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2043 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2044 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2045 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2046 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2047 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2048 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2049 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2050 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2051 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2052 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2053 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2054 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2055 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2056 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
|
2057 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2058 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2059 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2060 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2061 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2062 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2063 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
2064 // kluge. Get the true width of a number. |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2065 int zero_fw; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2066 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2067 std::ostringstream tmp_oss; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2068 pr_float (tmp_oss, 0.0, fw, scale); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2069 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2070 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2071 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2072 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
|
2073 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2074 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
|
2075 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2076 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
|
2077 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2078 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2079 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
|
2080 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2081 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2082 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2083 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
|
2084 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2085 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2086 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2087 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2088 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2089 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2090 pr_float (os, m(i,j), fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2091 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2092 os << std::setw (zero_fw) << '0'; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2093 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2094 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2095 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2096 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2097 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2098 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2099 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2100 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2101 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2102 } |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2103 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2104 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
|
2105 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
|
2106 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
|
2107 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2108 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2109 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
|
2110 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
|
2111 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2112 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2113 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2114 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
|
2115 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2116 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
|
2117 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2118 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
|
2119 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2120 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
|
2121 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2122 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
|
2123 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
|
2124 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2125 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
|
2126 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
|
2127 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2128 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
|
2129 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2130 octave_quit (); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2131 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2132 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
|
2133 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2134 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
|
2135 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2136 nm += "(:,:,"; |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2137 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2138 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
|
2139 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2140 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
|
2141 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2142 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
|
2143 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2144 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
|
2145 buf << ','; |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2146 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2147 buf << ')'; |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2148 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2149 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2150 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
|
2151 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2152 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2153 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
|
2154 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2155 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
|
2156 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
|
2157 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2158 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
|
2159 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
|
2160 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2161 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
|
2162 = 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
|
2163 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2164 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
|
2165 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2166 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
|
2167 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2168 else |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2169 { |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2170 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
|
2171 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
|
2172 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2173 |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2174 if (i < m) |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2175 NDA_T::increment_index (ra_idx, dims, 2); |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2176 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2177 } |
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2178 } |
4532 | 2179 |
4513 | 2180 void |
2181 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
|
2182 bool pr_as_read_syntax, int extra_indent) |
4513 | 2183 { |
2184 switch (nda.ndims ()) | |
2185 { | |
2186 case 1: | |
2187 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2188 octave_print_internal (os, Matrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2189 pr_as_read_syntax, extra_indent); |
4513 | 2190 break; |
2191 | |
2192 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2193 print_nd_array <NDArray, double, Matrix> (os, nda, pr_as_read_syntax); |
4513 | 2194 break; |
2195 } | |
2196 } | |
2197 | |
5030 | 2198 template <> |
6018 | 2199 /* static */ inline void |
6015 | 2200 pr_plus_format<> (std::ostream& os, const Complex& c) |
3248 | 2201 { |
2202 double rp = c.real (); | |
2203 double ip = c.imag (); | |
2204 | |
2205 if (rp == 0.0) | |
2206 { | |
2207 if (ip == 0.0) | |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2208 os << ' '; |
3248 | 2209 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2210 os << 'i'; |
3248 | 2211 } |
2212 else if (ip == 0.0) | |
3608 | 2213 pr_plus_format (os, rp); |
3248 | 2214 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2215 os << 'c'; |
3248 | 2216 } |
2217 | |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2218 extern void |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2219 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
|
2220 const Complex& c, bool pr_as_read_syntax) |
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2221 { |
17867
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2222 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
|
2223 os << c; |
49d573a1deda
avoid initial spaces for scalars in GUI workspace viewer (bug #40500)
John W. Eaton <jwe@octave.org>
parents:
17866
diff
changeset
|
2224 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
|
2225 pr_plus_format (os, c); |
1 | 2226 else |
2227 { | |
2228 if (free_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2229 os << c; |
1 | 2230 else |
24668
d4dd741b2794
new octave_value functions for formatting output
John W. Eaton <jwe@octave.org>
parents:
24667
diff
changeset
|
2231 pr_complex (os, fmt, c); |
1 | 2232 } |
2233 } | |
2234 | |
2235 void | |
3523 | 2236 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
|
2237 bool pr_as_read_syntax, int extra_indent) |
1 | 2238 { |
5275 | 2239 octave_idx_type nr = cm.rows (); |
2240 octave_idx_type nc = cm.columns (); | |
1 | 2241 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2242 if (nr == 0 || nc == 0) |
626 | 2243 print_empty_matrix (os, nr, nc, pr_as_read_syntax); |
2244 else if (plus_format && ! pr_as_read_syntax) | |
1 | 2245 { |
5275 | 2246 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2247 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2248 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2249 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2250 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2251 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2252 pr_plus_format (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2253 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2254 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2255 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2256 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2257 } |
1 | 2258 } |
2259 else | |
2260 { | |
2261 int r_fw, i_fw; | |
3105 | 2262 double scale = 1.0; |
2263 set_format (cm, r_fw, i_fw, scale); | |
1 | 2264 int column_width = i_fw + r_fw; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2265 column_width += (rat_format || bank_format || hex_format |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2266 || bit_format) ? 2 : 7; |
5275 | 2267 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
|
2268 octave_idx_type max_width = octave::command_editor::terminal_cols (); |
1 | 2269 |
626 | 2270 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2271 max_width -= 4; |
1972 | 2272 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2273 max_width -= extra_indent; |
1972 | 2274 |
2275 if (max_width < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2276 max_width = 0; |
626 | 2277 |
1 | 2278 if (free_format) |
10315
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 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2281 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2282 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2283 os << cm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2284 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2285 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
|
2286 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2287 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2288 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2289 } |
1 | 2290 |
5275 | 2291 octave_idx_type inc = nc; |
2165 | 2292 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
|
2293 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2294 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2295 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2296 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2297 } |
1 | 2298 |
626 | 2299 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2301 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
|
2302 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2303 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2304 while (col < nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2305 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2306 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
|
2307 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2308 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
|
2309 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2310 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2311 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2312 if (i == 0 && j == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2313 os << "[ "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2314 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2315 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2316 if (j > col && j < lim) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2317 os << ", "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2318 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2319 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2320 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2321 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2322 pr_complex (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2323 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2324 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2325 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2326 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2327 if (col >= nc) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2328 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2329 if (i == nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2330 os << " ]"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2331 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2332 os << ";\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2333 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2334 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2335 os << " ...\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2336 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2337 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2338 } |
626 | 2339 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2340 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2341 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
|
2342 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2343 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2344 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2345 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
|
2346 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2347 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
|
2348 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2349 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
|
2350 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2351 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2352 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
|
2353 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2354 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2355 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2356 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
|
2357 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2358 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2359 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2360 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2361 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2362 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2363 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2364 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2365 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2366 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2367 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2368 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2369 } |
1 | 2370 } |
2371 } | |
2372 | |
2373 void | |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2374 octave_print_internal (std::ostream& os, const ComplexDiagMatrix& cm, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2375 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2376 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2377 octave_idx_type nr = cm.rows (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2378 octave_idx_type nc = cm.columns (); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2379 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2380 if (nr == 0 || nc == 0) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2381 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
|
2382 else if (plus_format && ! pr_as_read_syntax) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2383 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2384 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2385 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2386 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2388 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2389 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2390 pr_plus_format (os, cm(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2391 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2392 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2393 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2394 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2395 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2396 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2397 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2398 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2399 int r_fw, i_fw; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2400 double scale = 1.0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2401 set_format (ComplexMatrix (cm.diag ()), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2402 int column_width = i_fw + r_fw; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2403 column_width += (rat_format || bank_format || hex_format |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2404 || bit_format) ? 2 : 7; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2405 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
|
2406 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
|
2407 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2408 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2409 max_width -= 4; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2410 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2411 max_width -= extra_indent; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2412 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2413 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2414 max_width = 0; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2415 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2416 if (free_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2417 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2418 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2419 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2420 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2421 os << ComplexMatrix (cm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2422 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2423 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
|
2424 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2425 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2426 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2427 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2428 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2429 octave_idx_type inc = nc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2430 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
|
2431 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2432 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2433 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2434 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2435 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2436 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2437 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2438 { |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2439 os << "diag ("; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2440 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2441 octave_idx_type col = 0; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2442 while (col < nc) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2443 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2444 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
|
2445 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2446 for (octave_idx_type j = col; j < lim; j++) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2447 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2448 octave_quit (); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2449 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2450 if (j == 0) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2451 os << "[ "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2452 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2453 { |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2454 if (j > col && j < lim) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2455 os << ", "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2456 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2457 os << " "; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2458 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2459 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2460 pr_complex (os, cm(j,j)); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2461 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2462 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2463 col += inc; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2464 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2465 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2466 os << " ]"; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2467 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2468 os << " ...\n"; |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2469 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2470 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2471 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2472 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2473 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2474 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
|
2475 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2476 os << "Diagonal Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2477 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2478 os << "\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2479 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2480 pr_scale_header (os, scale); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2481 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21748
diff
changeset
|
2482 // kluge. Get the true width of a number. |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2483 int zero_fw; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2484 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2485 std::ostringstream tmp_oss; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2486 pr_complex (tmp_oss, Complex (0.0), r_fw, i_fw, scale); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2487 zero_fw = tmp_oss.str ().length (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2488 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2489 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2490 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
|
2491 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2492 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
|
2493 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2494 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
|
2495 extra_indent); |
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 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
|
2498 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2499 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2500 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2501 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
|
2502 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2503 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2504 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2505 os << " "; |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2506 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2507 if (i == j) |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2508 pr_complex (os, cm(i,j), r_fw, i_fw, scale); |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2509 else |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2510 os << std::setw (zero_fw) << '0'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2511 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2512 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2513 if (i < nr - 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2514 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2515 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2516 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2517 } |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2518 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2519 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2520 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2521 void |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2522 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
|
2523 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
|
2524 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2525 octave_idx_type nr = m.rows (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2526 octave_idx_type nc = m.columns (); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2527 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2528 if (nr == 0 || nc == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2529 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
|
2530 else if (plus_format && ! pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2531 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2532 for (octave_idx_type i = 0; i < nr; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2533 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2534 for (octave_idx_type j = 0; j < nc; j++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2535 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2536 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2537 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2538 pr_plus_format (os, m(i,j)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2539 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2540 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2541 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2542 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2543 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2544 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2545 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2546 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2547 int fw = 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2548 int column_width = fw + 2; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2549 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
|
2550 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
|
2551 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2552 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2553 max_width -= 4; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2554 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2555 max_width -= extra_indent; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2556 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2557 if (max_width < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2558 max_width = 0; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2559 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2560 if (free_format) |
10315
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 (pr_as_read_syntax) |
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 os << Matrix (m); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2566 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2567 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
|
2568 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2569 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2570 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2571 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2572 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2573 octave_idx_type inc = nc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2574 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
|
2575 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2576 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2577 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2578 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2579 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2580 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2581 if (pr_as_read_syntax) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2582 { |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2583 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
|
2584 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2585 os << "eye ("; |
18849
aa9ca67f09fb
make all permutation matrices column permutations (bug #42418)
David Spies <dnspies@gmail.com>
parents:
18816
diff
changeset
|
2586 os << ":, "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2587 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2588 octave_idx_type col = 0; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2589 while (col < nc) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2590 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2591 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
|
2592 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2593 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
|
2594 { |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
10066
diff
changeset
|
2595 octave_quit (); |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2596 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2597 if (j == 0) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2598 os << "[ "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2599 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2600 { |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2601 if (j > col && j < lim) |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2602 os << ", "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2603 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2604 os << " "; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2605 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2606 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2607 os << pvec (j); |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2608 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2609 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2610 col += inc; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2611 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2612 if (col >= nc) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2613 os << " ]"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2614 else |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2615 os << " ...\n"; |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2616 } |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2617 os << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2618 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2619 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2620 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2621 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
|
2622 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2623 os << "Permutation Matrix\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2624 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
2625 os << "\n"; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2626 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2627 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
|
2628 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2629 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
|
2630 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2631 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
|
2632 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2633 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2634 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
|
2635 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2636 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2637 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2638 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
|
2639 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2640 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2641 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2642 os << " "; |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2643 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2644 os << std::setw (fw) << m(i,j); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2645 } |
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 if (i < nr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2648 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2649 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2650 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2651 } |
8891
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2652 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2653 } |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2654 |
d077c590eb88
indicate diag & perm matrices on output
Jaroslav Hajek <highegg@gmail.com>
parents:
8746
diff
changeset
|
2655 void |
4513 | 2656 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
|
2657 bool pr_as_read_syntax, int extra_indent) |
4513 | 2658 { |
2659 switch (nda.ndims ()) | |
2660 { | |
2661 case 1: | |
2662 case 2: | |
19320
d0c73e23a505
Change inheritance tree so that <T>Matrix inherit from <T>NDArray.
Carnë Draug <carandraug@octave.org>
parents:
19318
diff
changeset
|
2663 octave_print_internal (os, ComplexMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2664 pr_as_read_syntax, extra_indent); |
4513 | 2665 break; |
2666 | |
2667 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2668 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
|
2669 (os, nda, pr_as_read_syntax); |
4513 | 2670 break; |
2671 } | |
2672 } | |
2673 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2674 // 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
|
2675 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2676 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2677 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
|
2678 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
|
2679 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2680 octave_print_internal (os, Matrix (m), pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2681 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2682 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2683 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2684 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
|
2685 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
|
2686 { |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2687 octave_print_internal (os, DiagMatrix (m), pr_as_read_syntax, extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2688 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2689 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2690 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2691 octave_print_internal (std::ostream& os, const FloatNDArray& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2692 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
|
2693 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
2694 octave_print_internal (os, NDArray (nda), pr_as_read_syntax, extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2695 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2696 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2697 void |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2698 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
|
2699 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
|
2700 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2701 octave_print_internal (os, ComplexMatrix (cm), pr_as_read_syntax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2702 extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2703 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2704 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2705 void |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2706 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
|
2707 bool pr_as_read_syntax, int extra_indent) |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2708 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2709 octave_print_internal (os, ComplexDiagMatrix (cm), pr_as_read_syntax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2710 extra_indent); |
8625
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2711 } |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2712 |
4d90d21a9cd9
special printing of diagonal matrices
Jaroslav Hajek <highegg@gmail.com>
parents:
8333
diff
changeset
|
2713 void |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2714 octave_print_internal (std::ostream& os, const FloatComplexNDArray& nda, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2715 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
|
2716 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2717 octave_print_internal (os, ComplexNDArray (nda), pr_as_read_syntax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2718 extra_indent); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2719 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2720 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7721
diff
changeset
|
2721 void |
3523 | 2722 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
|
2723 bool pr_as_read_syntax, int extra_indent) |
1 | 2724 { |
626 | 2725 double base = r.base (); |
1 | 2726 double increment = r.inc (); |
626 | 2727 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
|
2728 octave_idx_type num_elem = r.numel (); |
1 | 2729 |
626 | 2730 if (plus_format && ! pr_as_read_syntax) |
1 | 2731 { |
5275 | 2732 for (octave_idx_type i = 0; i < num_elem; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2733 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2734 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2735 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2736 double val = base + i * increment; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2737 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2738 pr_plus_format (os, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2739 } |
1 | 2740 } |
2741 else | |
2742 { | |
10987
eec74ee00b32
eliminate some GCC warnings
John W. Eaton <jwe@octave.org>
parents:
10846
diff
changeset
|
2743 int fw = 0; |
3105 | 2744 double scale = 1.0; |
2745 set_format (r, fw, scale); | |
1 | 2746 |
626 | 2747 if (pr_as_read_syntax) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2748 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2749 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2750 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2751 os << base << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2752 if (increment != 1.0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2753 os << increment << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2754 os << limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2755 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2756 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2757 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2758 pr_float (os, base, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2759 os << " : "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2760 if (increment != 1.0) |
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 pr_float (os, increment, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2763 os << " : "; |
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 pr_float (os, limit, fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2766 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2767 } |
626 | 2768 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2769 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
2770 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
|
2771 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2772 int column_width = fw + 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2773 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
|
2774 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
|
2775 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2776 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2777 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2778 os << r; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2779 return; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2780 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2781 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2782 octave_idx_type inc = num_elem; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2783 if (total_width > max_width && Vsplit_long_rows) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2784 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2785 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2786 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2787 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2788 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2789 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2790 max_width -= extra_indent; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2791 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2792 if (max_width < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2793 max_width = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2794 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2795 pr_scale_header (os, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2796 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2797 octave_idx_type col = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2798 while (col < num_elem) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2799 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
2800 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
|
2801 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2802 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
|
2803 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2804 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2805 os << std::setw (extra_indent) << ""; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2806 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2807 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
|
2808 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2809 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2810 |
16169
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2811 double val; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2812 if (i == 0) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2813 val = base; |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2814 else |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2815 val = base + i * increment; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2816 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2817 if (i == num_elem - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2818 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2819 // 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
|
2820 if ((increment > 0 && val >= limit) |
0303fda3e929
Fix range behavior with -0 endpoints (bug #38423)
Rik <rik@octave.org>
parents:
15467
diff
changeset
|
2821 || (increment < 0 && val <= limit)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2822 val = limit; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2823 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2824 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2825 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2826 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2827 pr_float (os, val, fw, scale); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2828 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2829 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2830 col += inc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2831 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2832 } |
1 | 2833 } |
2834 } | |
2835 | |
1343 | 2836 void |
3523 | 2837 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
|
2838 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2839 int extra_indent) |
3215 | 2840 { |
21583
d5963a6e29c2
Use integer output formatting for logicals (bug #47607)
Mike Miller <mtmiller@octave.org>
parents:
21568
diff
changeset
|
2841 uint8NDArray tmp (bm); |
3215 | 2842 octave_print_internal (os, tmp, pr_as_read_syntax, extra_indent); |
2843 } | |
2844 | |
2845 void | |
4513 | 2846 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
|
2847 bool pr_as_read_syntax, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2848 int extra_indent) |
4513 | 2849 { |
2850 switch (nda.ndims ()) | |
2851 { | |
2852 case 1: | |
2853 case 2: | |
19317
25f535b90e52
Change boolMatrix to subclass boolNDArray rather than be another Array<bool>.
Carnë Draug <carandraug@octave.org>
parents:
19255
diff
changeset
|
2854 octave_print_internal (os, boolMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2855 pr_as_read_syntax, extra_indent); |
4513 | 2856 break; |
2857 | |
2858 default: | |
13102
801c5a6ad487
Change the PRINT_ND_ARRAY macro into a templated function
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
12483
diff
changeset
|
2859 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
|
2860 boolMatrix> (os, nda, pr_as_read_syntax); |
4513 | 2861 break; |
2862 } | |
2863 } | |
2864 | |
2865 void | |
3523 | 2866 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
|
2867 bool pr_as_read_syntax, |
21066
258c787cd9ce
maint: Use "FIXME:" consistently in code base.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
2868 int /* FIXME: extra_indent */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2869 bool pr_as_string) |
1343 | 2870 { |
1572 | 2871 if (pr_as_string) |
2872 { | |
5275 | 2873 octave_idx_type nstr = chm.rows (); |
1343 | 2874 |
1572 | 2875 if (pr_as_read_syntax && nstr > 1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2876 os << "[ "; |
1343 | 2877 |
2907 | 2878 if (nstr != 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2879 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2880 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
|
2881 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2882 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2883 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2884 std::string row = chm.row_as_string (i); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2885 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2886 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2887 { |
23803
90689bdbe048
Use C++11 raw string literals to avoid escaping double quotes.
Rik <rik@octave.org>
parents:
23797
diff
changeset
|
2888 os << '"' << undo_string_escapes (row) << '"'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2889 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2890 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2891 os << "; "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2892 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2893 else |
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 os << row; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2896 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2897 if (i < nstr - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2898 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2899 } |
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 } |
1572 | 2902 |
2903 if (pr_as_read_syntax && nstr > 1) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2904 os << " ]"; |
1343 | 2905 } |
1572 | 2906 else |
2907 { | |
2908 os << "sorry, printing char matrices not implemented yet\n"; | |
2909 } | |
1343 | 2910 } |
2911 | |
4513 | 2912 void |
2913 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
|
2914 bool pr_as_read_syntax, int extra_indent, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2915 bool pr_as_string) |
4513 | 2916 { |
2917 switch (nda.ndims ()) | |
2918 { | |
2919 case 1: | |
2920 case 2: | |
19318
6c9ea5be96bf
Change charMatrix to subclass charNDArray rather than be another Array<char>.
Carnë Draug <carandraug@octave.org>
parents:
19317
diff
changeset
|
2921 octave_print_internal (os, charMatrix (nda), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2922 pr_as_read_syntax, extra_indent, pr_as_string); |
4513 | 2923 break; |
2924 | |
2925 default: | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2926 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
|
2927 pr_as_read_syntax); |
4513 | 2928 break; |
2929 } | |
2930 } | |
2931 | |
4655 | 2932 void |
4925 | 2933 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
|
2934 bool pr_as_read_syntax, int extra_indent) |
4925 | 2935 { |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2936 Array<std::string> nda (dim_vector (1, 1), s); |
4925 | 2937 |
2938 octave_print_internal (os, nda, pr_as_read_syntax, extra_indent); | |
2939 } | |
2940 | |
2941 void | |
9732
b4fdfee405b5
remove ArrayN<T> + fix nonhom. diag-scalar ops
Jaroslav Hajek <highegg@gmail.com>
parents:
9643
diff
changeset
|
2942 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
|
2943 bool pr_as_read_syntax, int /* extra_indent */) |
4655 | 2944 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2945 // 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
|
2946 // function. Can fix this with std::is_same from C++11. |
4655 | 2947 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
2948 if (nda.isempty ()) |
4655 | 2949 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
|
2950 else if (nda.numel () == 1) |
4655 | 2951 { |
2952 os << nda(0); | |
2953 } | |
2954 else | |
2955 { | |
2956 int ndims = nda.ndims (); | |
2957 | |
2958 dim_vector dims = nda.dims (); | |
2959 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2960 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 2961 |
2962 octave_idx_type m = 1; | |
4655 | 2963 |
2964 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2965 m *= dims(i); |
4655 | 2966 |
5275 | 2967 octave_idx_type nr = dims(0); |
2968 octave_idx_type nc = dims(1); | |
2969 | |
2970 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
|
2971 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2972 std::string nm = "ans"; |
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 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2975 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2976 nm += "(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2977 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2978 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2979 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2980 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2981 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2982 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2983 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2984 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
|
2985 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2986 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
2987 buf << ')'; |
10315
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 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2990 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2991 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2992 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
2993 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
|
2994 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2995 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2996 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2997 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2998 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
2999 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3000 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3001 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
|
3002 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3003 // 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
|
3004 // in neatly aligned columns... |
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 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3007 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3008 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3009 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3010 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3011 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3012 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3013 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
|
3014 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3015 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
|
3016 os << " " << page(ii,jj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3017 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3018 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3019 } |
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 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3022 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3023 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3024 if (i < m) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3025 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3026 } |
4655 | 3027 } |
3028 } | |
3029 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3030 template <typename T> |
4901 | 3031 class |
3032 octave_print_conv | |
3033 { | |
3034 public: | |
3035 typedef T print_conv_type; | |
3036 }; | |
3037 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3038 #define PRINT_CONV(T1, T2) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3039 template <> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3040 class \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3041 octave_print_conv<T1> \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3042 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3043 public: \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3044 typedef T2 print_conv_type; \ |
4901 | 3045 } |
3046 | |
3047 PRINT_CONV (octave_int8, octave_int16); | |
3048 PRINT_CONV (octave_uint8, octave_uint16); | |
3049 | |
3050 #undef PRINT_CONV | |
3051 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3052 template <typename T> |
6018 | 3053 /* static */ inline void |
4949 | 3054 pr_int (std::ostream& os, const T& d, int fw = 0) |
3055 { | |
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
|
3056 size_t sz = d.byte_size (); |
23432
e35a5c1233d0
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23410
diff
changeset
|
3057 const unsigned char *tmpi = d.iptr (); |
4949 | 3058 |
5544 | 3059 // Unless explicitly asked for, always print in big-endian |
3060 // format for hex and bit formats. | |
3061 // | |
3062 // {bit,hex}_format == 1: print big-endian | |
3063 // {bit,hex}_format == 2: print native | |
3064 | |
4949 | 3065 if (hex_format) |
3066 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3067 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
|
3068 |
f1b59ef34eda
attempt to avoid setting persistent state on i/o streams (bug #40396)
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3069 os.flags (std::ios::right | std::ios::hex); |
4949 | 3070 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3071 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
|
3072 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3073 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3074 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
|
3075 } |
4949 | 3076 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3077 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3078 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3079 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
|
3080 } |
4949 | 3081 } |
3082 else if (bit_format) | |
3083 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
3084 if (octave::mach_info::words_big_endian ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3085 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3086 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3087 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3088 } |
4949 | 3089 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3090 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3091 if (bit_format > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3092 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3093 for (size_t i = 0; i < sz; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3094 PRINT_CHAR_BITS_SWAPPED (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3095 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3096 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3097 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3098 for (int i = sz - 1; i >= 0; i--) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3099 PRINT_CHAR_BITS (os, tmpi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3100 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3101 } |
4949 | 3102 } |
3103 else | |
3104 { | |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3105 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
|
3106 |
4949 | 3107 os << std::setw (fw) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3108 << typename octave_print_conv<T>::print_conv_type (d); |
4949 | 3109 |
3110 if (bank_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3111 os << ".00"; |
4949 | 3112 } |
3113 } | |
3114 | |
7215 | 3115 template void |
3116 pr_int (std::ostream&, const octave_int8&, int); | |
3117 | |
3118 template void | |
3119 pr_int (std::ostream&, const octave_int16&, int); | |
3120 | |
3121 template void | |
3122 pr_int (std::ostream&, const octave_int32&, int); | |
3123 | |
3124 template void | |
3125 pr_int (std::ostream&, const octave_int64&, int); | |
3126 | |
3127 template void | |
3128 pr_int (std::ostream&, const octave_uint8&, int); | |
3129 | |
3130 template void | |
3131 pr_int (std::ostream&, const octave_uint16&, int); | |
3132 | |
3133 template void | |
3134 pr_int (std::ostream&, const octave_uint32&, int); | |
3135 | |
3136 template void | |
3137 pr_int (std::ostream&, const octave_uint64&, int); | |
3138 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3139 template <typename T> |
4901 | 3140 void |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3141 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
|
3142 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
|
3143 const octave_int<T>& val, bool) |
7215 | 3144 { |
3145 if (plus_format) | |
3146 { | |
3147 pr_plus_format (os, val); | |
3148 } | |
3149 else | |
3150 { | |
3151 if (free_format) | |
23534
b6498c088fca
maint: Don't write '> >' for declaration of templates that use templates.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
3152 os << typename octave_print_conv<octave_int<T>>::print_conv_type (val); |
7215 | 3153 else |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3154 { |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3155 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
|
3156 |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3157 pr_int (os, val, r_fmt.fw); |
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3158 } |
7215 | 3159 } |
3160 } | |
3161 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3162 #define PRINT_INT_SCALAR_INTERNAL(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3163 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
|
3164 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
|
3165 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
|
3166 const octave_int<TYPE>& val, bool dummy) \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3167 { \ |
24745
d2467914ce33
enable (or improve) display for more types in the variable editor
John W. Eaton <jwe@octave.org>
parents:
24737
diff
changeset
|
3168 octave_print_internal_template (os, fmt, val, dummy); \ |
7215 | 3169 } |
3170 | |
3171 PRINT_INT_SCALAR_INTERNAL (int8_t) | |
3172 PRINT_INT_SCALAR_INTERNAL (uint8_t) | |
3173 PRINT_INT_SCALAR_INTERNAL (int16_t) | |
3174 PRINT_INT_SCALAR_INTERNAL (uint16_t) | |
3175 PRINT_INT_SCALAR_INTERNAL (int32_t) | |
3176 PRINT_INT_SCALAR_INTERNAL (uint32_t) | |
3177 PRINT_INT_SCALAR_INTERNAL (int64_t) | |
3178 PRINT_INT_SCALAR_INTERNAL (uint64_t) | |
3179 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21100
diff
changeset
|
3180 template <typename T> |
7215 | 3181 /* static */ inline void |
3182 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
|
3183 bool pr_as_read_syntax, int extra_indent) |
4901 | 3184 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3185 // 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
|
3186 // function. Can fix this with std::is_same from C++11. |
4901 | 3187 |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23565
diff
changeset
|
3188 if (nda.isempty ()) |
4901 | 3189 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
|
3190 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
|
3191 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
|
3192 pr_as_read_syntax); |
4949 | 3193 else if (plus_format && ! pr_as_read_syntax) |
4901 | 3194 { |
3195 int ndims = nda.ndims (); | |
3196 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3197 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
4949 | 3198 |
4901 | 3199 dim_vector dims = nda.dims (); |
3200 | |
5275 | 3201 octave_idx_type m = 1; |
4901 | 3202 |
3203 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3204 m *= dims(i); |
4901 | 3205 |
5275 | 3206 octave_idx_type nr = dims(0); |
3207 octave_idx_type nc = dims(1); | |
3208 | |
3209 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
|
3210 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3211 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3212 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3213 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3214 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3215 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3216 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3217 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3218 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3219 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3220 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3221 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
|
3222 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3223 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3224 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3225 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3226 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3227 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3228 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3229 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3230 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3231 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3232 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3233 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3234 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
|
3235 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3236 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3237 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3238 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3239 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3240 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3241 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3242 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
|
3243 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3244 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
|
3245 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3246 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
|
3247 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3248 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3249 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3250 pr_plus_format (os, page(ii,jj)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3251 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3252 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3253 if ((ii < nr - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3254 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3255 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3256 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3257 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3258 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3259 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3260 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3261 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3262 } |
4949 | 3263 } |
3264 else | |
3265 { | |
3266 int ndims = nda.ndims (); | |
3267 | |
3268 dim_vector dims = nda.dims (); | |
3269 | |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3270 Array<octave_idx_type> ra_idx (dim_vector (ndims, 1), 0); |
5275 | 3271 |
3272 octave_idx_type m = 1; | |
4949 | 3273 |
3274 for (int i = 2; i < ndims; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3275 m *= dims(i); |
4949 | 3276 |
5275 | 3277 octave_idx_type nr = dims(0); |
3278 octave_idx_type nc = dims(1); | |
4949 | 3279 |
3280 int fw = 0; | |
3281 if (hex_format) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3282 fw = 2 * nda(0).byte_size (); |
4949 | 3283 else if (bit_format) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3284 fw = nda(0).nbits (); |
4949 | 3285 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3286 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3287 bool isneg = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3288 int digits = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3289 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3290 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
|
3291 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3292 int new_digits |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3293 = static_cast<int> |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
3294 (std::floor (log10 (double (abs (nda(i).value ()))) + 1.0)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3295 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3296 if (new_digits > digits) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3297 digits = new_digits; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3298 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3299 if (! isneg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3300 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
|
3301 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3302 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3303 fw = digits + isneg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3304 } |
4949 | 3305 |
6788 | 3306 int column_width = fw + (rat_format ? 0 : (bank_format ? 5 : 2)); |
5275 | 3307 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
|
3308 int max_width = octave::command_editor::terminal_cols () - extra_indent; |
5275 | 3309 octave_idx_type inc = nc; |
4949 | 3310 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
|
3311 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3312 inc = max_width / column_width; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3313 if (inc == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3314 inc++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3315 } |
4949 | 3316 |
5275 | 3317 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
|
3318 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3319 if (m > 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3320 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3321 std::string nm = "ans(:,:,"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3322 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3323 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3324 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3325 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3326 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3327 buf << ra_idx(k) + 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3328 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3329 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
|
3330 buf << ','; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3331 else |
23807
336f89b6208b
Use character literals 'c' rather than string literals "c" when possible.
Rik <rik@octave.org>
parents:
23803
diff
changeset
|
3332 buf << ')'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3333 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3334 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3335 nm += buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3336 |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3337 os << nm << " =\n"; |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3338 if (! Vcompact_format) |
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3339 os << "\n"; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3340 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3341 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3342 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
|
3343 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3344 idx(0) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3345 idx(1) = idx_vector (':'); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3346 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3347 for (int k = 2; k < ndims; k++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3348 idx(k) = idx_vector (ra_idx(k)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3349 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11547
diff
changeset
|
3350 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
|
3351 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3352 if (free_format) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3353 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3354 if (pr_as_read_syntax) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3355 os << "[\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3356 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3357 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
|
3358 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3359 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
|
3360 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3361 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3362 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3363 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
|
3364 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3365 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3366 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3367 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3368 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
|
3369 os << ']'; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3370 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3371 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3372 { |
23675
f71c0195b19d
move octave_preserve_stream_state to octave namespace
John W. Eaton <jwe@octave.org>
parents:
23662
diff
changeset
|
3373 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
|
3374 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3375 octave_idx_type n_rows = page.rows (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3376 octave_idx_type n_cols = page.cols (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3377 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3378 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
|
3379 { |
24737
5be92b26ef8f
Fix alignment of numbers in fixed_point_format display (bug #53083).
Rik <rik@octave.org>
parents:
24673
diff
changeset
|
3380 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
|
3381 : n_cols); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3382 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3383 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
|
3384 extra_indent); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3385 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3386 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
|
3387 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3388 os << std::setw (extra_indent) << ""; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3389 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3390 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
|
3391 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3392 octave_quit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3393 os << " "; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3394 pr_int (os, page(ii,jj), fw); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3395 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3396 if ((ii < n_rows - 1) || (i < m -1)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3397 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3398 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3399 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3400 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3401 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3402 if (i < m - 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3403 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3404 os << "\n"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3405 increment_index (ra_idx, dims, 2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3406 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3407 } |
4901 | 3408 } |
3409 } | |
3410 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3411 #define PRINT_INT_ARRAY_INTERNAL(TYPE) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3412 OCTINTERP_API void \ |
7215 | 3413 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
|
3414 bool pr_as_read_syntax, int extra_indent) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
22022
diff
changeset
|
3415 { \ |
7215 | 3416 octave_print_internal_template (os, nda, pr_as_read_syntax, extra_indent); \ |
3417 } | |
3418 | |
3419 PRINT_INT_ARRAY_INTERNAL (octave_int8) | |
3420 PRINT_INT_ARRAY_INTERNAL (octave_uint8) | |
3421 PRINT_INT_ARRAY_INTERNAL (octave_int16) | |
3422 PRINT_INT_ARRAY_INTERNAL (octave_uint16) | |
3423 PRINT_INT_ARRAY_INTERNAL (octave_int32) | |
3424 PRINT_INT_ARRAY_INTERNAL (octave_uint32) | |
3425 PRINT_INT_ARRAY_INTERNAL (octave_int64) | |
3426 PRINT_INT_ARRAY_INTERNAL (octave_uint64) | |
4901 | 3427 |
8012
63dbb85452cc
fix extern decls in .cc files
John W. Eaton <jwe@octave.org>
parents:
7896
diff
changeset
|
3428 void |
3933 | 3429 octave_print_internal (std::ostream&, const Cell&, bool, int, bool) |
3928 | 3430 { |
3933 | 3431 panic_impossible (); |
3928 | 3432 } |
3433 | |
17866
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3434 void |
19620
a1d172bfcb2f
eliminate some unused variable and typedef warnings
John W. Eaton <jwe@octave.org>
parents:
19367
diff
changeset
|
3435 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
|
3436 { |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3437 panic_impossible (); |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3438 } |
ea0ecbe2eaf5
display matrix values in GUI workspace viewer (bug #40499)
John W. Eaton <jwe@octave.org>
parents:
17847
diff
changeset
|
3439 |
20915
a3359fe50966
remove unused nargout variables
John W. Eaton <jwe@octave.org>
parents:
20909
diff
changeset
|
3440 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
|
3441 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
|
3442 @deftypefn {} {} rats (@var{x}, @var{len}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3443 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
|
3444 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3445 The string can be converted back into a matrix as follows: |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3446 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3447 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3448 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3449 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
|
3450 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
|
3451 @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
|
3452 @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
|
3453 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3454 The optional second argument defines the maximum length of the string |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3455 representing the elements of @var{x}. By default @var{len} is 9. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3456 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3457 If the length of the smallest possible rational approximation exceeds |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3458 @var{len}, an asterisk (*) padded with spaces will be returned instead. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3459 @seealso{format, rat} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3460 @end deftypefn */) |
6788 | 3461 { |
3462 int nargin = args.length (); | |
3463 | |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3464 if (nargin < 1 || nargin > 2) |
7896 | 3465 print_usage (); |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3466 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3467 octave_value arg = args(0); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3468 |
23586
f6c5db0a02e7
maint: Deprecate is_numeric_type and replace with isnumeric.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
3469 if (! arg.isnumeric ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3470 error ("rats: X must be numeric"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3471 |
21743
f4d7d0eb5b0c
use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
3472 octave::unwind_protect frame; |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3473 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3474 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
|
3475 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3476 rat_string_len = 9; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3477 if (nargin == 2) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3478 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
|
3479 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3480 frame.protect_var (rat_format); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3481 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3482 rat_format = true; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3483 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3484 std::ostringstream buf; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3485 arg.print (buf); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3486 std::string s = buf.str (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3487 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3488 std::list<std::string> lst; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3489 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3490 size_t n = 0; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3491 size_t s_len = s.length (); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3492 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3493 while (n < s_len) |
6788 | 3494 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3495 size_t m = s.find ('\n', n); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3496 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3497 if (m == std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3498 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3499 lst.push_back (s.substr (n)); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3500 break; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3501 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3502 else |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3503 { |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3504 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
|
3505 n = m + 1; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3506 } |
6788 | 3507 } |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3508 |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3509 return ovl (string_vector (lst)); |
6788 | 3510 } |
3511 | |
3685 | 3512 DEFUN (disp, args, nargout, |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3513 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
|
3514 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
|
3515 @deftypefn {} {} disp (@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
|
3516 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
|
3517 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3518 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
|
3519 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3520 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3521 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3522 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
|
3523 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3524 @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
|
3525 @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
|
3526 @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
|
3527 @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
|
3528 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3529 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3530 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
|
3531 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3532 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
|
3533 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
|
3534 @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
|
3535 @end deftypefn */) |
3685 | 3536 { |
20909
03e4ddd49396
omit unnecessary nargout checks
John W. Eaton <jwe@octave.org>
parents:
20897
diff
changeset
|
3537 if (args.length () != 1) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3538 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3539 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3540 octave_value_list retval; |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20925
diff
changeset
|
3541 |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3542 octave_value arg = args(0); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3543 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3544 if (nargout == 0) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3545 arg.print (octave_stdout); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3546 else |
3685 | 3547 { |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3548 std::ostringstream buf; |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3549 arg.print (buf); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
3550 retval = (octave_value (buf.str (), arg.is_dq_string () ? '"' : '\'')); |
3685 | 3551 } |
3552 | |
3553 return retval; | |
3554 } | |
3555 | |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3556 DEFMETHOD (fdisp, interp, args, , |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3557 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
|
3558 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
|
3559 @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
|
3560 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
|
3561 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3562 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
|
3563 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3564 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3565 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3566 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
|
3567 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3568 @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
|
3569 @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
|
3570 @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
|
3571 @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
|
3572 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3573 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3574 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
|
3575 @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
|
3576 @end deftypefn */) |
3685 | 3577 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20801
diff
changeset
|
3578 if (args.length () != 2) |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3579 print_usage (); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3580 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3581 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
|
3582 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3583 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
|
3584 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23675
diff
changeset
|
3585 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
|
3586 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3587 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
|
3588 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3589 octave_value arg = args(1); |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3590 |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3591 if (osp) |
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3592 arg.print (*osp); |
3685 | 3593 else |
20801
a542a9bf177e
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
3594 error ("fdisp: stream FID not open for writing"); |
3685 | 3595 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
3596 return ovl (); |
3685 | 3597 } |
3598 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3599 /* |
9629 | 3600 %!test |
3601 %! format short | |
3602 %! fd = tmpfile (); | |
3603 %! for r = [0, Inf -Inf, NaN] | |
3604 %! for i = [0, Inf -Inf, NaN] | |
3605 %! fdisp (fd, complex (r, i)); | |
3606 %! endfor | |
3607 %! endfor | |
3608 %! fclose (fd); | |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3609 |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3610 %!test |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3611 %! foo.real = pi * ones (3,20,3); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3612 %! foo.complex = pi * ones (3,20,3) + 1i; |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3613 %! foo.char = repmat ("- Hello World -", [3, 20]); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3614 %! foo.cell = {foo.real, foo.complex, foo.char}; |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3615 %! fields = fieldnames (foo); |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
3616 %! for f = 1:numel (fields) |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
3617 %! format loose; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3618 %! loose = disp (foo.(fields{f})); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
3619 %! format compact; |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3620 %! compact = disp (foo.(fields{f})); |
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3621 %! expected = strrep (loose, "\n\n", "\n"); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14360
diff
changeset
|
3622 %! assert (expected, compact); |
13129
155d7a5e70f5
src/pr-output.cc: Test "format compact"
Ben Abbott <bpabbott@mac.com>
parents:
13112
diff
changeset
|
3623 %! endfor |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
3624 */ |
9629 | 3625 |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3626 DEFUN (display, args, , |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3627 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
|
3628 doc: /* -*- texinfo -*- |
23565
3a730821e4a2
doc: Peridoc grammarcheck of documentation.
Rik <rik@octave.org>
parents:
23564
diff
changeset
|
3629 @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
|
3630 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
|
3631 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3632 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
|
3633 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
|
3634 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
|
3635 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3636 @example |
23182
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3637 myclass (@dots{}) |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3638 @end example |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3639 |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3640 Or: |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3641 |
8a37443f1a7b
doc: Document second input argument of display (bug #49794)
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23084
diff
changeset
|
3642 @example |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3643 myobj = myclass (@dots{}) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3644 @end example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3645 |
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
|
3646 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
|
3647 avoid the default output: |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3648 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3649 @example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3650 @group |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3651 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
|
3652 @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
|
3653 |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3654 <class myclass> |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3655 @end group |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3656 @end example |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3657 |
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
|
3658 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
|
3659 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
|
3660 @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
|
3661 |
705361dfe353
doc: disp rather than display should be overloaded (bug #50640, bug #50729).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
23398
diff
changeset
|
3662 @seealso{disp, class, subsref, subsasgn} |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3663 @end deftypefn */) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3664 { |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3665 int nargin = args.length (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3666 |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3667 // 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
|
3668 // 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
|
3669 // 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
|
3670 // 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
|
3671 |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3672 if (nargin < 1 || nargin > 2) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3673 print_usage (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3674 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3675 std::string name; |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3676 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3677 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
|
3678 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
|
3679 else |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3680 { |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3681 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
|
3682 name = names(0); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3683 } |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3684 |
23332
7d4ca8c01bbb
don't call display methods with more than one argument (bug #50640)
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
3685 // 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
|
3686 // object type. |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3687 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3688 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
|
3689 |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3690 // 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
|
3691 // disp is done. |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3692 |
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3693 bool print_newlines = false; |
22921
b28801182c08
don't display "ans" for "display (expr)" (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22898
diff
changeset
|
3694 if (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
|
3695 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
|
3696 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3697 // 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
|
3698 |
23075
4e3d47dc7e25
move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23059
diff
changeset
|
3699 octave::feval ("disp", ovl (value)); |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3700 |
22989
698c1190d790
* pr-output.cc (Fdisplay): Use octave_value::print_name_tag.
John W. Eaton <jwe@octave.org>
parents:
22921
diff
changeset
|
3701 if (print_newlines) |
22898
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3702 octave_stdout << std::endl; |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3703 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3704 return ovl (); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3705 } |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3706 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3707 /* |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3708 %!test |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3709 %! str = evalc ("x = 1.1; display (x)"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3710 %! assert (str, "x = 1.1000\n"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3711 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3712 %!test |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3713 %! str = evalc ("display (1.1)"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3714 %! assert (str, " 1.1000\n"); |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3715 |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3716 ## Test input validation |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3717 %!error display () |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3718 %!error display (1,2) |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3719 */ |
9baa19102908
refactor display and disp functions (bug #49794)
John W. Eaton <jwe@octave.org>
parents:
22881
diff
changeset
|
3720 |
1 | 3721 static void |
3722 init_format_state (void) | |
3723 { | |
2387 | 3724 free_format = false; |
3725 plus_format = false; | |
6788 | 3726 rat_format = false; |
2387 | 3727 bank_format = false; |
3608 | 3728 hex_format = 0; |
1309 | 3729 bit_format = 0; |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3730 Vcompact_format = false; |
2387 | 3731 print_e = false; |
3732 print_big_e = false; | |
4509 | 3733 print_g = false; |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3734 print_eng = false; |
1 | 3735 } |
3736 | |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3737 static std::string format_string ("short"); |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3738 |
1755 | 3739 static void |
3740 set_format_style (int argc, const string_vector& argv) | |
1 | 3741 { |
1755 | 3742 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
|
3743 std::string format; |
1755 | 3744 |
1899 | 3745 if (--argc > 0) |
1 | 3746 { |
3523 | 3747 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
|
3748 format = arg; |
2584 | 3749 |
1755 | 3750 if (arg == "short") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3751 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3752 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3753 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3754 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
|
3755 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3756 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3757 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3758 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3759 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3760 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3761 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3762 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3764 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3765 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3766 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3768 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3769 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3770 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3771 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3772 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3773 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3774 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3775 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3776 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3777 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3778 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3779 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3780 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3781 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3782 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3783 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3784 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3785 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
|
3786 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3787 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3788 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3789 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3790 set_output_prec_and_fw (5, 10); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3791 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3792 else if (arg == "shorte") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3793 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3794 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3795 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3796 set_output_prec_and_fw (5, 10); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3797 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3798 else if (arg == "shortE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3799 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3800 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3801 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3802 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3803 set_output_prec_and_fw (5, 10); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3804 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3805 else if (arg == "shortg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3806 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3807 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3808 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3809 set_output_prec_and_fw (5, 10); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3810 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3811 else if (arg == "shortG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3812 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3813 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3814 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3815 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3816 set_output_prec_and_fw (5, 10); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3817 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3818 else if (arg == "shortEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3819 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3820 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3821 print_eng = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3822 set_output_prec_and_fw (5, 10); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3823 } |
1755 | 3824 else if (arg == "long") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3825 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3826 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3827 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3828 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
|
3829 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3830 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3831 if (arg == "e") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3832 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3833 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3834 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3835 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3836 else if (arg == "E") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3837 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3838 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3839 print_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3840 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3841 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3842 else if (arg == "g") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3843 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3844 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3845 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3846 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3847 else if (arg == "G") |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3848 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3849 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3850 print_g = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3851 print_big_e = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3852 } |
10741
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3853 else if (arg == "eng") |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3854 { |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3855 init_format_state (); |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3856 print_eng = true; |
38bdcbb58df7
Add engineering formats. eg 'fomat short eng' (Feature Request #30163)
David Bateman <dbateman@free.fr>
parents:
10706
diff
changeset
|
3857 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3858 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3859 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
|
3860 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3861 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3862 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3863 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3864 set_output_prec_and_fw (15, 20); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3865 } |
18464
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3866 else if (arg == "longe") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3867 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3868 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3869 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3870 set_output_prec_and_fw (15, 20); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3871 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3872 else if (arg == "longE") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3873 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3874 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3875 print_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3876 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3877 set_output_prec_and_fw (15, 20); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3878 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3879 else if (arg == "longg") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3880 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3881 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3882 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3883 set_output_prec_and_fw (15, 20); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3884 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3885 else if (arg == "longG") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3886 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3887 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3888 print_g = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3889 print_big_e = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3890 set_output_prec_and_fw (15, 20); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3891 } |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3892 else if (arg == "longEng") |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3893 { |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3894 init_format_state (); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3895 print_eng = true; |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3896 set_output_prec_and_fw (15, 20); |
917f1af7d2e4
Additional format options for matlab compatibility (bug #41541).
Markus Bergholz <markuman@gmail.com>
parents:
18438
diff
changeset
|
3897 } |
1755 | 3898 else if (arg == "hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3899 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3900 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3901 hex_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3902 } |
1755 | 3903 else if (arg == "native-hex") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3904 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3905 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3906 hex_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3907 } |
1755 | 3908 else if (arg == "bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3909 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3910 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3911 bit_format = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3912 } |
1755 | 3913 else if (arg == "native-bit") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3914 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3915 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3916 bit_format = 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3917 } |
1755 | 3918 else if (arg == "+" || arg == "plus") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3919 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3920 if (--argc > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3921 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3922 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
|
3923 format.append (arg); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3924 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3925 if (arg.length () == 3) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3926 plus_format_chars = arg; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3927 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3928 error ("format: invalid option for plus format"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3929 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3930 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
|
3931 plus_format_chars = "+- "; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3932 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3933 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3934 plus_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3935 } |
6788 | 3936 else if (arg == "rat") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3937 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3938 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3939 rat_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3940 } |
1755 | 3941 else if (arg == "bank") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3942 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3943 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3944 bank_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3945 } |
1755 | 3946 else if (arg == "free") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3947 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3948 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3949 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3950 } |
1755 | 3951 else if (arg == "none") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3952 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3953 init_format_state (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3954 free_format = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3955 } |
1755 | 3956 else if (arg == "compact") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3957 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3958 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
|
3959 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3960 } |
1755 | 3961 else if (arg == "loose") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3962 { |
13112
969ed305dde5
Remove all blank lines with "format compact"
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
13102
diff
changeset
|
3963 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
|
3964 return; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
3965 } |
1 | 3966 else |
20831
35241c4b696c
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20819
diff
changeset
|
3967 error ("format: unrecognized format state '%s'", arg.c_str ()); |
1 | 3968 } |
3969 else | |
3970 { | |
3971 init_format_state (); | |
3972 set_output_prec_and_fw (5, 10); | |
23829
01899bdd2a3a
Eliminate unnecessary std::string ("...") constructor calls when "..." suffices.
Rik <rik@octave.org>
parents:
23807
diff
changeset
|
3973 format = "short"; |
1 | 3974 } |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3975 |
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
3976 format_string = format; |
1 | 3977 } |
3978 | |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3979 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
|
3980 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
|
3981 @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
|
3982 @deftypefnx {} {} format options |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3983 @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
|
3984 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
|
3985 normal echoing mechanism. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3986 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
3987 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
|
3988 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
|
3989 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
|
3990 @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
|
3991 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3992 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
|
3993 (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
|
3994 @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
|
3995 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3996 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
|
3997 table. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3998 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
3999 @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
|
4000 @item short |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4001 Fixed point format with 5 significant figures in a field that is a maximum of |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4002 10 characters wide. (default). |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4003 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4004 If Octave is unable to format a matrix so that columns line up on the decimal |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4005 point and all numbers fit within the maximum field width then it switches to an |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4006 exponential @samp{e} 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
|
4007 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4008 @item long |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4009 Fixed point format with 15 significant figures in a field that is a maximum of |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4010 20 characters wide. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4011 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4012 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
|
4013 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
|
4014 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4015 @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
|
4016 @itemx long e |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4017 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
|
4018 and an exponent (power of 10). The mantissa has 5 significant digits in the |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4019 short format and 15 digits in the long format. For example, with the |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4020 @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
|
4021 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4022 @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
|
4023 @itemx long E |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4024 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
|
4025 to indicate the exponent. For example, with the @samp{long E} format, |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4026 @code{pi} is displayed as @code{3.14159265358979E+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
|
4027 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4028 @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
|
4029 @itemx long g |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4030 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
|
4031 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
|
4032 @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
|
4033 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4034 @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 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4036 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4037 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4038 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
|
4039 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
|
4040 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
|
4041 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
|
4042 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
|
4043 @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
|
4044 @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
|
4045 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4046 @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
|
4047 @itemx long eng |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4048 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
|
4049 engineering format, where the exponent is divisible by 3. For example, with |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4050 the @samp{short eng} format, @code{10 * pi} is displayed as @code{31.4159e+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
|
4051 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4052 @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
|
4053 @itemx short G |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4054 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
|
4055 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
|
4056 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4057 @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
|
4058 @itemx none |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4059 Print output in free format, without trying to line up columns of matrices on |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4060 the decimal point. This also causes complex numbers to be formatted as numeric |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4061 pairs like this @samp{(0.60419, 0.60709)} instead of like this |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4062 @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
|
4063 @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
|
4064 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4065 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
|
4066 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
|
4067 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4068 @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
|
4069 @item "+" |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4070 @itemx "+" @var{chars} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4071 @itemx plus |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4072 @itemx plus @var{chars} |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4073 Print a @samp{+} symbol for matrix elements greater than zero, a @samp{-} |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4074 symbol for elements less than zero and a space for zero matrix elements. This |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4075 format can be very useful for examining the structure of a large sparse matrix. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4076 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4077 The optional argument @var{chars} specifies a list of 3 characters to use for |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4078 printing values greater than zero, less than zero and equal to zero. For |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4079 example, with the @samp{"+" "+-."} format, @code{[1, 0, -1; -1, 0, 1]} is |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4080 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
|
4081 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4082 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4083 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4084 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4085 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4086 +.- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4087 -.+ |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4088 @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
|
4089 @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
|
4090 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4091 @item bank |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4092 Print in a fixed format with two digits to the right of the decimal point. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4093 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4094 @item native-hex |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4095 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
|
4096 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
|
4097 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
|
4098 @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
|
4099 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4100 @item hex |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4101 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
|
4102 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
|
4103 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4104 @item native-bit |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4105 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
|
4106 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
|
4107 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4108 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4109 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4110 01000000000010010010000111111011 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4111 01010100010001000010110100011000 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4112 @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
|
4113 @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
|
4114 |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4115 (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
|
4116 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
|
4117 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
|
4118 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4119 @item bit |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4120 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
|
4121 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
|
4122 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4123 @item rat |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4124 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
|
4125 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
|
4126 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
|
4127 @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
|
4128 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4129 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
|
4130 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4131 @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
|
4132 @item compact |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4133 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
|
4134 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
|
4135 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4136 @item loose |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4137 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
|
4138 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
|
4139 @end table |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4140 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4141 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
|
4142 format and format spacing. |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4143 |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4144 @seealso{fixed_point_format, output_max_field_width, output_precision, split_long_rows, print_empty_dimensions, rats} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4145 @end deftypefn */) |
529 | 4146 { |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4147 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
|
4148 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4149 if (nargout == 0) |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4150 { |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4151 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
|
4152 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4153 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
|
4154 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4155 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
|
4156 } |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4157 else |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4158 { |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4159 if (nargout >= 2) |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
4160 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
|
4161 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4162 retval(0) = format_string; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4163 } |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4164 |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4165 return retval; |
529 | 4166 } |
4167 | |
22881
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4168 /* |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4169 %!test |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4170 %! [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
|
4171 %! unwind_protect |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4172 %! ## 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
|
4173 %! format long; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4174 %! str = disp (pi); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4175 %! assert (str, " 3.14159265358979\n"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4176 %! new_fmt = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4177 %! assert (new_fmt, "long"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4178 %! ## Test resetting format |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4179 %! format compact; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4180 %! [~, new_spacing] = format (); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4181 %! assert (new_spacing, "compact"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4182 %! format; |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4183 %! [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
|
4184 %! assert (new_fmt, "short"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4185 %! assert (new_spacing, "loose"); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4186 %! unwind_protect_cleanup |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4187 %! format (old_fmt); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4188 %! format (old_spacing); |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4189 %! end_unwind_protect |
f84aa17075d4
Add Octave-only query mode for format command to find status.
Rik <rik@octave.org>
parents:
22868
diff
changeset
|
4190 */ |
18735
28eab2d84190
Add callbacks for root properties format and formatspacing (bug #42135).
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents:
18676
diff
changeset
|
4191 |
5794 | 4192 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
|
4193 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
|
4194 @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
|
4195 @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
|
4196 @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
|
4197 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
|
4198 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
|
4199 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4200 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
|
4201 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
|
4202 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
|
4203 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4204 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4205 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4206 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
|
4207 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4208 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4209 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
|
4210 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4211 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
|
4212 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
|
4213 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
|
4214 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
|
4215 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
|
4216 @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
|
4217 @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
|
4218 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4219 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4220 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
|
4221 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
|
4222 @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
|
4223 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4224 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
|
4225 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
|
4226 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
|
4227 @seealso{format, output_max_field_width, output_precision} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4228 @end deftypefn */) |
5794 | 4229 { |
4230 return SET_INTERNAL_VARIABLE (fixed_point_format); | |
4231 } | |
4232 | |
4233 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
|
4234 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
|
4235 @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
|
4236 @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
|
4237 @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
|
4238 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
|
4239 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
|
4240 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4241 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
|
4242 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4243 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4244 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
|
4245 @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
|
4246 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4247 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4248 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
|
4249 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4250 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4251 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
|
4252 @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
|
4253 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4254 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
|
4255 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
|
4256 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
|
4257 @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
|
4258 @end deftypefn */) |
5794 | 4259 { |
4260 return SET_INTERNAL_VARIABLE (print_empty_dimensions); | |
4261 } | |
4262 | |
4263 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
|
4264 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
|
4265 @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
|
4266 @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
|
4267 @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
|
4268 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
|
4269 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
|
4270 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4271 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
|
4272 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
|
4273 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
|
4274 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
|
4275 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4276 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4277 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4278 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
|
4279 ans = |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4280 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4281 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
|
4282 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4283 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
|
4284 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
|
4285 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4286 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
|
4287 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4288 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
|
4289 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
|
4290 @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
|
4291 @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
|
4292 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21942
diff
changeset
|
4293 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
|
4294 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
|
4295 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
|
4296 @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
|
4297 @end deftypefn */) |
5794 | 4298 { |
4299 return SET_INTERNAL_VARIABLE (split_long_rows); | |
4300 } |